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.
This commit is contained in:
Romain Vimont 2018-02-28 16:46:03 +01:00
parent b61310a257
commit c78ad6377c
1 changed files with 2 additions and 6 deletions

View File

@ -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");