diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/libwebrtc/rtc_base/async_tcp_socket.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/rtc_base/async_tcp_socket.cc')
-rw-r--r-- | third_party/libwebrtc/rtc_base/async_tcp_socket.cc | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/third_party/libwebrtc/rtc_base/async_tcp_socket.cc b/third_party/libwebrtc/rtc_base/async_tcp_socket.cc index 367c5b04e7..2924340c16 100644 --- a/third_party/libwebrtc/rtc_base/async_tcp_socket.cc +++ b/third_party/libwebrtc/rtc_base/async_tcp_socket.cc @@ -14,6 +14,8 @@ #include <string.h> #include <algorithm> +#include <cstddef> +#include <cstdint> #include <memory> #include "api/array_view.h" @@ -209,15 +211,17 @@ void AsyncTCPSocketBase::OnReadEvent(Socket* socket) { return; } - size_t size = inbuf_.size(); - ProcessInput(inbuf_.data<char>(), &size); - - if (size > inbuf_.size()) { + size_t processed = ProcessInput(inbuf_); + size_t bytes_remaining = inbuf_.size() - processed; + if (processed > inbuf_.size()) { RTC_LOG(LS_ERROR) << "input buffer overflow"; RTC_DCHECK_NOTREACHED(); inbuf_.Clear(); } else { - inbuf_.SetSize(size); + if (bytes_remaining > 0) { + memmove(inbuf_.data(), inbuf_.data() + processed, bytes_remaining); + } + inbuf_.SetSize(bytes_remaining); } } @@ -283,24 +287,24 @@ int AsyncTCPSocket::Send(const void* pv, return static_cast<int>(cb); } -void AsyncTCPSocket::ProcessInput(char* data, size_t* len) { +size_t AsyncTCPSocket::ProcessInput(rtc::ArrayView<const uint8_t> data) { SocketAddress remote_addr(GetRemoteAddress()); + size_t processed_bytes = 0; while (true) { - if (*len < kPacketLenSize) - return; - - PacketLength pkt_len = rtc::GetBE16(data); - if (*len < kPacketLenSize + pkt_len) - return; - - SignalReadPacket(this, data + kPacketLenSize, pkt_len, remote_addr, - TimeMicros()); - - *len -= kPacketLenSize + pkt_len; - if (*len > 0) { - memmove(data, data + kPacketLenSize + pkt_len, *len); - } + size_t bytes_left = data.size() - processed_bytes; + if (bytes_left < kPacketLenSize) + return processed_bytes; + + PacketLength pkt_len = rtc::GetBE16(data.data() + processed_bytes); + if (bytes_left < kPacketLenSize + pkt_len) + return processed_bytes; + + rtc::ReceivedPacket received_packet( + data.subview(processed_bytes + kPacketLenSize, pkt_len), remote_addr, + webrtc::Timestamp::Micros(rtc::TimeMicros())); + NotifyPacketReceived(received_packet); + processed_bytes += kPacketLenSize + pkt_len; } } |