Skip to content

Commit

Permalink
Interrupt and close sockets on server stop
Browse files Browse the repository at this point in the history
The sockets were never interrupted or closed by the client since recent
changes to run the server from a dedicated thread (see commit
0426708).

As a side effect, the server could never terminate properly (it was
waiting on socket blocking calls), so it was always killed by the client
after the WATCHDOG_DELAY.

Interrupt the sockets on stop to give the servera chance to terminate
property, then close them.
  • Loading branch information
rom1v committed Dec 8, 2021
1 parent cabcbc2 commit ddb9396
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,17 @@ run_server(void *data) {
}
sc_mutex_unlock(&server->mutex);

// Interrupt sockets to wake up socket blocking calls on the server
assert(server->video_socket != SC_SOCKET_NONE);
net_interrupt(server->video_socket);
net_close(server->video_socket);

if (server->control_socket != SC_SOCKET_NONE) {
// There is no control_socket if --no-control is set
net_interrupt(server->control_socket);
net_close(server->control_socket);
}

// Give some delay for the server to terminate properly
#define WATCHDOG_DELAY SC_TICK_FROM_SEC(1)
sc_tick deadline = sc_tick_now() + WATCHDOG_DELAY;
Expand Down

0 comments on commit ddb9396

Please sign in to comment.