void UDPSocketParent::Send(const InputStreamParams& aStream, const UDPSocketAddr& aAddr) { nsTArray<mozilla::ipc::FileDescriptor> fds; nsCOMPtr<nsIInputStream> stream = DeserializeInputStream(aStream, fds); if (NS_WARN_IF(!stream)) { return; } nsresult rv; switch(aAddr.type()) { case UDPSocketAddr::TUDPAddressInfo: { const UDPAddressInfo& addrInfo(aAddr.get_UDPAddressInfo()); rv = mSocket->SendBinaryStream(addrInfo.addr(), addrInfo.port(), stream); break; } case UDPSocketAddr::TNetAddr: { const NetAddr& addr(aAddr.get_NetAddr()); rv = mSocket->SendBinaryStreamWithAddress(&addr, stream); break; } default: MOZ_ASSERT(false, "Invalid address type!"); return; } if (NS_FAILED(rv)) { FireInternalError(__LINE__); } }
// static already_AddRefed<ReadStream> ReadStream::Create(const CacheReadStream& aReadStream) { // The parameter may or may not be for a Cache created stream. The way we // tell is by looking at the stream control actor. If the actor exists, // then we know the Cache created it. if (!aReadStream.controlChild() && !aReadStream.controlParent()) { return nullptr; } MOZ_ASSERT(!aReadStream.pushStreamChild()); MOZ_ASSERT(!aReadStream.pushStreamParent()); // Control is guaranteed to survive this method as ActorDestroy() cannot // run on this thread until we complete. StreamControl* control; if (aReadStream.controlChild()) { auto actor = static_cast<CacheStreamControlChild*>(aReadStream.controlChild()); control = actor; } else { auto actor = static_cast<CacheStreamControlParent*>(aReadStream.controlParent()); control = actor; } MOZ_ASSERT(control); AutoTArray<FileDescriptor, 4> fds; control->DeserializeFds(aReadStream, fds); nsCOMPtr<nsIInputStream> stream = DeserializeInputStream(aReadStream.params(), fds); MOZ_ASSERT(stream); // Currently we expect all cache read streams to be blocking file streams. #ifdef DEBUG nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(stream); MOZ_ASSERT(!asyncStream); #endif RefPtr<Inner> inner = new Inner(control, aReadStream.id(), stream); RefPtr<ReadStream> ref = new ReadStream(inner); return ref.forget(); }
already_AddRefed<nsIInputStream> DeserializeInputStream(const OptionalInputStreamParams& aParams, const nsTArray<FileDescriptor>& aFileDescriptors) { nsCOMPtr<nsIInputStream> stream; switch (aParams.type()) { case OptionalInputStreamParams::Tvoid_t: // Leave stream null. break; case OptionalInputStreamParams::TInputStreamParams: stream = DeserializeInputStream(aParams.get_InputStreamParams(), aFileDescriptors); break; default: MOZ_ASSERT(false, "Unknown params!"); } return stream.forget(); }
already_AddRefed<nsIInputStream> DeserializeInputStream(const OptionalInputStreamParams& aParams) { MOZ_ASSERT(NS_IsMainThread()); nsCOMPtr<nsIInputStream> stream; switch (aParams.type()) { case OptionalInputStreamParams::Tvoid_t: // Leave stream null. break; case OptionalInputStreamParams::TInputStreamParams: stream = DeserializeInputStream(aParams.get_InputStreamParams()); break; default: MOZ_ASSERT(false, "Unknown params!"); } return stream.forget(); }