1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_UnixSocketWatcher_h
8 #define mozilla_ipc_UnixSocketWatcher_h
10 #include <sys/socket.h>
11 #include <sys/types.h>
13 #include <netinet/in.h>
14 #ifdef MOZ_B2G_BT_BLUEZ
15 #include <bluetooth/bluetooth.h>
16 #include <bluetooth/sco.h>
17 #include <bluetooth/l2cap.h>
18 #include <bluetooth/rfcomm.h>
20 #include "UnixFdWatcher.h"
26 sockaddr_storage storage
; // address-family only
30 #ifdef MOZ_B2G_BT_BLUEZ
38 class UnixSocketWatcher
: public UnixFdWatcher
41 enum ConnectionStatus
{
42 SOCKET_IS_DISCONNECTED
= 0,
48 virtual ~UnixSocketWatcher();
50 virtual void Close() MOZ_OVERRIDE
;
52 ConnectionStatus
GetConnectionStatus() const
54 return mConnectionStatus
;
58 nsresult
Connect(const struct sockaddr
* aAddr
, socklen_t aAddrLen
);
60 // Listen on socket for incoming connection requests
61 nsresult
Listen(const struct sockaddr
* aAddr
, socklen_t aAddrLen
);
63 // Callback method for accepted connections
64 virtual void OnAccepted(int aFd
, const sockaddr_any
* aAddr
,
65 socklen_t aAddrLen
) {};
67 // Callback method for successful connection requests
68 virtual void OnConnected() {};
70 // Callback method for successful listen requests
71 virtual void OnListening() {};
73 // Callback method for receiving from socket
74 virtual void OnSocketCanReceiveWithoutBlocking() {};
76 // Callback method for sending on socket
77 virtual void OnSocketCanSendWithoutBlocking() {};
80 UnixSocketWatcher(MessageLoop
* aIOLoop
);
81 UnixSocketWatcher(MessageLoop
* aIOLoop
, int aFd
,
82 ConnectionStatus aConnectionStatus
);
83 void SetSocket(int aFd
, ConnectionStatus aConnectionStatus
);
86 void OnFileCanReadWithoutBlocking(int aFd
) MOZ_OVERRIDE
;
87 void OnFileCanWriteWithoutBlocking(int aFd
) MOZ_OVERRIDE
;
89 ConnectionStatus mConnectionStatus
;