From eae28d3a4510c5ccf08c0d69488934f694538875 Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Wed, 11 Dec 2024 13:42:14 -0800 Subject: [PATCH] Increase socket send buffer size. PiperOrigin-RevId: 705225169 --- .../windows/wifi_hotspot_socket.cc | 17 +++++++++++++++++ .../implementation/windows/wifi_lan_socket.cc | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/internal/platform/implementation/windows/wifi_hotspot_socket.cc b/internal/platform/implementation/windows/wifi_hotspot_socket.cc index d2cd2d75..65793e20 100644 --- a/internal/platform/implementation/windows/wifi_hotspot_socket.cc +++ b/internal/platform/implementation/windows/wifi_hotspot_socket.cc @@ -29,6 +29,8 @@ namespace { // Recorded the maximum bytes received in one read is 65586 in the test, but add // a little more for const kMaxByteRecieved for safty reason. constexpr int kMaxByteRecieved = 66000; +// SO_SNDBUF is set to 4MB. +constexpr int kSendBufSize = 4 * 1024 * 1024; } // namespace WifiHotspotSocket::WifiHotspotSocket(StreamSocket socket) { @@ -39,6 +41,21 @@ WifiHotspotSocket::WifiHotspotSocket(StreamSocket socket) { WifiHotspotSocket::WifiHotspotSocket(SOCKET socket) { stream_soket_winsock_ = socket; + int buffer_size = kSendBufSize; + int opt_len = sizeof(buffer_size); + if (getsockopt(socket, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast(&buffer_size), &opt_len) == 0) { + LOG(INFO) << "Socket send buffer size: " << buffer_size; + } + if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast(&buffer_size), + sizeof(buffer_size)) != 0) { + LOG(WARNING) << "Failed to set SO_SNDBUF: " << WSAGetLastError(); + } + if (getsockopt(socket, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast(&buffer_size), &opt_len) == 0) { + LOG(INFO) << "Updated send buffer size to: " << buffer_size; + } input_stream_ = SocketInputStream(socket); output_stream_ = SocketOutputStream(socket); } diff --git a/internal/platform/implementation/windows/wifi_lan_socket.cc b/internal/platform/implementation/windows/wifi_lan_socket.cc index c2a91975..56cb42c5 100644 --- a/internal/platform/implementation/windows/wifi_lan_socket.cc +++ b/internal/platform/implementation/windows/wifi_lan_socket.cc @@ -28,6 +28,11 @@ namespace windows { WifiLanSocket::WifiLanSocket(StreamSocket socket) { stream_soket_ = socket; + LOG(INFO) << "Socket send buffer size: " + << socket.Control().OutboundBufferSizeInBytes(); + socket.Control().OutboundBufferSizeInBytes(4 * 1024 * 1024); + LOG(INFO) << "Updated send buffer size to: " + << socket.Control().OutboundBufferSizeInBytes(); input_stream_ = SocketInputStream(socket.InputStream()); output_stream_ = SocketOutputStream(socket.OutputStream()); }