From 9b327d615c5424855b4e5dbc0769bdf5694ffc90 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Oct 07 2021 17:09:20 +0000 Subject: tcp nodelay --- diff --git a/tcp.cpp b/tcp.cpp index 711b78c..40a703d 100644 --- a/tcp.cpp +++ b/tcp.cpp @@ -10,7 +10,8 @@ #include #include #include - +#include + #include "tcp.h" @@ -59,7 +60,10 @@ bool Connection::open(const Address &remoteAddr) { if (0 != connect(sockId, (sockaddr*)&addr, sizeof(addr))) { close(ERR_TCP_CONNECTION_FAILED); return false; } + int tcp_nodelay = 1; fcntl(sockId, F_SETFL, fcntl(sockId, F_GETFL, 0) | O_NONBLOCK); + setsockopt(sockId, IPPROTO_TCP, TCP_NODELAY, &tcp_nodelay, sizeof(int)); + return true; } @@ -220,7 +224,10 @@ bool Server::start(const Address &localAddr, Handler *handler) { return false; } + int tcp_nodelay = 1; fcntl(sockId, F_SETFL, fcntl(sockId, F_GETFL, 0) | O_NONBLOCK); + setsockopt(sockId, IPPROTO_TCP, TCP_NODELAY, &tcp_nodelay, sizeof(int)); + thread = new std::thread(&Server::listen, this); return true; }