make Nagle's algorithm configurable

This commit is contained in:
Xertis
2025-09-30 23:45:00 +03:00
parent e3da256c5d
commit b6ca7cf918
5 changed files with 50 additions and 0 deletions
+16
View File
@@ -329,6 +329,22 @@ public:
}
}
void setNoDelay(bool noDelay) override {
int opt = noDelay ? 1 : 0;
if (setsockopt(descriptor, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(opt)) < 0) {
throw handle_socket_error("setsockopt(TCP_NODELAY) failed");
}
}
bool getNoDelay() const override {
int opt = 0;
socklen_t len = sizeof(opt);
if (getsockopt(descriptor, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, &len) < 0) {
throw handle_socket_error("getsockopt(TCP_NODELAY) failed");
}
return opt != 0;
}
void startListen() {
while (state == ConnectionState::CONNECTED) {
int size = recvsocket(descriptor, buffer.data(), buffer.size());
+2
View File
@@ -76,6 +76,8 @@ namespace network {
virtual void connect(runnable callback) = 0;
virtual int recv(char* buffer, size_t length) = 0;
virtual int available() = 0;
virtual void setNoDelay(bool noDelay) = 0;
[[nodiscard]] virtual bool getNoDelay() const = 0;
[[nodiscard]] TransportType getTransportType() const noexcept override {
return TransportType::TCP;