Fix typo in 9b54bd30006c008b4a951331b273613d5bac3abf
[pm.git] / ipc / unixsocket / StreamSocket.h
blob54e2efef59d471dd490a8b4d4cae657a9d0ca9e6
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_streamsocket_h
8 #define mozilla_ipc_streamsocket_h
10 #include "mozilla/ipc/SocketBase.h"
11 #include "ConnectionOrientedSocket.h"
13 namespace mozilla {
14 namespace ipc {
16 class StreamSocketIO;
17 class UnixSocketConnector;
19 class StreamSocket : public SocketConsumerBase
20 , public ConnectionOrientedSocket
22 public:
23 StreamSocket();
25 /**
26 * Queue data to be sent to the socket on the IO thread. Can only be called on
27 * originating thread.
29 * @param aMessage Data to be sent to socket
31 * @return true if data is queued, false otherwise (i.e. not connected)
33 bool SendSocketData(UnixSocketRawData* aMessage);
35 /**
36 * Convenience function for sending strings to the socket (common in bluetooth
37 * profile usage). Converts to a UnixSocketRawData struct. Can only be called
38 * on originating thread.
40 * @param aMessage String to be sent to socket
42 * @return true if data is queued, false otherwise (i.e. not connected)
44 bool SendSocketData(const nsACString& aMessage);
46 /**
47 * Starts a task on the socket that will try to connect to a socket in a
48 * non-blocking manner.
50 * @param aConnector Connector object for socket type specific functions
51 * @param aAddress Address to connect to.
52 * @param aDelayMs Time delay in milli-seconds.
54 * @return true on connect task started, false otherwise.
56 bool Connect(UnixSocketConnector* aConnector,
57 const char* aAddress,
58 int aDelayMs = 0);
60 /**
61 * Queues the internal representation of socket for deletion. Can be called
62 * from main thread.
64 void Close();
66 /**
67 * Get the current sockaddr for the socket
69 void GetSocketAddr(nsAString& aAddrStr);
71 protected:
72 virtual ~StreamSocket();
74 // Prepares an instance of |StreamSocket| in DISCONNECTED state
75 // for accepting a connection. Subclasses implementing |GetIO|
76 // need to call this method.
77 ConnectionOrientedSocketIO* PrepareAccept(UnixSocketConnector* aConnector);
79 private:
81 // Legacy interface from |SocketBase|; should be replaced by |Close|.
82 void CloseSocket() override
84 Close();
87 StreamSocketIO* mIO;
90 } // namespace ipc
91 } // namepsace mozilla
93 #endif // mozilla_ipc_streamsocket_h