Skip to content

Commit 3407aa7

Browse files
Set TCP_QUICKACK on Linux to improve responsiveness when using client/service configuration
1 parent 2a1b7a9 commit 3407aa7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

NetworkClient.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
#ifdef __linux__
2626
#include <unistd.h>
2727
#include <sys/select.h>
28+
#include <netinet/tcp.h>
2829
#endif
2930

31+
const int yes = 1;
32+
3033
using namespace std::chrono_literals;
3134

3235
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
@@ -438,6 +441,13 @@ int NetworkClient::recv_select(SOCKET s, char *buf, int len, int flags)
438441
}
439442
else
440443
{
444+
/*-------------------------------------------------*\
445+
| Set QUICKACK socket option on Linux to improve |
446+
| performance |
447+
\*-------------------------------------------------*/
448+
#ifdef __linux__
449+
setsockopt(s, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes));
450+
#endif
441451
return(recv(s, buf, len, flags));
442452
}
443453

NetworkServer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <stdlib.h>
2727
#include <iostream>
2828

29-
const char yes = 1;
29+
const int yes = 1;
3030

3131
#ifdef WIN32
3232
#include <Windows.h>
@@ -548,6 +548,13 @@ int NetworkServer::recv_select(SOCKET s, char *buf, int len, int flags)
548548
}
549549
else
550550
{
551+
/*-------------------------------------------------*\
552+
| Set QUICKACK socket option on Linux to improve |
553+
| performance |
554+
\*-------------------------------------------------*/
555+
#ifdef __linux__
556+
setsockopt(s, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes));
557+
#endif
551558
return(recv(s, buf, len, flags));
552559
}
553560
}

net_port/net_port.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define connect_socklen_t socklen_t
3030
#endif
3131

32-
const char yes = 1;
32+
const int yes = 1;
3333

3434
net_port::net_port()
3535
{
@@ -328,6 +328,14 @@ void net_port::tcp_close()
328328

329329
int net_port::tcp_listen(char * recv_data, int length)
330330
{
331+
/*-------------------------------------------------*\
332+
| Set QUICKACK socket option on Linux to improve |
333+
| performance |
334+
\*-------------------------------------------------*/
335+
#ifdef __linux__
336+
setsockopt(sock, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes));
337+
#endif
338+
331339
return(recv(sock, recv_data, length, 0));
332340
}
333341

0 commit comments

Comments
 (0)