mirror of
https://github.com/debauchee/barrier.git
synced 2026-02-07 20:34:28 +08:00
more fixes to reduce latency. nagle agorithm doesn't seem to
stay off on a socket on linux because a connection clearly doesn't send data as often as possible. will have to implement a UDP socket to reduce overhead and avoid these delays. wanted to do that anyway.
This commit is contained in:
@@ -31,12 +31,8 @@ CUnixTCPSocket::CUnixTCPSocket() : m_fd(-1),
|
||||
throw XSocketCreate(::strerror(errno));
|
||||
}
|
||||
|
||||
// turn off Nagle algorithm. we send lots of really short messages.
|
||||
struct protoent* p = getprotobyname("tcp");
|
||||
if (p) {
|
||||
int on = 1;
|
||||
setsockopt(m_fd, p->p_proto, TCP_NODELAY, &on, sizeof(on));
|
||||
}
|
||||
// always send immediately
|
||||
setNoDelay();
|
||||
}
|
||||
|
||||
CUnixTCPSocket::CUnixTCPSocket(int fd) : m_fd(fd),
|
||||
@@ -44,6 +40,7 @@ CUnixTCPSocket::CUnixTCPSocket(int fd) : m_fd(fd),
|
||||
m_addedJobs(false)
|
||||
{
|
||||
assert(m_fd != -1);
|
||||
setNoDelay();
|
||||
}
|
||||
|
||||
CUnixTCPSocket::~CUnixTCPSocket()
|
||||
@@ -268,3 +265,14 @@ void CUnixTCPSocket::write(
|
||||
numBytes -= n;
|
||||
}
|
||||
}
|
||||
|
||||
void CUnixTCPSocket::setNoDelay()
|
||||
{
|
||||
// turn off Nagle algorithm. we send lots of really short messages
|
||||
// so we'll accept the (much) larger overhead to reduce latency.
|
||||
struct protoent* p = getprotobyname("tcp");
|
||||
if (p) {
|
||||
int on = 1;
|
||||
setsockopt(m_fd, p->p_proto, TCP_NODELAY, &on, sizeof(on));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user