michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ipc_UnixSocketWatcher_h michael@0: #define mozilla_ipc_UnixSocketWatcher_h michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #ifdef MOZ_B2G_BT_BLUEZ michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #endif michael@0: #include "UnixFdWatcher.h" michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: union sockaddr_any { michael@0: sockaddr_storage storage; // address-family only michael@0: sockaddr_un un; michael@0: sockaddr_in in; michael@0: sockaddr_in6 in6; michael@0: #ifdef MOZ_B2G_BT_BLUEZ michael@0: sockaddr_sco sco; michael@0: sockaddr_rc rc; michael@0: sockaddr_l2 l2; michael@0: #endif michael@0: // ... others michael@0: }; michael@0: michael@0: class UnixSocketWatcher : public UnixFdWatcher michael@0: { michael@0: public: michael@0: enum ConnectionStatus { michael@0: SOCKET_IS_DISCONNECTED = 0, michael@0: SOCKET_IS_LISTENING, michael@0: SOCKET_IS_CONNECTING, michael@0: SOCKET_IS_CONNECTED michael@0: }; michael@0: michael@0: virtual ~UnixSocketWatcher(); michael@0: michael@0: virtual void Close() MOZ_OVERRIDE; michael@0: michael@0: ConnectionStatus GetConnectionStatus() const michael@0: { michael@0: return mConnectionStatus; michael@0: } michael@0: michael@0: // Connect to a peer michael@0: nsresult Connect(const struct sockaddr* aAddr, socklen_t aAddrLen); michael@0: michael@0: // Listen on socket for incoming connection requests michael@0: nsresult Listen(const struct sockaddr* aAddr, socklen_t aAddrLen); michael@0: michael@0: // Callback method for accepted connections michael@0: virtual void OnAccepted(int aFd, const sockaddr_any* aAddr, michael@0: socklen_t aAddrLen) {}; michael@0: michael@0: // Callback method for successful connection requests michael@0: virtual void OnConnected() {}; michael@0: michael@0: // Callback method for successful listen requests michael@0: virtual void OnListening() {}; michael@0: michael@0: // Callback method for receiving from socket michael@0: virtual void OnSocketCanReceiveWithoutBlocking() {}; michael@0: michael@0: // Callback method for sending on socket michael@0: virtual void OnSocketCanSendWithoutBlocking() {}; michael@0: michael@0: protected: michael@0: UnixSocketWatcher(MessageLoop* aIOLoop); michael@0: UnixSocketWatcher(MessageLoop* aIOLoop, int aFd, michael@0: ConnectionStatus aConnectionStatus); michael@0: void SetSocket(int aFd, ConnectionStatus aConnectionStatus); michael@0: michael@0: private: michael@0: void OnFileCanReadWithoutBlocking(int aFd) MOZ_OVERRIDE; michael@0: void OnFileCanWriteWithoutBlocking(int aFd) MOZ_OVERRIDE; michael@0: michael@0: ConnectionStatus mConnectionStatus; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif