Skip to content

Commit 9b1e3cc

Browse files
authored
Merge pull request #22 from fjtrujy/nodelay
Enable TCP_NODELAY
2 parents e495f41 + 3268dce commit 9b1e3cc

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/ps2link.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <pthread.h>
1111
#ifndef _WIN32
1212
#include <netinet/in.h>
13+
#include <netinet/tcp.h>
1314
#else
1415
#include <windows.h>
1516
#define sleep(x) Sleep(x * 1000)
@@ -52,6 +53,14 @@
5253
// Connect to the request port.
5354
request_socket = network_connect(hostname, 0x4711, SOCK_STREAM);
5455

56+
// Disable Nagle algorithm: without TCP_NODELAY, the two-part response
57+
// (small header then data) interacts with PS2's delayed-ACK and causes
58+
// ~200 ms stall per read() syscall, making fread() ~400x slower than read().
59+
if (request_socket > 0) {
60+
int one = 1;
61+
setsockopt(request_socket, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
62+
}
63+
5564
// Create the request thread.
5665
if (request_socket > 0) { pthread_create(&request_thread_id, NULL, ps2link_thread_request, (void *)&request_thread_id); }
5766

0 commit comments

Comments
 (0)