diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index afd04d6d..e96fa187 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -698,6 +698,10 @@ end: sc_file_pusher_destroy(&s->file_pusher); } + if (server_started) { + sc_server_join(&s->server); + } + sc_server_destroy(&s->server); return ret; diff --git a/app/src/server.c b/app/src/server.c index c9164972..413f02ee 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -909,7 +909,10 @@ sc_server_stop(struct sc_server *server) { sc_cond_signal(&server->cond_stopped); sc_intr_interrupt(&server->intr); sc_mutex_unlock(&server->mutex); +} +void +sc_server_join(struct sc_server *server) { sc_thread_join(&server->thread, NULL); } diff --git a/app/src/server.h b/app/src/server.h index d6b1401e..c05b1e5b 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -108,6 +108,10 @@ sc_server_start(struct sc_server *server); void sc_server_stop(struct sc_server *server); +// join the server thread +void +sc_server_join(struct sc_server *server); + // close and release sockets void sc_server_destroy(struct sc_server *server);