From 98a24f41aa8fff7d2ec899d0211e1c561072db00 Mon Sep 17 00:00:00 2001 From: iliavy Date: Fri, 5 Apr 2024 23:32:40 +0300 Subject: [PATCH] Add proxy methods to maximize socket buffers --- tdutils/td/utils/port/ServerSocketFd.cpp | 8 ++++++++ tdutils/td/utils/port/ServerSocketFd.h | 3 +++ tdutils/td/utils/port/SocketFd.cpp | 8 ++++++++ tdutils/td/utils/port/SocketFd.h | 3 +++ tdutils/td/utils/port/UdpSocketFd.cpp | 8 ++++++++ tdutils/td/utils/port/UdpSocketFd.h | 3 +++ 6 files changed, 33 insertions(+) diff --git a/tdutils/td/utils/port/ServerSocketFd.cpp b/tdutils/td/utils/port/ServerSocketFd.cpp index d3c5195ca..72578a9be 100644 --- a/tdutils/td/utils/port/ServerSocketFd.cpp +++ b/tdutils/td/utils/port/ServerSocketFd.cpp @@ -369,4 +369,12 @@ Result ServerSocketFd::open(int32 port, CSlice addr) { return ServerSocketFd(std::move(impl)); } +Result ServerSocketFd::maximize_snd_buffer(uint32 max_size) { + return get_native_fd().maximize_snd_buffer(max_size); +} + +Result ServerSocketFd::maximize_rcv_buffer(uint32 max_size) { + return get_native_fd().maximize_rcv_buffer(max_size); +} + } // namespace td diff --git a/tdutils/td/utils/port/ServerSocketFd.h b/tdutils/td/utils/port/ServerSocketFd.h index 52557cda2..dcee89917 100644 --- a/tdutils/td/utils/port/ServerSocketFd.h +++ b/tdutils/td/utils/port/ServerSocketFd.h @@ -33,6 +33,9 @@ class ServerSocketFd { ServerSocketFd &operator=(ServerSocketFd &&) noexcept; ~ServerSocketFd(); + Result maximize_snd_buffer(uint32 max_size = 0); + Result maximize_rcv_buffer(uint32 max_size = 0); + static Result open(int32 port, CSlice addr = CSlice("0.0.0.0")) TD_WARN_UNUSED_RESULT; PollableFdInfo &get_poll_info(); diff --git a/tdutils/td/utils/port/SocketFd.cpp b/tdutils/td/utils/port/SocketFd.cpp index e52535055..ac4038c3f 100644 --- a/tdutils/td/utils/port/SocketFd.cpp +++ b/tdutils/td/utils/port/SocketFd.cpp @@ -717,4 +717,12 @@ Result SocketFd::read(MutableSlice slice) { return impl_->read(slice); } +Result SocketFd::maximize_snd_buffer(uint32 max_size) { + return get_native_fd().maximize_snd_buffer(max_size); +} + +Result SocketFd::maximize_rcv_buffer(uint32 max_size) { + return get_native_fd().maximize_rcv_buffer(max_size); +} + } // namespace td diff --git a/tdutils/td/utils/port/SocketFd.h b/tdutils/td/utils/port/SocketFd.h index 5427cc99b..40f3a9321 100644 --- a/tdutils/td/utils/port/SocketFd.h +++ b/tdutils/td/utils/port/SocketFd.h @@ -37,6 +37,9 @@ class SocketFd { SocketFd &operator=(SocketFd &&) noexcept; ~SocketFd(); + Result maximize_snd_buffer(uint32 max_size = 0); + Result maximize_rcv_buffer(uint32 max_size = 0); + static Result open(const IPAddress &address) TD_WARN_UNUSED_RESULT; PollableFdInfo &get_poll_info(); diff --git a/tdutils/td/utils/port/UdpSocketFd.cpp b/tdutils/td/utils/port/UdpSocketFd.cpp index ab7a38873..cd4641b18 100644 --- a/tdutils/td/utils/port/UdpSocketFd.cpp +++ b/tdutils/td/utils/port/UdpSocketFd.cpp @@ -822,4 +822,12 @@ bool UdpSocketFd::is_critical_read_error(const Status &status) { return status.code() == ENOMEM || status.code() == ENOBUFS; } +Result UdpSocketFd::maximize_snd_buffer(uint32 max_size) { + return get_native_fd().maximize_snd_buffer(max_size); +} + +Result UdpSocketFd::maximize_rcv_buffer(uint32 max_size) { + return get_native_fd().maximize_rcv_buffer(max_size); +} + } // namespace td diff --git a/tdutils/td/utils/port/UdpSocketFd.h b/tdutils/td/utils/port/UdpSocketFd.h index 1dfbc4b62..53d7755b6 100644 --- a/tdutils/td/utils/port/UdpSocketFd.h +++ b/tdutils/td/utils/port/UdpSocketFd.h @@ -44,6 +44,9 @@ class UdpSocketFd { UdpSocketFd(const UdpSocketFd &) = delete; UdpSocketFd &operator=(const UdpSocketFd &) = delete; + Result maximize_snd_buffer(uint32 max_size = 0); + Result maximize_rcv_buffer(uint32 max_size = 0); + static Result open(const IPAddress &address) TD_WARN_UNUSED_RESULT; PollableFdInfo &get_poll_info();