From c78ad6377c71c1b7dc1a008a0af2e080d0c53a1a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 28 Feb 2018 16:46:03 +0100 Subject: [PATCH] Terminate the server on stop On user request to quit, two kinds of blocking calls must be interrupted on the server: 1. the reads from and writes to the socket; 2. the call to MediaCodec.dequeueOutputBuffer(). The former case was handled by calling shutdown() on the socket from the client, but the latter was not managed. There is no easy way to wake this call properly, so just terminate the process from the client (i.e. send SIGTERM on Linux) instead. --- app/src/server.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/server.c b/app/src/server.c index aa2009de..f925895e 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -143,14 +143,10 @@ socket_t server_connect_to(struct server *server, const char *serial, Uint32 tim void server_stop(struct server *server, const char *serial) { SDL_assert(server->process != PROCESS_NONE); - if (server->device_socket != INVALID_SOCKET) { - // shutdown the socket to finish the device process gracefully - if (!net_shutdown(server->device_socket, SHUT_RDWR)) { - LOGW("Cannot shutdown socket"); - } + if (!cmd_terminate(server->process)) { + LOGW("Cannot terminate server"); } - LOGD("Waiting the server to complete execution on the device..."); cmd_simple_wait(server->process, NULL); // ignore exit code LOGD("Server terminated");