/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: sw=2 ts=4 et :
*/ /* 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/. */
mObserver = new PortObserverThunk(mChan->mMonitor, this);
mNode->SetPortObserver(mPort, mObserver);
// Dispatch an event to the IO loop to trigger an initial // `OnPortStatusChanged` to deliver any pending messages. This needs to be run // asynchronously from a different thread (or in the case of a same-thread // channel, from the current thread), for now due to assertions in // `MessageChannel`.
nsCOMPtr<nsIRunnable> openRunnable = NewRunnableMethod( "PortLink::Open", mObserver, &PortObserverThunk::OnPortStatusChanged); if (aChan->mIsSameThreadChannel) {
aChan->mWorkerThread->Dispatch(openRunnable.forget());
} else {
XRE_GetAsyncIOEventTarget()->Dispatch(openRunnable.forget());
}
}
PortLink::~PortLink() {
MOZ_RELEASE_ASSERT(!mObserver, "PortLink destroyed without being closed!");
}
if (aMessage->size() > IPC::Channel::kMaximumMessageSize) {
CrashReporter::RecordAnnotationCString(
CrashReporter::Annotation::IPCMessageName, aMessage->name());
CrashReporter::RecordAnnotationU32(
CrashReporter::Annotation::IPCMessageSize, aMessage->size());
CrashReporter::RecordAnnotationU32(
CrashReporter::Annotation::IPCMessageLargeBufferShmemFailureSize,
aMessage->LargeBufferShmemFailureSize());
MOZ_CRASH("IPC message size is too large");
}
aMessage->AssertAsLargeAsHeader();
RefPtr<PortObserverThunk> observer = mObserver; if (!observer) {
NS_WARNING("Ignoring message to closed PortLink"); return;
}
// Make local copies of relevant member variables, so we can unlock the // monitor for the rest of this function. This protects us in case `this` is // deleted during the call (although that shouldn't happen in practice). // // We don't want the monitor to be held when calling into ports, as we may be // re-entrantly called by our `PortObserverThunk` which will attempt to // acquire the monitor.
RefPtr<RefCountedMonitor> monitor = mChan->mMonitor;
RefPtr<NodeController> node = mNode;
PortRef port = mPort;
bool ok = false;
monitor->AssertCurrentThreadOwns();
{
MonitorAutoUnlock guard(*monitor);
ok = node->SendUserMessage(port, std::move(aMessage));
} if (!ok) { // The send failed, but double-check that we weren't closed racily while // sending, which could lead to an invalid state error. if (observer->mLink) {
MOZ_CRASH("Invalid argument to SendUserMessage");
}
NS_WARNING("Message dropped as PortLink was closed");
}
}
// NOTE: We're calling into `ports` with our monitor held! Usually, this could // lead to deadlocks due to the PortObserverThunk acquiring the lock // re-entrantly, but is OK here as we're immediately clearing the port's // observer. We shouldn't have issues with any re-entrant calls on this thread // acquiring this MessageChannel's monitor. // // We also clear out the reference in `mObserver` back to this type so that // notifications from other threads won't try to call us again once we release // the monitor.
mNode->SetPortObserver(mPort, nullptr);
mObserver->mLink = nullptr;
mObserver = nullptr;
mNode->ClosePort(mPort);
}
// Check if the port's remoteness status has updated, and tell our channel if // it has. if (Maybe<PortStatus> status = mNode->GetStatus(mPort);
status && status->peer_remote != mChan->IsCrossProcess()) {
mChan->SetIsCrossProcess(status->peer_remote);
}
while (mObserver) {
UniquePtr<IPC::Message> message; if (!mNode->GetMessage(mPort, &message)) {
Clear();
mChan->OnChannelErrorFromLink(); return;
} if (!message) { return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.