From 83913509782fd0c076f040468e8b0dac91fc2784 Mon Sep 17 00:00:00 2001 From: Bogdan Tara Date: Tue, 6 Oct 2020 13:46:20 +0300 Subject: [PATCH] Backed out changeset eff866cb4c66 (bug 1668851) for browser_net-ws-filter-freetext.js failures CLOSED TREE --- .../websocket/PWebSocketConnection.ipdl | 1 - .../protocol/websocket/WebSocketChannel.cpp | 27 ++++++++------- .../websocket/WebSocketConnectionChild.cpp | 8 ++--- .../websocket/WebSocketConnectionParent.cpp | 16 --------- .../websocket/WebSocketConnectionParent.h | 1 - .../websocket/nsIWebSocketConnection.idl | 5 ++- .../websocket/nsWebSocketConnection.cpp | 33 +++++++++++-------- .../websocket/nsWebSocketConnection.h | 1 + 8 files changed, 39 insertions(+), 53 deletions(-) diff --git a/netwerk/protocol/websocket/PWebSocketConnection.ipdl b/netwerk/protocol/websocket/PWebSocketConnection.ipdl index 3bf681fd7f7d..adb253c87643 100644 --- a/netwerk/protocol/websocket/PWebSocketConnection.ipdl +++ b/netwerk/protocol/websocket/PWebSocketConnection.ipdl @@ -19,7 +19,6 @@ parent: async OnTCPClosed(); async OnDataReceived(uint8_t[] aData); async OnUpgradeFailed(nsresult aReason); - async OnDataSent(); child: async EnqueueOutgoingData(uint8_t[] aData); diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index 873b4a480bcc..ddbd919539dd 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -3852,7 +3852,7 @@ void WebSocketChannel::DoEnqueueOutgoingMessage() { if (!mCurrentOut) PrimeNewOutgoingMessage(); - if (mCurrentOut && mConnection) { + while (mCurrentOut && mConnection) { LOG( ("WebSocketChannel::DoEnqueueOutgoingMessage: " "Try to send %u of hdr/copybreak and %u of data\n", @@ -3862,6 +3862,10 @@ void WebSocketChannel::DoEnqueueOutgoingMessage() { mHdrOut, mHdrOutSize, (uint8_t*)mCurrentOut->BeginReading(), mCurrentOut->Length()); + if (rv == NS_BASE_STREAM_WOULD_BLOCK) { + return; + } + LOG(("WebSocketChannel::DoEnqueueOutgoingMessage: rv %" PRIx32 "\n", static_cast(rv))); @@ -3869,6 +3873,14 @@ void WebSocketChannel::DoEnqueueOutgoingMessage() { AbortSession(rv); return; } + + if (!mStopped) { + mTargetThread->Dispatch( + new CallAcknowledge(this, mCurrentOut->OrigLength()), + NS_DISPATCH_NORMAL); + } + DeleteCurrentOutGoingMessage(); + PrimeNewOutgoingMessage(); } if (mReleaseOnTransmit) ReleaseSession(); @@ -3917,17 +3929,8 @@ WebSocketChannel::OnDataReceived(uint8_t* aData, uint32_t aCount) { } NS_IMETHODIMP -WebSocketChannel::OnDataSent() { - MOZ_ASSERT(OnSocketThread(), "not on socket thread"); - - if (!mStopped) { - mTargetThread->Dispatch( - new CallAcknowledge(this, mCurrentOut->OrigLength()), - NS_DISPATCH_NORMAL); - } - DeleteCurrentOutGoingMessage(); - PrimeNewOutgoingMessage(); - +WebSocketChannel::OnReadyToSendData() { + DoEnqueueOutgoingMessage(); return NS_OK; } diff --git a/netwerk/protocol/websocket/WebSocketConnectionChild.cpp b/netwerk/protocol/websocket/WebSocketConnectionChild.cpp index 09d573a40b1a..37e0da65ae70 100644 --- a/netwerk/protocol/websocket/WebSocketConnectionChild.cpp +++ b/netwerk/protocol/websocket/WebSocketConnectionChild.cpp @@ -175,12 +175,8 @@ WebSocketConnectionChild::OnDataReceived(uint8_t* aData, uint32_t aCount) { } NS_IMETHODIMP -WebSocketConnectionChild::OnDataSent() { - LOG(("WebSocketConnectionChild::OnDataSent %p\n", this)); - - if (CanSend()) { - Unused << SendOnDataSent(); - } +WebSocketConnectionChild::OnReadyToSendData() { + // TODO: implement flow control between parent and socket process. return NS_OK; } diff --git a/netwerk/protocol/websocket/WebSocketConnectionParent.cpp b/netwerk/protocol/websocket/WebSocketConnectionParent.cpp index 5e9e9c3e402c..62952c9bd30c 100644 --- a/netwerk/protocol/websocket/WebSocketConnectionParent.cpp +++ b/netwerk/protocol/websocket/WebSocketConnectionParent.cpp @@ -130,22 +130,6 @@ mozilla::ipc::IPCResult WebSocketConnectionParent::RecvOnDataReceived( return IPC_OK(); } -mozilla::ipc::IPCResult WebSocketConnectionParent::RecvOnDataSent() { - LOG(("WebSocketConnectionParent::RecvOnDataSent %p\n", this)); - MOZ_ASSERT(mEventTarget); - - RefPtr self = this; - auto task = [self{std::move(self)}]() { - if (self->mListener) { - Unused << self->mListener->OnDataSent(); - } - }; - - DispatchHelper(mEventTarget, "WebSocketConnectionParent::RecvOnDataSent", - std::move(task)); - return IPC_OK(); -} - void WebSocketConnectionParent::ActorDestroy(ActorDestroyReason aWhy) { LOG(("WebSocketConnectionParent::ActorDestroy %p aWhy=%d\n", this, aWhy)); if (!mClosed) { diff --git a/netwerk/protocol/websocket/WebSocketConnectionParent.h b/netwerk/protocol/websocket/WebSocketConnectionParent.h index 3f7601261d5b..8257cb758cad 100644 --- a/netwerk/protocol/websocket/WebSocketConnectionParent.h +++ b/netwerk/protocol/websocket/WebSocketConnectionParent.h @@ -45,7 +45,6 @@ class WebSocketConnectionParent final : public PWebSocketConnectionParent, mozilla::ipc::IPCResult RecvOnTCPClosed(); mozilla::ipc::IPCResult RecvOnDataReceived(nsTArray&& aData); mozilla::ipc::IPCResult RecvOnUpgradeFailed(const nsresult& aReason); - mozilla::ipc::IPCResult RecvOnDataSent(); void ActorDestroy(ActorDestroyReason aWhy) override; diff --git a/netwerk/protocol/websocket/nsIWebSocketConnection.idl b/netwerk/protocol/websocket/nsIWebSocketConnection.idl index 0fcd8b57b847..9c8fdd22c228 100644 --- a/netwerk/protocol/websocket/nsIWebSocketConnection.idl +++ b/netwerk/protocol/websocket/nsIWebSocketConnection.idl @@ -73,8 +73,7 @@ interface nsIWebSocketConnectionListener : nsISupports in unsigned long dataLength); /** - * Called to inform the listener that the outgoing data is written - * to socket. + * Called to inform the listener that the outgoing data is ready to write. */ - void onDataSent(); + void onReadyToSendData(); }; diff --git a/netwerk/protocol/websocket/nsWebSocketConnection.cpp b/netwerk/protocol/websocket/nsWebSocketConnection.cpp index da03c74d9c89..8934e4677438 100644 --- a/netwerk/protocol/websocket/nsWebSocketConnection.cpp +++ b/netwerk/protocol/websocket/nsWebSocketConnection.cpp @@ -20,7 +20,8 @@ nsWebSocketConnection::nsWebSocketConnection( mSocketIn(aInputStream), mSocketOut(aOutputStream), mWriteOffset(0), - mStartReadingCalled(false) { + mStartReadingCalled(false), + mOutputStreamBlocked(false) { LOG(("nsWebSocketConnection ctor %p\n", this)); } @@ -79,12 +80,12 @@ nsWebSocketConnection::Close() { nsresult nsWebSocketConnection::EnqueueOutputData(nsTArray&& aData) { MOZ_ASSERT(mEventTarget->IsOnCurrentThread()); - if (!mSocketOut) { - return NS_ERROR_NOT_AVAILABLE; + mOutputQueue.emplace_back(std::move(aData)); + + if (mSocketOut) { + mSocketOut->AsyncWait(this, 0, 0, mEventTarget); } - mOutputQueue.emplace_back(std::move(aData)); - OnOutputStreamReady(mSocketOut); return NS_OK; } @@ -96,16 +97,19 @@ nsWebSocketConnection::EnqueueOutputData(const uint8_t* aHdrBuf, LOG(("nsWebSocketConnection::EnqueueOutputData %p\n", this)); MOZ_ASSERT(mEventTarget->IsOnCurrentThread()); - if (!mSocketOut) { - return NS_ERROR_NOT_AVAILABLE; - } - nsTArray data; data.AppendElements(aHdrBuf, aHdrBufLength); data.AppendElements(aPayloadBuf, aPayloadBufLength); mOutputQueue.emplace_back(std::move(data)); - OnOutputStreamReady(mSocketOut); + if (mSocketOut) { + mSocketOut->AsyncWait(this, 0, 0, mEventTarget); + } + + if (mOutputStreamBlocked) { + return NS_BASE_STREAM_WOULD_BLOCK; + } + return NS_OK; } @@ -216,6 +220,8 @@ nsWebSocketConnection::OnOutputStreamReady(nsIAsyncOutputStream* aStream) { return NS_OK; } + mOutputStreamBlocked = false; + while (!mOutputQueue.empty()) { const OutputData& data = mOutputQueue.front(); @@ -231,6 +237,7 @@ nsWebSocketConnection::OnOutputStreamReady(nsIAsyncOutputStream* aStream) { if (rv == NS_BASE_STREAM_WOULD_BLOCK) { mSocketOut->AsyncWait(this, 0, 0, mEventTarget); + mOutputStreamBlocked = true; return NS_OK; } @@ -246,12 +253,10 @@ nsWebSocketConnection::OnOutputStreamReady(nsIAsyncOutputStream* aStream) { if (toWrite == wrote) { mWriteOffset = 0; mOutputQueue.pop_front(); - Unused << mListener->OnDataSent(); - } else { - mSocketOut->AsyncWait(this, 0, 0, mEventTarget); - return NS_OK; } } + Unused << mListener->OnReadyToSendData(); + return NS_OK; } diff --git a/netwerk/protocol/websocket/nsWebSocketConnection.h b/netwerk/protocol/websocket/nsWebSocketConnection.h index 4cde06e86274..5adea98a5650 100644 --- a/netwerk/protocol/websocket/nsWebSocketConnection.h +++ b/netwerk/protocol/websocket/nsWebSocketConnection.h @@ -60,6 +60,7 @@ class nsWebSocketConnection : public nsIWebSocketConnection, size_t mWriteOffset; std::list mOutputQueue; bool mStartReadingCalled; + bool mOutputStreamBlocked; }; } // namespace net