From 21eb879b4182a83d685db2b2da3f252aa42d7ef6 Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Wed, 21 Feb 2024 18:19:14 +0000 Subject: [PATCH] Don't timeout select() call --- src/IpcServer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/IpcServer.cpp b/src/IpcServer.cpp index 63ce7d9..5049874 100644 --- a/src/IpcServer.cpp +++ b/src/IpcServer.cpp @@ -132,11 +132,7 @@ class ServerImpl final FD_ZERO( &fd ); FD_SET( serverSocket, &fd ); - struct timeval timeout; - timeout.tv_sec = 2; - timeout.tv_usec = 0; - - if ( select( (int)serverSocket + 1, &fd, nullptr, nullptr, &timeout ) <= 0 ) + if ( select( (int)serverSocket + 1, &fd, nullptr, nullptr, nullptr ) <= 0 ) { return Message( "select() failed (error: " + std::to_string( lastError() ) + ")", true ); } @@ -149,11 +145,16 @@ class ServerImpl final #ifdef _WIN32 int timeoutMs = 2000; + setsockopt( clientSocket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast( &timeoutMs ), sizeof( timeoutMs ) ); setsockopt( clientSocket, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast( &timeoutMs ), sizeof( timeoutMs ) ); #else + struct timeval timeout; + timeout.tv_sec = 2; + timeout.tv_usec = 0; + setsockopt( clientSocket, SOL_SOCKET, SO_SNDTIMEO, static_cast( &timeout ), sizeof( timeout ) ); setsockopt( clientSocket, SOL_SOCKET, SO_RCVTIMEO, static_cast( &timeout ), sizeof( timeout ) ); #endif