Simplify adb_tunnel
With the new adb functions, the static adb_tunnel functions become unnecessary.
This commit is contained in:
parent
3fdbd994e0
commit
2fc80eae2d
1 changed files with 5 additions and 28 deletions
|
@ -9,29 +9,6 @@
|
||||||
|
|
||||||
#define SC_SOCKET_NAME "scrcpy"
|
#define SC_SOCKET_NAME "scrcpy"
|
||||||
|
|
||||||
static bool
|
|
||||||
enable_tunnel_reverse(struct sc_intr *intr, const char *serial,
|
|
||||||
uint16_t local_port) {
|
|
||||||
return adb_reverse(intr, serial, SC_SOCKET_NAME, local_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
disable_tunnel_reverse(struct sc_intr *intr, const char *serial) {
|
|
||||||
return adb_reverse_remove(intr, serial, SC_SOCKET_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
enable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
|
||||||
uint16_t local_port) {
|
|
||||||
return adb_forward(intr, serial, local_port, SC_SOCKET_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
disable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
|
||||||
uint16_t local_port) {
|
|
||||||
return adb_forward_remove(intr, serial, local_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
listen_on_port(struct sc_intr *intr, sc_socket socket, uint16_t port) {
|
listen_on_port(struct sc_intr *intr, sc_socket socket, uint16_t port) {
|
||||||
return net_listen_intr(intr, socket, IPV4_LOCALHOST, port, 1);
|
return net_listen_intr(intr, socket, IPV4_LOCALHOST, port, 1);
|
||||||
|
@ -43,7 +20,7 @@ enable_tunnel_reverse_any_port(struct sc_adb_tunnel *tunnel,
|
||||||
struct sc_port_range port_range) {
|
struct sc_port_range port_range) {
|
||||||
uint16_t port = port_range.first;
|
uint16_t port = port_range.first;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!enable_tunnel_reverse(intr, serial, port)) {
|
if (!adb_reverse(intr, serial, SC_SOCKET_NAME, port)) {
|
||||||
// the command itself failed, it will fail on any port
|
// the command itself failed, it will fail on any port
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +51,7 @@ enable_tunnel_reverse_any_port(struct sc_adb_tunnel *tunnel,
|
||||||
}
|
}
|
||||||
|
|
||||||
// failure, disable tunnel and try another port
|
// failure, disable tunnel and try another port
|
||||||
if (!disable_tunnel_reverse(intr, serial)) {
|
if (!adb_reverse_remove(intr, serial, SC_SOCKET_NAME)) {
|
||||||
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
LOGW("Could not remove reverse tunnel on port %" PRIu16, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +81,7 @@ enable_tunnel_forward_any_port(struct sc_adb_tunnel *tunnel,
|
||||||
|
|
||||||
uint16_t port = port_range.first;
|
uint16_t port = port_range.first;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (enable_tunnel_forward(intr, serial, port)) {
|
if (adb_forward(intr, serial, port, SC_SOCKET_NAME)) {
|
||||||
// success
|
// success
|
||||||
tunnel->local_port = port;
|
tunnel->local_port = port;
|
||||||
tunnel->enabled = true;
|
tunnel->enabled = true;
|
||||||
|
@ -169,9 +146,9 @@ sc_adb_tunnel_close(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
||||||
|
|
||||||
bool ret;
|
bool ret;
|
||||||
if (tunnel->forward) {
|
if (tunnel->forward) {
|
||||||
ret = disable_tunnel_forward(intr, serial, tunnel->local_port);
|
ret = adb_forward_remove(intr, serial, tunnel->local_port);
|
||||||
} else {
|
} else {
|
||||||
ret = disable_tunnel_reverse(intr, serial);
|
ret = adb_reverse_remove(intr, serial, SC_SOCKET_NAME);
|
||||||
|
|
||||||
assert(tunnel->server_socket != SC_SOCKET_NONE);
|
assert(tunnel->server_socket != SC_SOCKET_NONE);
|
||||||
if (!net_close(tunnel->server_socket)) {
|
if (!net_close(tunnel->server_socket)) {
|
||||||
|
|
Loading…
Reference in a new issue