mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1168806: Configurable I/O thread for socket IPC classes, r=kmachulis
The I/O thread sends and receives data on a file descriptor. This has traditionally been performed on a single I/O thread. This patch extends the socket IPC classes to support arbitrary I/O threads. The thread is configured when a connection is established and used until the socket gets closed.
This commit is contained in:
parent
b86d1d9857
commit
d8e16014cd
@ -398,8 +398,8 @@ public:
|
||||
}
|
||||
|
||||
mImpl->mConsumer->SetAddress(aBdAddress);
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
||||
new AcceptTask(mImpl, fd.forget()));
|
||||
mImpl->GetIOLoop()->PostTask(FROM_HERE,
|
||||
new AcceptTask(mImpl, fd.forget()));
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
@ -615,8 +615,8 @@ public:
|
||||
}
|
||||
|
||||
mImpl->mConsumer->SetAddress(aBdAddress);
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
||||
new SocketConnectTask(mImpl, aFd));
|
||||
mImpl->GetIOLoop()->PostTask(FROM_HERE,
|
||||
new SocketConnectTask(mImpl, aFd));
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
@ -642,14 +642,15 @@ BluetoothSocket::Connect(const nsAString& aDeviceAddress,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt)
|
||||
bool aAuth, bool aEncrypt,
|
||||
MessageLoop* aIOLoop)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mImpl);
|
||||
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
mImpl = new DroidSocketImpl(XRE_GetIOMessageLoop(), this);
|
||||
mImpl = new DroidSocketImpl(aIOLoop, this);
|
||||
|
||||
BluetoothSocketResultHandler* res = new ConnectSocketResultHandler(mImpl);
|
||||
SetCurrentResultHandler(res);
|
||||
@ -662,6 +663,17 @@ BluetoothSocket::Connect(const nsAString& aDeviceAddress,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Connect(const nsAString& aDeviceAddress,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt)
|
||||
{
|
||||
return Connect(aDeviceAddress, aServiceUuid, aType, aChannel, aAuth,
|
||||
aEncrypt, XRE_GetIOMessageLoop());
|
||||
}
|
||||
|
||||
class ListenResultHandler final : public BluetoothSocketResultHandler
|
||||
{
|
||||
public:
|
||||
@ -675,8 +687,7 @@ public:
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
||||
new SocketListenTask(mImpl, aFd));
|
||||
mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketListenTask(mImpl, aFd));
|
||||
}
|
||||
|
||||
void OnError(BluetoothStatus aStatus) override
|
||||
@ -695,14 +706,15 @@ BluetoothSocket::Listen(const nsAString& aServiceName,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt)
|
||||
bool aAuth, bool aEncrypt,
|
||||
MessageLoop* aIOLoop)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mImpl);
|
||||
|
||||
SetConnectionStatus(SOCKET_LISTENING);
|
||||
|
||||
mImpl = new DroidSocketImpl(XRE_GetIOMessageLoop(), this);
|
||||
mImpl = new DroidSocketImpl(aIOLoop, this);
|
||||
|
||||
BluetoothSocketResultHandler* res = new ListenResultHandler(mImpl);
|
||||
SetCurrentResultHandler(res);
|
||||
@ -715,6 +727,17 @@ BluetoothSocket::Listen(const nsAString& aServiceName,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Listen(const nsAString& aServiceName,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt)
|
||||
{
|
||||
return Listen(aServiceName, aServiceUuid, aType, aChannel, aAuth, aEncrypt,
|
||||
XRE_GetIOMessageLoop());
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
|
||||
{
|
||||
@ -733,7 +756,7 @@ BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
MOZ_ASSERT(mImpl);
|
||||
MOZ_ASSERT(!mImpl->IsShutdownOnMainThread());
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
mImpl->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
new SocketIOSendTask<DroidSocketImpl, UnixSocketIOBuffer>(mImpl, aBuffer));
|
||||
}
|
||||
@ -758,9 +781,7 @@ BluetoothSocket::Close()
|
||||
// We sever the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mImpl->ShutdownOnMainThread();
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
|
||||
|
||||
mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
|
||||
mImpl = nullptr;
|
||||
|
||||
NotifyDisconnect();
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "BluetoothCommon.h"
|
||||
#include "mozilla/ipc/DataSocket.h"
|
||||
|
||||
class MessageLoop;
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocketObserver;
|
||||
@ -21,12 +23,26 @@ class BluetoothSocket final : public mozilla::ipc::DataSocket
|
||||
public:
|
||||
BluetoothSocket(BluetoothSocketObserver* aObserver);
|
||||
|
||||
nsresult Connect(const nsAString& aDeviceAddress,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt,
|
||||
MessageLoop* aIOLoop);
|
||||
|
||||
nsresult Connect(const nsAString& aDeviceAddress,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt);
|
||||
|
||||
nsresult Listen(const nsAString& aServiceName,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
int aChannel,
|
||||
bool aAuth, bool aEncrypt,
|
||||
MessageLoop* aIOLoop);
|
||||
|
||||
nsresult Listen(const nsAString& aServiceName,
|
||||
const BluetoothUuid& aServiceUuid,
|
||||
BluetoothSocketType aType,
|
||||
|
@ -549,7 +549,7 @@ public:
|
||||
}
|
||||
|
||||
io->ClearDelayedConnectTask();
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new ConnectTask(io));
|
||||
io->GetIOLoop()->PostTask(FROM_HERE, new ConnectTask(io));
|
||||
}
|
||||
};
|
||||
|
||||
@ -645,39 +645,55 @@ BluetoothSocket::SendSocketData(const nsACString& aStr)
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Connect(BluetoothUnixSocketConnector* aConnector,
|
||||
int aDelayMs)
|
||||
int aDelayMs, MessageLoop* aIOLoop)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aConnector);
|
||||
MOZ_ASSERT(aIOLoop);
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
|
||||
mIO = new BluetoothSocketIO(ioLoop, this, aConnector);
|
||||
mIO = new BluetoothSocketIO(aIOLoop, this, aConnector);
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
if (aDelayMs > 0) {
|
||||
DelayedConnectTask* connectTask = new DelayedConnectTask(mIO);
|
||||
mIO->SetDelayedConnectTask(connectTask);
|
||||
MessageLoop::current()->PostDelayedTask(FROM_HERE, connectTask, aDelayMs);
|
||||
} else {
|
||||
ioLoop->PostTask(FROM_HERE, new ConnectTask(mIO));
|
||||
aIOLoop->PostTask(FROM_HERE, new ConnectTask(mIO));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Connect(BluetoothUnixSocketConnector* aConnector,
|
||||
int aDelayMs)
|
||||
{
|
||||
return Connect(aConnector, aDelayMs, XRE_GetIOMessageLoop());
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Listen(BluetoothUnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aConnector);
|
||||
MOZ_ASSERT(aIOLoop);
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
mIO = new BluetoothSocketIO(aIOLoop, this, aConnector);
|
||||
SetConnectionStatus(SOCKET_LISTENING);
|
||||
|
||||
aIOLoop->PostTask(FROM_HERE, new ListenTask(mIO));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Listen(BluetoothUnixSocketConnector* aConnector)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aConnector);
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
|
||||
|
||||
mIO = new BluetoothSocketIO(ioLoop, this, aConnector);
|
||||
SetConnectionStatus(SOCKET_LISTENING);
|
||||
ioLoop->PostTask(FROM_HERE, new ListenTask(mIO));
|
||||
|
||||
return NS_OK;
|
||||
return Listen(aConnector, XRE_GetIOMessageLoop());
|
||||
}
|
||||
|
||||
void
|
||||
@ -700,7 +716,7 @@ BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
MOZ_ASSERT(mIO);
|
||||
MOZ_ASSERT(!mIO->IsShutdownOnMainThread());
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
mIO->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
new SocketIOSendTask<BluetoothSocketIO, UnixSocketIOBuffer>(mIO, aBuffer));
|
||||
}
|
||||
@ -721,9 +737,7 @@ BluetoothSocket::Close()
|
||||
// We sever the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mIO->ShutdownOnMainThread();
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
NotifyDisconnect();
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "nsString.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
class MessageLoop;
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
class BluetoothSocketObserver;
|
||||
@ -58,6 +60,18 @@ public:
|
||||
*/
|
||||
bool SendSocketData(const nsACString& aMessage);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to connect to a socket in a
|
||||
* non-blocking manner.
|
||||
*
|
||||
* @param aConnector Connector object for socket type specific functions
|
||||
* @param aDelayMs Time delay in milli-seconds.
|
||||
* @param aIOLoop The socket's I/O thread.
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
nsresult Connect(BluetoothUnixSocketConnector* aConnector,
|
||||
int aDelayMs, MessageLoop* aIOLoop);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to connect to a socket in a
|
||||
* non-blocking manner.
|
||||
@ -69,6 +83,17 @@ public:
|
||||
nsresult Connect(BluetoothUnixSocketConnector* aConnector,
|
||||
int aDelayMs = 0);
|
||||
|
||||
/**
|
||||
* 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 aIOLoop The socket's I/O thread.
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
nsresult Listen(BluetoothUnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to accept a new connection in a
|
||||
* non-blocking manner.
|
||||
|
@ -437,10 +437,10 @@ BluetoothDaemonConnection::BluetoothDaemonConnection(
|
||||
BluetoothDaemonPDUConsumer* aPDUConsumer,
|
||||
BluetoothDaemonConnectionConsumer* aConsumer,
|
||||
int aIndex)
|
||||
: mPDUConsumer(aPDUConsumer)
|
||||
: mIO(nullptr)
|
||||
, mPDUConsumer(aPDUConsumer)
|
||||
, mConsumer(aConsumer)
|
||||
, mIndex(aIndex)
|
||||
, mIO(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(mConsumer);
|
||||
}
|
||||
@ -452,6 +452,7 @@ BluetoothDaemonConnection::~BluetoothDaemonConnection()
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonConnection::PrepareAccept(UnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocketIO*& aIO)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@ -465,7 +466,7 @@ BluetoothDaemonConnection::PrepareAccept(UnixSocketConnector* aConnector,
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
mIO = new BluetoothDaemonConnectionIO(
|
||||
XRE_GetIOMessageLoop(), -1, UnixSocketWatcher::SOCKET_IS_CONNECTING,
|
||||
aIOLoop, -1, UnixSocketWatcher::SOCKET_IS_CONNECTING,
|
||||
this, mPDUConsumer);
|
||||
aIO = mIO;
|
||||
|
||||
@ -480,7 +481,7 @@ BluetoothDaemonConnection::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mIO);
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
mIO->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
new SocketIOSendTask<BluetoothDaemonConnectionIO,
|
||||
UnixSocketIOBuffer>(mIO, aBuffer));
|
||||
@ -498,8 +499,7 @@ BluetoothDaemonConnection::Close()
|
||||
return;
|
||||
}
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
NotifyDisconnect();
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "mozilla/ipc/ConnectionOrientedSocket.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
class MessageLoop;
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
@ -123,6 +125,7 @@ public:
|
||||
//
|
||||
|
||||
nsresult PrepareAccept(UnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocketIO*& aIO) override;
|
||||
|
||||
// Methods for |DataSocket|
|
||||
@ -139,10 +142,10 @@ public:
|
||||
void OnDisconnect() override;
|
||||
|
||||
private:
|
||||
BluetoothDaemonConnectionIO* mIO;
|
||||
BluetoothDaemonPDUConsumer* mPDUConsumer;
|
||||
BluetoothDaemonConnectionConsumer* mConsumer;
|
||||
int mIndex;
|
||||
BluetoothDaemonConnectionIO* mIO;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <sys/socket.h>
|
||||
#include "DataSocket.h"
|
||||
|
||||
class MessageLoop;
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
@ -40,10 +42,12 @@ public:
|
||||
*
|
||||
* @param aConnector The new connector object, owned by the
|
||||
* connection-oriented socket.
|
||||
* @param aIOLoop The socket's I/O thread.
|
||||
* @param[out] aIO, Returns an instance of |ConnectionOrientedSocketIO|.
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
virtual nsresult PrepareAccept(UnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocketIO*& aIO) = 0;
|
||||
|
||||
protected:
|
||||
|
@ -293,9 +293,9 @@ private:
|
||||
//
|
||||
|
||||
ListenSocket::ListenSocket(ListenSocketConsumer* aConsumer, int aIndex)
|
||||
: mConsumer(aConsumer)
|
||||
: mIO(nullptr)
|
||||
, mConsumer(aConsumer)
|
||||
, mIndex(aIndex)
|
||||
, mIO(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(mConsumer);
|
||||
}
|
||||
@ -307,12 +307,13 @@ ListenSocket::~ListenSocket()
|
||||
|
||||
nsresult
|
||||
ListenSocket::Listen(UnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocket* aCOSocket)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
mIO = new ListenSocketIO(XRE_GetIOMessageLoop(), this, aConnector);
|
||||
mIO = new ListenSocketIO(aIOLoop, this, aConnector);
|
||||
|
||||
// Prepared I/O object, now start listening.
|
||||
nsresult rv = Listen(aCOSocket);
|
||||
@ -325,6 +326,13 @@ ListenSocket::Listen(UnixSocketConnector* aConnector,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ListenSocket::Listen(UnixSocketConnector* aConnector,
|
||||
ConnectionOrientedSocket* aCOSocket)
|
||||
{
|
||||
return Listen(aConnector, XRE_GetIOMessageLoop(), aCOSocket);
|
||||
}
|
||||
|
||||
nsresult
|
||||
ListenSocket::Listen(ConnectionOrientedSocket* aCOSocket)
|
||||
{
|
||||
@ -342,7 +350,8 @@ ListenSocket::Listen(ConnectionOrientedSocket* aCOSocket)
|
||||
}
|
||||
|
||||
nsAutoPtr<ConnectionOrientedSocketIO> io;
|
||||
rv = aCOSocket->PrepareAccept(connector, *io.StartAssignment());
|
||||
rv = aCOSocket->PrepareAccept(connector, mIO->GetIOLoop(),
|
||||
*io.StartAssignment());
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
@ -352,7 +361,7 @@ ListenSocket::Listen(ConnectionOrientedSocket* aCOSocket)
|
||||
|
||||
SetConnectionStatus(SOCKET_LISTENING);
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
mIO->GetIOLoop()->PostTask(
|
||||
FROM_HERE, new ListenSocketIO::ListenTask(mIO, io.forget()));
|
||||
|
||||
return NS_OK;
|
||||
@ -373,9 +382,7 @@ ListenSocket::Close()
|
||||
// the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mIO->ShutdownOnMainThread();
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
NotifyDisconnect();
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "nsString.h"
|
||||
#include "mozilla/ipc/SocketBase.h"
|
||||
|
||||
class MessageLoop;
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
@ -20,12 +22,29 @@ class UnixSocketConnector;
|
||||
|
||||
class ListenSocket final : public SocketBase
|
||||
{
|
||||
protected:
|
||||
virtual ~ListenSocket();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs an instance of |ListenSocket|.
|
||||
*
|
||||
* @param aConsumer The consumer for the socket.
|
||||
* @param aIndex An arbitrary index.
|
||||
*/
|
||||
ListenSocket(ListenSocketConsumer* aConsumer, int aIndex);
|
||||
|
||||
/**
|
||||
* 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 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,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocket* aCOSocket);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to accept a new connection
|
||||
* in a non-blocking manner.
|
||||
@ -57,10 +76,13 @@ public:
|
||||
void OnConnectError() override;
|
||||
void OnDisconnect() override;
|
||||
|
||||
protected:
|
||||
virtual ~ListenSocket();
|
||||
|
||||
private:
|
||||
ListenSocketIO* mIO;
|
||||
ListenSocketConsumer* mConsumer;
|
||||
int mIndex;
|
||||
ListenSocketIO* mIO;
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
|
@ -476,7 +476,7 @@ class StreamSocketIO::DelayedConnectTask final
|
||||
{
|
||||
public:
|
||||
DelayedConnectTask(StreamSocketIO* aIO)
|
||||
: SocketIOTask<StreamSocketIO>(aIO)
|
||||
: SocketIOTask<StreamSocketIO>(aIO)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
@ -493,7 +493,7 @@ public:
|
||||
}
|
||||
|
||||
io->ClearDelayedConnectTask();
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new ConnectTask(io));
|
||||
io->GetIOLoop()->PostTask(FROM_HERE, new ConnectTask(io));
|
||||
}
|
||||
};
|
||||
|
||||
@ -502,9 +502,9 @@ public:
|
||||
//
|
||||
|
||||
StreamSocket::StreamSocket(StreamSocketConsumer* aConsumer, int aIndex)
|
||||
: mConsumer(aConsumer)
|
||||
: mIO(nullptr)
|
||||
, mConsumer(aConsumer)
|
||||
, mIndex(aIndex)
|
||||
, mIO(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(mConsumer);
|
||||
}
|
||||
@ -523,14 +523,13 @@ StreamSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
|
||||
}
|
||||
|
||||
nsresult
|
||||
StreamSocket::Connect(UnixSocketConnector* aConnector,
|
||||
int aDelayMs)
|
||||
StreamSocket::Connect(UnixSocketConnector* aConnector, int aDelayMs,
|
||||
MessageLoop* aIOLoop)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mIO);
|
||||
|
||||
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
|
||||
mIO = new StreamSocketIO(ioLoop, this, aConnector);
|
||||
mIO = new StreamSocketIO(aIOLoop, this, aConnector);
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
if (aDelayMs > 0) {
|
||||
@ -539,15 +538,22 @@ StreamSocket::Connect(UnixSocketConnector* aConnector,
|
||||
mIO->SetDelayedConnectTask(connectTask);
|
||||
MessageLoop::current()->PostDelayedTask(FROM_HERE, connectTask, aDelayMs);
|
||||
} else {
|
||||
ioLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
|
||||
aIOLoop->PostTask(FROM_HERE, new StreamSocketIO::ConnectTask(mIO));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
StreamSocket::Connect(UnixSocketConnector* aConnector, int aDelayMs)
|
||||
{
|
||||
return Connect(aConnector, aDelayMs, XRE_GetIOMessageLoop());
|
||||
}
|
||||
|
||||
// |ConnectionOrientedSocket|
|
||||
|
||||
nsresult
|
||||
StreamSocket::PrepareAccept(UnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocketIO*& aIO)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@ -556,7 +562,7 @@ StreamSocket::PrepareAccept(UnixSocketConnector* aConnector,
|
||||
|
||||
SetConnectionStatus(SOCKET_CONNECTING);
|
||||
|
||||
mIO = new StreamSocketIO(XRE_GetIOMessageLoop(),
|
||||
mIO = new StreamSocketIO(aIOLoop,
|
||||
-1, UnixSocketWatcher::SOCKET_IS_CONNECTING,
|
||||
this, aConnector);
|
||||
aIO = mIO;
|
||||
@ -573,7 +579,7 @@ StreamSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
MOZ_ASSERT(mIO);
|
||||
|
||||
MOZ_ASSERT(!mIO->IsShutdownOnMainThread());
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
mIO->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
new SocketIOSendTask<StreamSocketIO, UnixSocketIOBuffer>(mIO, aBuffer));
|
||||
}
|
||||
@ -592,9 +598,7 @@ StreamSocket::Close()
|
||||
// the relationship here so any future calls to |Connect| will create
|
||||
// a new I/O object.
|
||||
mIO->ShutdownOnMainThread();
|
||||
|
||||
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
NotifyDisconnect();
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "ConnectionOrientedSocket.h"
|
||||
|
||||
class MessageLoop;
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
@ -19,6 +21,12 @@ class UnixSocketConnector;
|
||||
class StreamSocket final : public ConnectionOrientedSocket
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs an instance of |StreamSocket|.
|
||||
*
|
||||
* @param aConsumer The consumer for the socket.
|
||||
* @param aIndex An arbitrary index.
|
||||
*/
|
||||
StreamSocket(StreamSocketConsumer* aConsumer, int aIndex);
|
||||
|
||||
/**
|
||||
@ -28,6 +36,18 @@ public:
|
||||
*/
|
||||
void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to connect to a socket in a
|
||||
* non-blocking manner.
|
||||
*
|
||||
* @param aConnector Connector object for socket type specific functions
|
||||
* @param aDelayMs Time delay in milliseconds.
|
||||
* @param aIOLoop The socket's I/O thread.
|
||||
* @return NS_OK on success, or an XPCOM error code otherwise.
|
||||
*/
|
||||
nsresult Connect(UnixSocketConnector* aConnector, int aDelayMs,
|
||||
MessageLoop* aIOLoop);
|
||||
|
||||
/**
|
||||
* Starts a task on the socket that will try to connect to a socket in a
|
||||
* non-blocking manner.
|
||||
@ -42,6 +62,7 @@ public:
|
||||
//
|
||||
|
||||
nsresult PrepareAccept(UnixSocketConnector* aConnector,
|
||||
MessageLoop* aIOLoop,
|
||||
ConnectionOrientedSocketIO*& aIO) override;
|
||||
|
||||
// Methods for |DataSocket|
|
||||
@ -61,9 +82,9 @@ protected:
|
||||
virtual ~StreamSocket();
|
||||
|
||||
private:
|
||||
StreamSocketIO* mIO;
|
||||
StreamSocketConsumer* mConsumer;
|
||||
int mIndex;
|
||||
StreamSocketIO* mIO;
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
|
Loading…
Reference in New Issue
Block a user