зеркало из https://github.com/mozilla/pjs.git
Bug 613442, part 3: Add AsyncChannel::Echo() to allow sending a message back to the originating endpoint. r=bent
This commit is contained in:
Родитель
bb88a0c184
Коммит
121a4a5e0f
|
@ -247,6 +247,33 @@ AsyncChannel::Send(Message* msg)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
AsyncChannel::Echo(Message* msg)
|
||||
{
|
||||
AssertWorkerThread();
|
||||
mMonitor.AssertNotCurrentThreadOwns();
|
||||
NS_ABORT_IF_FALSE(MSG_ROUTING_NONE != msg->routing_id(), "need a route");
|
||||
|
||||
{
|
||||
MonitorAutoLock lock(mMonitor);
|
||||
|
||||
if (!Connected()) {
|
||||
ReportConnectionError("AsyncChannel");
|
||||
return false;
|
||||
}
|
||||
|
||||
// NB: Go through this OnMessageReceived indirection so that
|
||||
// echoing this message does the right thing for SyncChannel
|
||||
// and RPCChannel too
|
||||
mIOLoop->PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableMethod(this, &AsyncChannel::OnEchoMessage, msg));
|
||||
// OnEchoMessage takes ownership of |msg|
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
AsyncChannel::OnDispatchMessage(const Message& msg)
|
||||
{
|
||||
|
@ -470,6 +497,14 @@ AsyncChannel::OnMessageReceived(const Message& msg)
|
|||
NewRunnableMethod(this, &AsyncChannel::OnDispatchMessage, msg));
|
||||
}
|
||||
|
||||
void
|
||||
AsyncChannel::OnEchoMessage(Message* msg)
|
||||
{
|
||||
AssertIOThread();
|
||||
OnMessageReceived(*msg);
|
||||
delete msg;
|
||||
}
|
||||
|
||||
void
|
||||
AsyncChannel::OnChannelOpened()
|
||||
{
|
||||
|
|
|
@ -117,6 +117,10 @@ public:
|
|||
// Asynchronously send a message to the other side of the channel
|
||||
virtual bool Send(Message* msg);
|
||||
|
||||
// Asynchronously deliver a message back to this side of the
|
||||
// channel
|
||||
virtual bool Echo(Message* msg);
|
||||
|
||||
// Send OnChannelConnected notification to listeners.
|
||||
void DispatchOnChannelConnected(int32 peer_pid);
|
||||
|
||||
|
@ -177,6 +181,7 @@ protected:
|
|||
void OnChannelOpened();
|
||||
void OnCloseChannel();
|
||||
void PostErrorNotifyTask();
|
||||
void OnEchoMessage(Message* msg);
|
||||
|
||||
// Return true if |msg| is a special message targeted at the IO
|
||||
// thread, in which case it shouldn't be delivered to the worker.
|
||||
|
|
Загрузка…
Ссылка в новой задаче