Extract adding timeout to socket

This commit is contained in:
Tyler Wilding
2020-09-08 14:17:15 -04:00
parent 871f1b43b0
commit 4b6223a6d0
4 changed files with 14 additions and 29 deletions
+1 -15
View File
@@ -74,24 +74,10 @@ bool Deci2Server::init() {
return false;
}
// TODO - put in library
#ifdef __linux
timeval timeout = {};
timeout.tv_sec = 0;
timeout.tv_usec = 100000;
if (set_socket_option(server_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) <
0) {
if (set_socket_timeout(server_socket, 100000) < 0) {
close_server_socket();
return false;
}
#elif _WIN32
unsigned long timeout = 100; // ms
if (set_socket_option(server_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) <
0) {
close_server_socket();
return false;
}
#endif
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;