Implement TCP_NODELAY, thanks #209

This commit is contained in:
Mr_Goldberg 2022-09-03 04:20:03 -04:00
parent b1986dfe38
commit 05e2c3bef0
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
2 changed files with 8 additions and 0 deletions

View File

@ -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>

View File

@ -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)
{
@ -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();
@ -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();