Skip to content

Commit

Permalink
Turn off Nagle
Browse files Browse the repository at this point in the history
  • Loading branch information
atarassov-ttd committed Oct 29, 2024
1 parent d1c7073 commit d69cefc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion vsock-bridge/include/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <errno.h>
#include <linux/vm_sockets.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
Expand Down Expand Up @@ -51,6 +52,17 @@ namespace vsockio
}
return true;
}

static bool setTcpNoDelay(int fd) {
int enable = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable)) < 0)
{
const int err = errno;
Logger::instance->Log(Logger::ERROR, "setsockopt error: ", strerror(err));
return false;
}
return true;
}
};

struct Listener
Expand Down Expand Up @@ -156,7 +168,13 @@ namespace vsockio
return;
}

auto outPeer = connectToPeer();
if (_listenEp->getAddress().first->sa_family == AF_INET && !IOControl::setTcpNoDelay(clientFd))
{
Logger::instance->Log(Logger::ERROR, "failed to turn off Nagle algorithm (fd=", clientFd, ")");
return;
}

auto outPeer = connectToPeer();
if (!outPeer)
{
return;
Expand All @@ -183,6 +201,12 @@ namespace vsockio
return nullptr;
}

if (_connectEp->getAddress().first->sa_family == AF_INET && !IOControl::setTcpNoDelay(fd))
{
Logger::instance->Log(Logger::ERROR, "failed to turn off Nagle algorithm (fd=", fd, ")");
return nullptr;
}

auto addrAndLen = _connectEp->getAddress();
int status = connect(fd, addrAndLen.first, addrAndLen.second);
if (status == 0 || (status = errno) == EINPROGRESS)
Expand Down

0 comments on commit d69cefc

Please sign in to comment.