mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-20 19:45:00 +00:00
Better forwarding.
This commit is contained in:
parent
fc2961e21e
commit
5d4016f16c
4 changed files with 32 additions and 18 deletions
|
@ -104,9 +104,8 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
|
|||
|
||||
process_t
|
||||
ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
||||
const char *const prefix_cmd[], size_t prefix_cmd_len,
|
||||
const char *const ssh_options[], size_t ssh_options_len) {
|
||||
const char *cmd[len + prefix_cmd_len + ssh_options_len + 3];
|
||||
const char *cmd[len + ssh_options_len + 3];
|
||||
unsigned i = 0;
|
||||
process_t process;
|
||||
|
||||
|
@ -114,8 +113,6 @@ ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
|||
memcpy(&cmd[i], ssh_options, ssh_options_len * sizeof(const char *));
|
||||
i += ssh_options_len;
|
||||
cmd[i++] = endpoint;
|
||||
memcpy(&cmd[i], prefix_cmd, prefix_cmd_len * sizeof(const char *));
|
||||
i += prefix_cmd_len;
|
||||
memcpy(&cmd[i], ssh_cmd, len * sizeof(const char *));
|
||||
i += len;
|
||||
cmd[i] = NULL;
|
||||
|
|
|
@ -58,8 +58,7 @@ bool
|
|||
cmd_simple_wait(process_t pid, exit_code_t *exit_code);
|
||||
|
||||
process_t
|
||||
ssh_execute(const char *serial, const char *const ssh_cmd[], size_t len,
|
||||
const char *const prefix_cmd[], size_t prefix_cmd_len,
|
||||
ssh_execute(const char *endpoint, const char *const ssh_cmd[], size_t len,
|
||||
const char *const ssh_options[], size_t ssh_options_len);
|
||||
|
||||
process_t
|
||||
|
|
|
@ -111,7 +111,7 @@ static bool prepare_ssh_socket_path(const struct server_params *params) {
|
|||
SSH_SOCKET_NAME,
|
||||
};
|
||||
process_t process = ssh_execute(params->ssh_endpoint, cmd, sizeof(cmd) / sizeof(cmd[0]),
|
||||
NULL, 0, NULL, 0);
|
||||
NULL, 0);
|
||||
return process_check_success(process, "ssh rm -f " SSH_SOCKET_NAME);
|
||||
}
|
||||
|
||||
|
@ -263,6 +263,17 @@ log_level_to_server_string(enum sc_log_level level) {
|
|||
}
|
||||
}
|
||||
|
||||
static process_t
|
||||
execute_socket_forwarding(const struct server_params *params) {
|
||||
const char *const cmd[] = {
|
||||
"/data/ssh/root/socat",
|
||||
"abstract-listen:" SOCKET_NAME ",fork,reuseaddr",
|
||||
"unix-connect:" SSH_SOCKET_NAME
|
||||
};
|
||||
return ssh_execute(params->ssh_endpoint, cmd, sizeof(cmd) / sizeof(cmd[0]),
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
static process_t
|
||||
execute_server(struct server *server, const struct server_params *params) {
|
||||
char max_size_string[6];
|
||||
|
@ -326,13 +337,6 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
"-R", tunnel_desc,
|
||||
};
|
||||
|
||||
const char *const prefix_cmd[] = {
|
||||
"/data/ssh/root/socat",
|
||||
"abstract-listen:" SOCKET_NAME ",fork",
|
||||
"unix-connect:" SSH_SOCKET_NAME,
|
||||
"&",
|
||||
};
|
||||
|
||||
for (uint16_t port = server->port_range.first;;) {
|
||||
server->server_socket = listen_on_port(port);
|
||||
if (server->server_socket == INVALID_SOCKET) {
|
||||
|
@ -355,7 +359,6 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
snprintf(tunnel_desc + strlen(tunnel_desc) - 5, 6, "%d", port);
|
||||
|
||||
return ssh_execute(params->ssh_endpoint, cmd, sizeof(cmd) / sizeof(cmd[0]),
|
||||
prefix_cmd, sizeof(prefix_cmd) / sizeof(prefix_cmd[0]),
|
||||
ssh_options, sizeof(ssh_options) / sizeof(ssh_options[0]));
|
||||
}
|
||||
}
|
||||
|
@ -445,8 +448,13 @@ server_start(struct server *server, const char *serial,
|
|||
goto error1;
|
||||
}
|
||||
|
||||
if (params->use_ssh && !prepare_ssh_socket_path(params))
|
||||
goto error1;
|
||||
if (params->use_ssh) {
|
||||
if (!prepare_ssh_socket_path(params))
|
||||
goto error1;
|
||||
server->socket_forwarder = execute_socket_forwarding(params);
|
||||
if (server->socket_forwarder == PROCESS_NONE)
|
||||
goto error1;
|
||||
}
|
||||
|
||||
if (!params->use_ssh && !enable_tunnel_any_port(server, params->port_range,
|
||||
params->force_adb_forward)) {
|
||||
|
@ -470,6 +478,10 @@ server_start(struct server *server, const char *serial,
|
|||
if (!server->wait_server_thread) {
|
||||
cmd_terminate(server->process);
|
||||
cmd_simple_wait(server->process, NULL); // ignore exit code
|
||||
if (server->use_ssh) {
|
||||
cmd_terminate(server->socket_forwarder);
|
||||
cmd_simple_wait(server->socket_forwarder, NULL); // ignore exit code
|
||||
}
|
||||
goto error2;
|
||||
}
|
||||
|
||||
|
@ -556,9 +568,13 @@ server_stop(struct server *server) {
|
|||
}
|
||||
|
||||
assert(server->process != PROCESS_NONE);
|
||||
|
||||
cmd_terminate(server->process);
|
||||
|
||||
if (server->use_ssh) {
|
||||
assert(server->socket_forwarder != PROCESS_NONE);
|
||||
cmd_terminate(server->socket_forwarder);
|
||||
}
|
||||
|
||||
if (server->tunnel_enabled && !server->use_ssh) {
|
||||
// ignore failure
|
||||
disable_tunnel(server);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
struct server {
|
||||
char *serial;
|
||||
process_t process;
|
||||
process_t socket_forwarder;
|
||||
SDL_Thread *wait_server_thread;
|
||||
atomic_flag server_socket_closed;
|
||||
socket_t server_socket; // only used if !tunnel_forward
|
||||
|
@ -31,6 +32,7 @@ struct server {
|
|||
#define SERVER_INITIALIZER { \
|
||||
.serial = NULL, \
|
||||
.process = PROCESS_NONE, \
|
||||
.socket_forwarder = PROCESS_NONE, \
|
||||
.wait_server_thread = NULL, \
|
||||
.server_socket_closed = ATOMIC_FLAG_INIT, \
|
||||
.server_socket = INVALID_SOCKET, \
|
||||
|
|
Loading…
Add table
Reference in a new issue