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"
17 class UnixSocketConnector
;
19 class StreamSocket
: public SocketConsumerBase
20 , public ConnectionOrientedSocket
26 * Queue data to be sent to the socket on the IO thread. Can only be called on
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
);
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
);
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
,
61 * Queues the internal representation of socket for deletion. Can be called
67 * Get the current sockaddr for the socket
69 void GetSocketAddr(nsAString
& aAddrStr
);
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
);
81 // Legacy interface from |SocketBase|; should be replaced by |Close|.
82 void CloseSocket() override
91 } // namepsace mozilla
93 #endif // mozilla_ipc_streamsocket_h