Skip to content

Commit d09c669

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

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

NetworkClient.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
#ifdef __linux__
2626
#include <unistd.h>
2727
#include <sys/select.h>
28+
#include <netinet/tcp.h>
29+
#endif
30+
31+
#ifdef __linux__
32+
const int yes = 1;
33+
#else
34+
const char yes = 1;
2835
#endif
2936

3037
using namespace std::chrono_literals;
@@ -438,6 +445,13 @@ int NetworkClient::recv_select(SOCKET s, char *buf, int len, int flags)
438445
}
439446
else
440447
{
448+
/*-------------------------------------------------*\
449+
| Set QUICKACK socket option on Linux to improve |
450+
| performance |
451+
\*-------------------------------------------------*/
452+
#ifdef __linux__
453+
setsockopt(s, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes));
454+
#endif
441455
return(recv(s, buf, len, flags));
442456
}
443457

NetworkServer.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
#include <stdlib.h>
2727
#include <iostream>
2828

29-
const char yes = 1;
30-
3129
#ifdef WIN32
3230
#include <Windows.h>
3331
#else
3432
#include <unistd.h>
3533
#endif
3634

35+
#ifdef __linux__
36+
const int yes = 1;
37+
#else
38+
const char yes = 1;
39+
#endif
40+
3741
using namespace std::chrono_literals;
3842

3943
NetworkClientInfo::NetworkClientInfo()
@@ -548,6 +552,13 @@ int NetworkServer::recv_select(SOCKET s, char *buf, int len, int flags)
548552
}
549553
else
550554
{
555+
/*-------------------------------------------------*\
556+
| Set QUICKACK socket option on Linux to improve |
557+
| performance |
558+
\*-------------------------------------------------*/
559+
#ifdef __linux__
560+
setsockopt(s, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes));
561+
#endif
551562
return(recv(s, buf, len, flags));
552563
}
553564
}

net_port/net_port.cpp

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

32+
#ifdef __linux__
33+
const int yes = 1;
34+
#else
3235
const char yes = 1;
36+
#endif
3337

3438
net_port::net_port()
3539
{
@@ -328,6 +332,13 @@ void net_port::tcp_close()
328332

329333
int net_port::tcp_listen(char * recv_data, int length)
330334
{
335+
/*-------------------------------------------------*\
336+
| Set QUICKACK socket option on Linux to improve |
337+
| performance |
338+
\*-------------------------------------------------*/
339+
#ifdef __linux__
340+
setsockopt(sock, IPPROTO_TCP, TCP_QUICKACK, &yes, sizeof(yes));
341+
#endif
331342
return(recv(sock, recv_data, length, 0));
332343
}
333344

0 commit comments

Comments
 (0)