Fix typo in 9b54bd30006c008b4a951331b273613d5bac3abf
[pm.git] / ipc / unixsocket / UnixSocket.h
blob9867c796f8d44f1fc8fcc6a4cf1eaa352b4af50d
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_unixsocket_h
8 #define mozilla_ipc_unixsocket_h
10 #include <stdlib.h>
11 #include "nsAutoPtr.h"
12 #include "nsString.h"
13 #include "nsThreadUtils.h"
14 #include "mozilla/ipc/SocketBase.h"
15 #include "mozilla/ipc/UnixSocketWatcher.h"
16 #include "mozilla/RefPtr.h"
17 #include "UnixSocketConnector.h"
19 namespace mozilla {
20 namespace ipc {
22 class UnixSocketConsumerIO;
24 class UnixSocketConsumer : public SocketConsumerBase
26 protected:
27 virtual ~UnixSocketConsumer();
29 public:
30 UnixSocketConsumer();
32 /**
33 * Queue data to be sent to the socket on the IO thread. Can only be called on
34 * originating thread.
36 * @param aMessage Data to be sent to socket
38 * @return true if data is queued, false otherwise (i.e. not connected)
40 bool SendSocketData(UnixSocketRawData* aMessage);
42 /**
43 * Convenience function for sending strings to the socket (common in bluetooth
44 * profile usage). Converts to a UnixSocketRawData struct. Can only be called
45 * on originating thread.
47 * @param aMessage String to be sent to socket
49 * @return true if data is queued, false otherwise (i.e. not connected)
51 bool SendSocketData(const nsACString& aMessage);
53 /**
54 * Starts a task on the socket that will try to connect to a socket in a
55 * non-blocking manner.
57 * @param aConnector Connector object for socket type specific functions
58 * @param aAddress Address to connect to.
59 * @param aDelayMs Time delay in milli-seconds.
61 * @return true on connect task started, false otherwise.
63 bool ConnectSocket(UnixSocketConnector* aConnector,
64 const char* aAddress,
65 int aDelayMs = 0);
67 /**
68 * Starts a task on the socket that will try to accept a new connection in a
69 * non-blocking manner.
71 * @param aConnector Connector object for socket type specific functions
73 * @return true on listen started, false otherwise
75 bool ListenSocket(UnixSocketConnector* aConnector);
77 /**
78 * Queues the internal representation of socket for deletion. Can be called
79 * from main thread.
81 void CloseSocket();
83 /**
84 * Get the current sockaddr for the socket
86 void GetSocketAddr(nsAString& aAddrStr);
88 private:
89 UnixSocketConsumerIO* mIO;
92 } // namespace ipc
93 } // namepsace mozilla
95 #endif // mozilla_ipc_unixsocket_h