Bug 826931 - Part 2/3: UnixSocket - allow delayed connection. r=qDot

This commit is contained in:
Vicamo Yang 2013-02-01 20:28:18 +08:00
parent 5075aba1fa
commit 70b1a26645
2 changed files with 12 additions and 4 deletions

View File

@ -772,7 +772,8 @@ UnixSocketConsumer::NotifyDisconnect()
bool
UnixSocketConsumer::ConnectSocket(UnixSocketConnector* aConnector,
const char* aAddress)
const char* aAddress,
int aDelayMs)
{
MOZ_ASSERT(aConnector);
MOZ_ASSERT(NS_IsMainThread());
@ -783,8 +784,12 @@ UnixSocketConsumer::ConnectSocket(UnixSocketConnector* aConnector,
nsCString addr;
addr.Assign(aAddress);
mImpl = new UnixSocketImpl(this, aConnector, addr);
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
new SocketConnectTask(mImpl));
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
if (aDelayMs > 0) {
ioLoop->PostDelayedTask(FROM_HERE, new SocketConnectTask(mImpl), aDelayMs);
} else {
ioLoop->PostTask(FROM_HERE, new SocketConnectTask(mImpl));
}
mConnectionStatus = SOCKET_CONNECTING;
return true;
}

View File

@ -159,10 +159,13 @@ public:
*
* @param aConnector Connector object for socket type specific functions
* @param aAddress Address to connect to.
* @param aDelayMs Time delay in milli-seconds.
*
* @return true on connect task started, false otherwise.
*/
bool ConnectSocket(UnixSocketConnector* aConnector, const char* aAddress);
bool ConnectSocket(UnixSocketConnector* aConnector,
const char* aAddress,
int aDelayMs = 0);
/**
* Starts a task on the socket that will try to accept a new connection in a