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:
parent
d0594ea9f3
commit
fe79ac593c
|
@ -31,12 +31,8 @@ CUnixTCPSocket::CUnixTCPSocket() : m_fd(-1),
|
||||||
throw XSocketCreate(::strerror(errno));
|
throw XSocketCreate(::strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn off Nagle algorithm. we send lots of really short messages.
|
// always send immediately
|
||||||
struct protoent* p = getprotobyname("tcp");
|
setNoDelay();
|
||||||
if (p) {
|
|
||||||
int on = 1;
|
|
||||||
setsockopt(m_fd, p->p_proto, TCP_NODELAY, &on, sizeof(on));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUnixTCPSocket::CUnixTCPSocket(int fd) : m_fd(fd),
|
CUnixTCPSocket::CUnixTCPSocket(int fd) : m_fd(fd),
|
||||||
|
@ -44,6 +40,7 @@ CUnixTCPSocket::CUnixTCPSocket(int fd) : m_fd(fd),
|
||||||
m_addedJobs(false)
|
m_addedJobs(false)
|
||||||
{
|
{
|
||||||
assert(m_fd != -1);
|
assert(m_fd != -1);
|
||||||
|
setNoDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
CUnixTCPSocket::~CUnixTCPSocket()
|
CUnixTCPSocket::~CUnixTCPSocket()
|
||||||
|
@ -268,3 +265,14 @@ void CUnixTCPSocket::write(
|
||||||
numBytes -= n;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ class CUnixTCPSocket : public CSocket {
|
||||||
private:
|
private:
|
||||||
CUnixTCPSocket(int);
|
CUnixTCPSocket(int);
|
||||||
|
|
||||||
|
// disable Nagle algorithm
|
||||||
|
void setNoDelay();
|
||||||
|
|
||||||
// callbacks for read/write events
|
// callbacks for read/write events
|
||||||
void readCB();
|
void readCB();
|
||||||
void writeCB();
|
void writeCB();
|
||||||
|
|
Loading…
Reference in New Issue