Skip to content

Commit

Permalink
Implement TCP_NODELAY, thanks #209
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr_Goldberg committed Sep 3, 2022
1 parent b1986df commit 05e2c3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions dll/common_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ inline void reset_LastError()
#include <sys/time.h>

#include <netinet/in.h>
#include <netinet/tcp.h>
#include <linux/netdevice.h>

#include <fcntl.h>
Expand Down
7 changes: 7 additions & 0 deletions dll/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ static int set_socket_nonblocking(sock_t sock)
#endif
}

static bool disable_nagle(sock_t sock)
{
int set = 1;
return (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&set, sizeof(set)) == 0);
}

static void kill_socket(sock_t sock)
{
Expand Down Expand Up @@ -978,6 +983,7 @@ void Networking::Run()
struct TCP_Socket socket;
if (set_socket_nonblocking(sock)) {
PRINT_DEBUG("SET NONBLOCK\n");
disable_nagle(sock);
socket.sock = sock;
socket.received_data = true;
socket.last_heartbeat_received = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -1031,6 +1037,7 @@ void Networking::Run()
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (is_socket_valid(sock) && set_socket_nonblocking(sock)) {
PRINT_DEBUG("NEW SOCKET %u %u\n", sock, conn.tcp_socket_outgoing.sock);
disable_nagle(sock);
connect_socket(sock, conn.tcp_ip_port);
conn.tcp_socket_outgoing.sock = sock;
conn.tcp_socket_outgoing.last_heartbeat_received = std::chrono::high_resolution_clock::now();
Expand Down

0 comments on commit 05e2c3b

Please sign in to comment.