2014-12-03 02:00:36 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-07-21 09:06:29 +03:00
|
|
|
#ifndef mozilla_ipc_ListenSocket_h
|
|
|
|
#define mozilla_ipc_ListenSocket_h
|
2014-12-03 02:00:36 +03:00
|
|
|
|
|
|
|
#include "mozilla/ipc/SocketBase.h"
|
2015-07-21 09:06:29 +03:00
|
|
|
#include "nsString.h"
|
2014-12-03 02:00:36 +03:00
|
|
|
|
2015-06-02 11:01:57 +03:00
|
|
|
class MessageLoop;
|
|
|
|
|
2014-12-03 02:00:36 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class ConnectionOrientedSocket;
|
2015-05-26 14:24:20 +03:00
|
|
|
class ListenSocketConsumer;
|
2014-12-03 02:00:36 +03:00
|
|
|
class ListenSocketIO;
|
|
|
|
class UnixSocketConnector;
|
|
|
|
|
2015-05-26 14:24:20 +03:00
|
|
|
class ListenSocket final : public SocketBase
|
2014-12-03 02:00:36 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-06-02 11:01:57 +03:00
|
|
|
/**
|
|
|
|
* Constructs an instance of |ListenSocket|.
|
|
|
|
*
|
|
|
|
* @param aConsumer The consumer for the socket.
|
|
|
|
* @param aIndex An arbitrary index.
|
|
|
|
*/
|
2015-05-26 14:24:20 +03:00
|
|
|
ListenSocket(ListenSocketConsumer* aConsumer, int aIndex);
|
2014-12-03 02:00:36 +03:00
|
|
|
|
2015-06-02 11:01:57 +03:00
|
|
|
/**
|
|
|
|
* Starts a task on the socket that will try to accept a new connection
|
|
|
|
* in a non-blocking manner.
|
|
|
|
*
|
|
|
|
* @param aConnector Connector object for socket-type-specific functions
|
2015-06-09 10:50:10 +03:00
|
|
|
* @param aConsumerLoop The socket's consumer thread.
|
2015-06-02 11:01:57 +03:00
|
|
|
* @param aIOLoop The socket's I/O thread.
|
|
|
|
* @param aCOSocket The connection-oriented socket for handling the
|
|
|
|
* accepted connection.
|
|
|
|
* @return NS_OK on success, or an XPCOM error code otherwise.
|
|
|
|
*/
|
|
|
|
nsresult Listen(UnixSocketConnector* aConnector,
|
2015-06-09 10:50:10 +03:00
|
|
|
MessageLoop* aConsumerLoop,
|
2015-06-02 11:01:57 +03:00
|
|
|
MessageLoop* aIOLoop,
|
|
|
|
ConnectionOrientedSocket* aCOSocket);
|
|
|
|
|
2014-12-03 02:00:36 +03:00
|
|
|
/**
|
|
|
|
* Starts a task on the socket that will try to accept a new connection
|
|
|
|
* in a non-blocking manner.
|
|
|
|
*
|
|
|
|
* @param aConnector Connector object for socket-type-specific functions
|
|
|
|
* @param aCOSocket The connection-oriented socket for handling the
|
|
|
|
* accepted connection.
|
2015-05-20 11:50:43 +03:00
|
|
|
* @return NS_OK on success, or an XPCOM error code otherwise.
|
2014-12-03 02:00:36 +03:00
|
|
|
*/
|
2015-05-20 11:50:43 +03:00
|
|
|
nsresult Listen(UnixSocketConnector* aConnector,
|
|
|
|
ConnectionOrientedSocket* aCOSocket);
|
2014-12-03 02:00:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a task on the socket that will try to accept a new connection
|
|
|
|
* in a non-blocking manner. This method re-uses a previously created
|
|
|
|
* listen socket.
|
|
|
|
*
|
|
|
|
* @param aCOSocket The connection-oriented socket for handling the
|
|
|
|
* accepted connection.
|
2015-05-20 11:50:43 +03:00
|
|
|
* @return NS_OK on success, or an XPCOM error code otherwise.
|
2014-12-03 02:00:36 +03:00
|
|
|
*/
|
2015-05-20 11:50:43 +03:00
|
|
|
nsresult Listen(ConnectionOrientedSocket* aCOSocket);
|
2014-12-03 02:00:36 +03:00
|
|
|
|
2015-04-30 13:55:37 +03:00
|
|
|
// Methods for |SocketBase|
|
|
|
|
//
|
2014-12-03 02:00:36 +03:00
|
|
|
|
2015-05-20 11:50:43 +03:00
|
|
|
void Close() override;
|
2015-05-26 14:24:20 +03:00
|
|
|
void OnConnectSuccess() override;
|
|
|
|
void OnConnectError() override;
|
|
|
|
void OnDisconnect() override;
|
2014-12-03 02:00:36 +03:00
|
|
|
|
2015-06-02 11:01:57 +03:00
|
|
|
protected:
|
|
|
|
virtual ~ListenSocket();
|
|
|
|
|
2015-04-30 13:55:37 +03:00
|
|
|
private:
|
2015-06-02 11:01:57 +03:00
|
|
|
ListenSocketIO* mIO;
|
2015-05-26 14:24:20 +03:00
|
|
|
ListenSocketConsumer* mConsumer;
|
|
|
|
int mIndex;
|
2014-12-03 02:00:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namepsace mozilla
|
|
|
|
|
2015-07-21 09:06:29 +03:00
|
|
|
#endif // mozilla_ipc_ListenSocket_h
|