Skip to content

Commit

Permalink
Don't timeout select() call
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson committed Feb 21, 2024
1 parent f9bd1be commit 21eb879
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/IpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -149,11 +145,16 @@ class ServerImpl final

#ifdef _WIN32
int timeoutMs = 2000;

setsockopt( clientSocket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<const char*>( &timeoutMs ),
sizeof( timeoutMs ) );
setsockopt( clientSocket, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<const char*>( &timeoutMs ),
sizeof( timeoutMs ) );
#else
struct timeval timeout;
timeout.tv_sec = 2;
timeout.tv_usec = 0;

setsockopt( clientSocket, SOL_SOCKET, SO_SNDTIMEO, static_cast<const void*>( &timeout ), sizeof( timeout ) );
setsockopt( clientSocket, SOL_SOCKET, SO_RCVTIMEO, static_cast<const void*>( &timeout ), sizeof( timeout ) );
#endif
Expand Down

0 comments on commit 21eb879

Please sign in to comment.