Skip to content

Commit da74af2

Browse files
authored
Enable TCP_NODELAY by default (#36)
There are a lot of discussions about TCP_NODELAY on the Internet. I think that enabling TCP_NODELAY can reduce latency and increase throughput in most scenarios.
1 parent 256d081 commit da74af2

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

trantor/net/inner/Acceptor.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ Acceptor::Acceptor(EventLoop *loop,
2727
{
2828
_sock.setReuseAddr(reUseAddr);
2929
_sock.setReusePort(reUsePort);
30-
3130
_sock.bindAddress(_addr);
32-
31+
_sock.setTcpNoDelay(true);
3332
_acceptChannel.setReadCallback(std::bind(&Acceptor::readCallback, this));
3433
}
3534
Acceptor::~Acceptor()

trantor/net/inner/TcpConnectionImpl.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ TcpConnectionImpl::TcpConnectionImpl(EventLoop *loop,
4747
_ioChannelPtr->setErrorCallback(
4848
std::bind(&TcpConnectionImpl::handleError, this));
4949
_socketPtr->setKeepAlive(true);
50+
_socketPtr->setTcpNoDelay(true);
5051
_name = localAddr.toIpPort() + "--" + peerAddr.toIpPort();
5152
}
5253
TcpConnectionImpl::~TcpConnectionImpl()

0 commit comments

Comments
 (0)