Skip to content

Commit f00c6c5

Browse files
committed
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 9b056f5 anymore.
1 parent 3b3803d commit f00c6c5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

app/src/scrcpy.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
113113

114114
SDL_bool ret = SDL_TRUE;
115115

116+
if (!SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1")) {
117+
LOGW("Cannot request to keep default signal handlers");
118+
}
119+
116120
if (!sdl_init_and_configure()) {
117121
ret = SDL_FALSE;
118122
goto finally_destroy_server;
119123
}
120124

121-
// SDL initialization replace the signal handler for SIGTERM, so Ctrl+C is
122-
// managed by the event loop. This blocking call blocks the event loop, so
123-
// timeout the connection not to block indefinitely in case of SIGTERM.
124-
#define SERVER_CONNECT_TIMEOUT_MS 2000
125-
socket_t device_socket = server_connect_to(&server, SERVER_CONNECT_TIMEOUT_MS);
125+
socket_t device_socket = server_connect_to(&server);
126126
if (device_socket == INVALID_SOCKET) {
127127
server_stop(&server);
128128
ret = SDL_FALSE;

app/src/server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
195195
return SDL_TRUE;
196196
}
197197

198-
socket_t server_connect_to(struct server *server, Uint32 timeout_ms) {
198+
socket_t server_connect_to(struct server *server) {
199199
if (!server->tunnel_forward) {
200200
server->device_socket = net_accept(server->server_socket);
201201
} else {

app/src/server.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po
3434
Uint16 max_size, Uint32 bit_rate);
3535

3636
// block until the communication with the server is established
37-
socket_t server_connect_to(struct server *server, Uint32 timeout_ms);
37+
socket_t server_connect_to(struct server *server);
3838

3939
// disconnect and kill the server process
4040
void server_stop(struct server *server);

0 commit comments

Comments
 (0)