Timeout the server socket connection

Wait no more than 2 seconds for accepting the connection from the
device, since it blocks the event loop, preventing to react to SIGTERM
(Ctrl+C).
This commit is contained in:
Romain Vimont
2018-02-09 15:18:09 +01:00
parent 90a46b4c45
commit eb09fefd43
5 changed files with 12 additions and 12 deletions

View File

@@ -98,9 +98,9 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
return SDL_TRUE;
}
TCPsocket server_connect_to(struct server *server, const char *serial) {
TCPsocket server_connect_to(struct server *server, const char *serial, Uint32 timeout_ms) {
SDL_assert(server->server_socket);
server->device_socket = server_socket_accept(server->server_socket);
server->device_socket = server_socket_accept(server->server_socket, timeout_ms);
// we don't need the server socket anymore
SDLNet_TCP_Close(server->server_socket);