Disable custom SDL signal handlers
Request SDL not to replace the SIGINT and SIGTERM handlers, so that the
process is immediately terminated on Ctrl+C.
This avoids process hanging on Ctrl+C during network calls on
initialization.
Some of them accepted a timeout, but it was not used since
commit 9b056f5091
anymore.
This commit is contained in:
parent
3b3803da0d
commit
f00c6c5b13
3 changed files with 7 additions and 7 deletions
|
@ -113,16 +113,16 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
|
||||||
|
|
||||||
SDL_bool ret = SDL_TRUE;
|
SDL_bool ret = SDL_TRUE;
|
||||||
|
|
||||||
|
if (!SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1")) {
|
||||||
|
LOGW("Cannot request to keep default signal handlers");
|
||||||
|
}
|
||||||
|
|
||||||
if (!sdl_init_and_configure()) {
|
if (!sdl_init_and_configure()) {
|
||||||
ret = SDL_FALSE;
|
ret = SDL_FALSE;
|
||||||
goto finally_destroy_server;
|
goto finally_destroy_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SDL initialization replace the signal handler for SIGTERM, so Ctrl+C is
|
socket_t device_socket = server_connect_to(&server);
|
||||||
// managed by the event loop. This blocking call blocks the event loop, so
|
|
||||||
// timeout the connection not to block indefinitely in case of SIGTERM.
|
|
||||||
#define SERVER_CONNECT_TIMEOUT_MS 2000
|
|
||||||
socket_t device_socket = server_connect_to(&server, SERVER_CONNECT_TIMEOUT_MS);
|
|
||||||
if (device_socket == INVALID_SOCKET) {
|
if (device_socket == INVALID_SOCKET) {
|
||||||
server_stop(&server);
|
server_stop(&server);
|
||||||
ret = SDL_FALSE;
|
ret = SDL_FALSE;
|
||||||
|
|
|
@ -195,7 +195,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_t server_connect_to(struct server *server, Uint32 timeout_ms) {
|
socket_t server_connect_to(struct server *server) {
|
||||||
if (!server->tunnel_forward) {
|
if (!server->tunnel_forward) {
|
||||||
server->device_socket = net_accept(server->server_socket);
|
server->device_socket = net_accept(server->server_socket);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -34,7 +34,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
|
||||||
Uint16 max_size, Uint32 bit_rate);
|
Uint16 max_size, Uint32 bit_rate);
|
||||||
|
|
||||||
// block until the communication with the server is established
|
// block until the communication with the server is established
|
||||||
socket_t server_connect_to(struct server *server, Uint32 timeout_ms);
|
socket_t server_connect_to(struct server *server);
|
||||||
|
|
||||||
// disconnect and kill the server process
|
// disconnect and kill the server process
|
||||||
void server_stop(struct server *server);
|
void server_stop(struct server *server);
|
||||||
|
|
Loading…
Reference in a new issue