Skip to content

Commit

Permalink
LibWebRTCSocket does no longer need to check for buffered data size
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261021
rdar://problem/114810113

Reviewed by Jean-Yves Avenard.

We used to check for buffered size to prevent excessive memory allocation in case the main thread is blocked.
We no longer need to do this since we are doing IPC straight from the networking thread.
The backpressure mechanism (via nw callback and libwebrtc SignalSentPacket) should be sufficient.
This might reduce a case where we would loose some UDP packets if there is a burst of packet sending on libwebrtc side and a slowdown in nw or network process.

* Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.cpp:
(WebKit::LibWebRTCSocket::signalSentPacket):
(WebKit::LibWebRTCSocket::SendTo):
(WebKit::LibWebRTCSocket::willSend): Deleted.
* Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.h:

Canonical link: https://commits.webkit.org/267634@main
  • Loading branch information
youennf committed Sep 5, 2023
1 parent 753b053 commit 2f1c609
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
22 changes: 1 addition & 21 deletions Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,7 @@ void LibWebRTCSocket::signalReadPacket(const uint8_t* data, size_t size, rtc::So

void LibWebRTCSocket::signalSentPacket(int rtcPacketID, int64_t sendTimeMs)
{
if (m_beingSentPacketSizes.isEmpty())
return;

m_availableSendingBytes += m_beingSentPacketSizes.takeFirst();
SignalSentPacket(this, rtc::SentPacket(rtcPacketID, sendTimeMs));
if (m_shouldSignalReadyToSend) {
m_shouldSignalReadyToSend = false;
SignalReadyToSend(this);
}
}

void LibWebRTCSocket::signalConnect()
Expand All @@ -115,22 +107,10 @@ void LibWebRTCSocket::signalUsedInterface(String&& name)
LibWebRTCNetworkManager::signalUsedInterface(m_contextIdentifier, WTFMove(name));
}

bool LibWebRTCSocket::willSend(size_t size)
{
if (size > m_availableSendingBytes) {
m_shouldSignalReadyToSend = true;
setError(EWOULDBLOCK);
return false;
}
m_availableSendingBytes -= size;
m_beingSentPacketSizes.append(size);
return true;
}

int LibWebRTCSocket::SendTo(const void *value, size_t size, const rtc::SocketAddress& address, const rtc::PacketOptions& options)
{
auto* connection = m_factory.connection();
if (!connection || !willSend(size))
if (!connection)
return -1;

if (m_isSuspended)
Expand Down
4 changes: 0 additions & 4 deletions Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <WebCore/LibWebRTCProvider.h>
#include <WebCore/LibWebRTCSocketIdentifier.h>
#include <wtf/Deque.h>
#include <wtf/Forward.h>

ALLOW_COMMA_BEGIN
Expand Down Expand Up @@ -101,9 +100,6 @@ class LibWebRTCSocket final : public rtc::AsyncPacketSocket {
static const unsigned MAX_SOCKET_OPTION { rtc::Socket::OPT_RTP_SENDTIME_EXTN_ID + 1 };
std::optional<int> m_options[MAX_SOCKET_OPTION];

Deque<size_t> m_beingSentPacketSizes;
size_t m_availableSendingBytes { 65536 };
bool m_shouldSignalReadyToSend { false };
bool m_isSuspended { false };
WebCore::ScriptExecutionContextIdentifier m_contextIdentifier;
};
Expand Down

0 comments on commit 2f1c609

Please sign in to comment.