From 3268dcec2b7dbd0529e39b2964977039d5dcdbdb Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sat, 28 Feb 2026 19:45:40 +0100 Subject: [PATCH] Enable TCP_NODELAY --- src/ps2link.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ps2link.c b/src/ps2link.c index 563aa67..4199ad6 100644 --- a/src/ps2link.c +++ b/src/ps2link.c @@ -10,6 +10,7 @@ #include #ifndef _WIN32 #include + #include #else #include #define sleep(x) Sleep(x * 1000) @@ -52,6 +53,14 @@ // Connect to the request port. request_socket = network_connect(hostname, 0x4711, SOCK_STREAM); + // Disable Nagle algorithm: without TCP_NODELAY, the two-part response + // (small header then data) interacts with PS2's delayed-ACK and causes + // ~200 ms stall per read() syscall, making fread() ~400x slower than read(). + if (request_socket > 0) { + int one = 1; + setsockopt(request_socket, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); + } + // Create the request thread. if (request_socket > 0) { pthread_create(&request_thread_id, NULL, ps2link_thread_request, (void *)&request_thread_id); }