Bug 1046109: Add |SocketIOEventRunnable|, r=kyle
|SocketIOEventRunnable| sends a notification from the Socket I/O object to a Socket consumer on the main thread.
This commit is contained in:
@@ -134,6 +134,11 @@ public:
|
||||
void OnSocketCanReceiveWithoutBlocking() MOZ_OVERRIDE;
|
||||
void OnSocketCanSendWithoutBlocking() MOZ_OVERRIDE;
|
||||
|
||||
SocketConsumerBase* GetConsumer()
|
||||
{
|
||||
return mConsumer.get();
|
||||
}
|
||||
|
||||
private:
|
||||
// Set up flags on whatever our current file descriptor is.
|
||||
static bool SetSocketFlags(int aFd);
|
||||
@@ -196,47 +201,6 @@ private:
|
||||
T* mInstance;
|
||||
};
|
||||
|
||||
class OnSocketEventRunnable : public SocketIORunnable<UnixSocketImpl>
|
||||
{
|
||||
public:
|
||||
enum SocketEvent {
|
||||
CONNECT_SUCCESS,
|
||||
CONNECT_ERROR,
|
||||
DISCONNECT
|
||||
};
|
||||
|
||||
OnSocketEventRunnable(UnixSocketImpl* aImpl, SocketEvent e)
|
||||
: SocketIORunnable<UnixSocketImpl>(aImpl)
|
||||
, mEvent(e)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
}
|
||||
|
||||
NS_IMETHOD Run() MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
UnixSocketImpl* impl = GetIO();
|
||||
|
||||
if (impl->IsShutdownOnMainThread()) {
|
||||
NS_WARNING("CloseSocket has already been called!");
|
||||
// Since we've already explicitly closed and the close happened before
|
||||
// this, this isn't really an error. Since we've warned, return OK.
|
||||
return NS_OK;
|
||||
}
|
||||
if (mEvent == CONNECT_SUCCESS) {
|
||||
impl->mConsumer->NotifySuccess();
|
||||
} else if (mEvent == CONNECT_ERROR) {
|
||||
impl->mConsumer->NotifyError();
|
||||
} else if (mEvent == DISCONNECT) {
|
||||
impl->mConsumer->NotifyDisconnect();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
private:
|
||||
SocketEvent mEvent;
|
||||
};
|
||||
|
||||
class SocketReceiveRunnable : public SocketIORunnable<UnixSocketImpl>
|
||||
{
|
||||
public:
|
||||
@@ -436,8 +400,10 @@ UnixSocketImpl::FireSocketError()
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
nsRefPtr<OnSocketEventRunnable> r =
|
||||
new OnSocketEventRunnable(this, OnSocketEventRunnable::CONNECT_ERROR);
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<UnixSocketImpl>(
|
||||
this, SocketIOEventRunnable<UnixSocketImpl>::CONNECT_ERROR);
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
}
|
||||
|
||||
@@ -566,8 +532,9 @@ UnixSocketImpl::OnAccepted(int aFd,
|
||||
}
|
||||
SetSocket(aFd, SOCKET_IS_CONNECTED);
|
||||
|
||||
nsRefPtr<OnSocketEventRunnable> r =
|
||||
new OnSocketEventRunnable(this, OnSocketEventRunnable::CONNECT_SUCCESS);
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<UnixSocketImpl>(
|
||||
this, SocketIOEventRunnable<UnixSocketImpl>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
@@ -594,8 +561,9 @@ UnixSocketImpl::OnConnected()
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<OnSocketEventRunnable> r =
|
||||
new OnSocketEventRunnable(this, OnSocketEventRunnable::CONNECT_SUCCESS);
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<UnixSocketImpl>(
|
||||
this, SocketIOEventRunnable<UnixSocketImpl>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
|
||||
Reference in New Issue
Block a user