ipc/unixfd/UnixSocketWatcher.h

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_ipc_UnixSocketWatcher_h
michael@0 8 #define mozilla_ipc_UnixSocketWatcher_h
michael@0 9
michael@0 10 #include <sys/socket.h>
michael@0 11 #include <sys/types.h>
michael@0 12 #include <sys/un.h>
michael@0 13 #include <netinet/in.h>
michael@0 14 #ifdef MOZ_B2G_BT_BLUEZ
michael@0 15 #include <bluetooth/bluetooth.h>
michael@0 16 #include <bluetooth/sco.h>
michael@0 17 #include <bluetooth/l2cap.h>
michael@0 18 #include <bluetooth/rfcomm.h>
michael@0 19 #endif
michael@0 20 #include "UnixFdWatcher.h"
michael@0 21
michael@0 22 namespace mozilla {
michael@0 23 namespace ipc {
michael@0 24
michael@0 25 union sockaddr_any {
michael@0 26 sockaddr_storage storage; // address-family only
michael@0 27 sockaddr_un un;
michael@0 28 sockaddr_in in;
michael@0 29 sockaddr_in6 in6;
michael@0 30 #ifdef MOZ_B2G_BT_BLUEZ
michael@0 31 sockaddr_sco sco;
michael@0 32 sockaddr_rc rc;
michael@0 33 sockaddr_l2 l2;
michael@0 34 #endif
michael@0 35 // ... others
michael@0 36 };
michael@0 37
michael@0 38 class UnixSocketWatcher : public UnixFdWatcher
michael@0 39 {
michael@0 40 public:
michael@0 41 enum ConnectionStatus {
michael@0 42 SOCKET_IS_DISCONNECTED = 0,
michael@0 43 SOCKET_IS_LISTENING,
michael@0 44 SOCKET_IS_CONNECTING,
michael@0 45 SOCKET_IS_CONNECTED
michael@0 46 };
michael@0 47
michael@0 48 virtual ~UnixSocketWatcher();
michael@0 49
michael@0 50 virtual void Close() MOZ_OVERRIDE;
michael@0 51
michael@0 52 ConnectionStatus GetConnectionStatus() const
michael@0 53 {
michael@0 54 return mConnectionStatus;
michael@0 55 }
michael@0 56
michael@0 57 // Connect to a peer
michael@0 58 nsresult Connect(const struct sockaddr* aAddr, socklen_t aAddrLen);
michael@0 59
michael@0 60 // Listen on socket for incoming connection requests
michael@0 61 nsresult Listen(const struct sockaddr* aAddr, socklen_t aAddrLen);
michael@0 62
michael@0 63 // Callback method for accepted connections
michael@0 64 virtual void OnAccepted(int aFd, const sockaddr_any* aAddr,
michael@0 65 socklen_t aAddrLen) {};
michael@0 66
michael@0 67 // Callback method for successful connection requests
michael@0 68 virtual void OnConnected() {};
michael@0 69
michael@0 70 // Callback method for successful listen requests
michael@0 71 virtual void OnListening() {};
michael@0 72
michael@0 73 // Callback method for receiving from socket
michael@0 74 virtual void OnSocketCanReceiveWithoutBlocking() {};
michael@0 75
michael@0 76 // Callback method for sending on socket
michael@0 77 virtual void OnSocketCanSendWithoutBlocking() {};
michael@0 78
michael@0 79 protected:
michael@0 80 UnixSocketWatcher(MessageLoop* aIOLoop);
michael@0 81 UnixSocketWatcher(MessageLoop* aIOLoop, int aFd,
michael@0 82 ConnectionStatus aConnectionStatus);
michael@0 83 void SetSocket(int aFd, ConnectionStatus aConnectionStatus);
michael@0 84
michael@0 85 private:
michael@0 86 void OnFileCanReadWithoutBlocking(int aFd) MOZ_OVERRIDE;
michael@0 87 void OnFileCanWriteWithoutBlocking(int aFd) MOZ_OVERRIDE;
michael@0 88
michael@0 89 ConnectionStatus mConnectionStatus;
michael@0 90 };
michael@0 91
michael@0 92 }
michael@0 93 }
michael@0 94
michael@0 95 #endif

mercurial