commit f3904f706bc928c63a9ab3e7b185e749ed40d6d9
parent a0e2e0d839b1ce76addb7d8705d03e54f0bdbd03
Author: Byron Campen <docfaraday@gmail.com>
Date: Fri, 21 Nov 2025 19:10:41 +0000
Bug 1999384: Re-run OnInputStreamReady when there are more bytes to read. r=mjf
Differential Revision: https://phabricator.services.mozilla.com/D272902
Diffstat:
1 file changed, 36 insertions(+), 28 deletions(-)
diff --git a/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp
@@ -684,44 +684,52 @@ WebrtcTCPSocket::OnInputStreamReady(nsIAsyncInputStream* in) {
MOZ_ASSERT(mTransport, "webrtc TCP socket not connected");
MOZ_ASSERT(mSocketIn == in, "wrong input stream");
- char buffer[9216];
- uint32_t remainingCapacity = sizeof(buffer);
- uint32_t read = 0;
+ while (true) {
+ char buffer[9216];
+ uint32_t remainingCapacity = sizeof(buffer);
+ uint32_t read = 0;
+
+ while (remainingCapacity > 0) {
+ uint32_t count = 0;
+ nsresult rv = mSocketIn->Read(buffer + read, remainingCapacity, &count);
+ if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ break;
+ }
- while (remainingCapacity > 0) {
- uint32_t count = 0;
- nsresult rv = mSocketIn->Read(buffer + read, remainingCapacity, &count);
- if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
- break;
- }
+ if (NS_FAILED(rv)) {
+ LOG(("WebrtcTCPSocket::OnInputStreamReady %p failed %u\n", this,
+ static_cast<uint32_t>(rv)));
+ CloseWithReason(rv);
+ return rv;
+ }
- if (NS_FAILED(rv)) {
- LOG(("WebrtcTCPSocket::OnInputStreamReady %p failed %u\n", this,
- static_cast<uint32_t>(rv)));
- CloseWithReason(rv);
- return rv;
- }
+ // base stream closed
+ if (count == 0) {
+ LOG(("WebrtcTCPSocket::OnInputStreamReady %p connection closed\n",
+ this));
+ CloseWithReason(NS_ERROR_FAILURE);
+ return NS_OK;
+ }
- // base stream closed
- if (count == 0) {
- LOG(("WebrtcTCPSocket::OnInputStreamReady %p connection closed\n", this));
- CloseWithReason(NS_ERROR_FAILURE);
- return NS_OK;
+ remainingCapacity -= count;
+ read += count;
}
- remainingCapacity -= count;
- read += count;
- }
+ if (read > 0) {
+ nsTArray<uint8_t> array(read);
+ array.AppendElements(buffer, read);
- if (read > 0) {
- nsTArray<uint8_t> array(read);
- array.AppendElements(buffer, read);
+ InvokeOnRead(std::move(array));
+ }
- InvokeOnRead(std::move(array));
+ if (remainingCapacity != 0) {
+ // Loop exited above, but not because we ran out of space. We're actually
+ // done, break out of the while(true) loop.
+ break;
+ }
}
mSocketIn->AsyncWait(this, 0, 0, nullptr);
-
return NS_OK;
}