Initialize tunnel_enabled flag internally
Set the flag from the inner methods, to avoid bypassing the assignment by mistake (on error for example).
This commit is contained in:
parent
03de9224fc
commit
e69356c550
1 changed files with 12 additions and 7 deletions
|
@ -104,10 +104,16 @@ disable_tunnel_forward(const char *serial, uint16_t local_port) {
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
disable_tunnel(struct server *server) {
|
disable_tunnel(struct server *server) {
|
||||||
if (server->tunnel_forward) {
|
assert(server->tunnel_enabled);
|
||||||
return disable_tunnel_forward(server->serial, server->local_port);
|
|
||||||
}
|
bool ok = server->tunnel_forward
|
||||||
return disable_tunnel_reverse(server->serial);
|
? disable_tunnel_forward(server->serial, server->local_port)
|
||||||
|
: disable_tunnel_reverse(server->serial);
|
||||||
|
|
||||||
|
// Consider tunnel disabled even if the command failed
|
||||||
|
server->tunnel_enabled = false;
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sc_socket
|
static sc_socket
|
||||||
|
@ -136,6 +142,7 @@ enable_tunnel_reverse_any_port(struct server *server,
|
||||||
if (server->server_socket != SC_INVALID_SOCKET) {
|
if (server->server_socket != SC_INVALID_SOCKET) {
|
||||||
// success
|
// success
|
||||||
server->local_port = port;
|
server->local_port = port;
|
||||||
|
server->tunnel_enabled = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +178,7 @@ enable_tunnel_forward_any_port(struct server *server,
|
||||||
if (enable_tunnel_forward(server->serial, port)) {
|
if (enable_tunnel_forward(server->serial, port)) {
|
||||||
// success
|
// success
|
||||||
server->local_port = port;
|
server->local_port = port;
|
||||||
|
server->tunnel_enabled = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,8 +401,6 @@ server_start(struct server *server, const struct server_params *params) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->tunnel_enabled = true;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -463,7 +469,6 @@ server_connect_to(struct server *server, struct server_info *info) {
|
||||||
|
|
||||||
// we don't need the adb tunnel anymore
|
// we don't need the adb tunnel anymore
|
||||||
disable_tunnel(server); // ignore failure
|
disable_tunnel(server); // ignore failure
|
||||||
server->tunnel_enabled = false;
|
|
||||||
|
|
||||||
// The sockets will be closed on stop if device_read_info() fails
|
// The sockets will be closed on stop if device_read_info() fails
|
||||||
return device_read_info(server->video_socket, info);
|
return device_read_info(server->video_socket, info);
|
||||||
|
|
Loading…
Reference in a new issue