From e1749a0c09b586794b131fcc7040c79433a486d9 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 8 Feb 2018 17:38:38 +0100 Subject: [PATCH] Remove the "adb reverse" tunnel immediately As soon as we accepted a connection, we can remove the "adb reverse" tunnel. --- app/src/scrcpy.c | 2 +- app/src/server.c | 8 +++++++- app/src/server.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index cda3bc2a..5a735127 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -311,7 +311,7 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b // to reduce startup time, we could be tempted to init other stuff before blocking here // but we should not block after SDL_Init since it handles the signals (Ctrl+C) in its // event loop: blocking could lead to deadlock - TCPsocket device_socket = server_connect_to(&server); + TCPsocket device_socket = server_connect_to(&server, serial); if (!device_socket) { server_stop(&server, serial); return SDL_FALSE; diff --git a/app/src/server.c b/app/src/server.c index ff0e4663..bc5e4f9e 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -99,12 +99,18 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po return SDL_TRUE; } -TCPsocket server_connect_to(struct server *server) { +TCPsocket server_connect_to(struct server *server, const char *serial) { SDL_assert(server->server_socket); server->device_socket = server_socket_accept(server->server_socket); + // we don't need the server socket anymore SDLNet_TCP_Close(server->server_socket); server->server_socket = NULL; + + // we don't need the adb tunnel anymore + disable_tunnel(serial); // ignore failure + server->adb_reverse_enabled = SDL_FALSE; + return server->device_socket; } diff --git a/app/src/server.h b/app/src/server.h index bec0c14d..082ac14a 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -26,7 +26,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_po Uint16 max_size, Uint32 bit_rate); // block until the communication with the server is established -TCPsocket server_connect_to(struct server *server); +TCPsocket server_connect_to(struct server *server, const char *serial); // disconnect and kill the server process void server_stop(struct server *server, const char *serial);