This commit is contained in:
Romain Vimont 2021-05-02 18:27:13 +02:00
parent 6e8df74c41
commit c37d455fa2
2 changed files with 33 additions and 6 deletions

View File

@ -461,25 +461,41 @@ run_wait_server(void *data) {
return 0;
}
bool
server_start(struct server *server) {
static int
run_server(void *data) {
struct server *server = data;
const struct server_params *params = &server->params;
const struct server_callbacks *cbs = &server->cbs;
void *userdata = server->userdata;
if (!push_server(params->serial)) {
return false;
cbs->on_connection_failed(server);
goto end;
}
if (!enable_tunnel_any_port(server, params->port_range,
params->force_adb_forward)) {
return false;
cbs->on_connection_failed(server);
goto end;
}
// server will connect to our server socket
server->process = execute_server(server, params);
if (server->process == PROCESS_NONE) {
goto error;
cbs->on_connection_failed(server);
goto end;
}
process_wait(server->process, false); // ignore exit code
end:
return 0;
}
bool
server_start(struct server *server) {
// If the server process dies before connecting to the server socket, then
// the client will be stuck forever on accept(). To avoid the problem, we
// must be able to wake up the accept() call when the server dies. To keep

View File

@ -51,6 +51,16 @@ struct server {
// The internal allocated strings are copies owned by the server
struct server_params params;
const struct server_callbacks *cbs;
void *userdata;
};
struct server_callbacks {
void (*on_connection_failed)(struct server *server);
void (*on_connected)(struct server *server, const char *name,
struct size size, void *userdata);
void (*on_disconnected)(struct server *server, void *userdata);
};
// init server fields
@ -59,7 +69,8 @@ server_init(struct server *server, const struct server_params *params);
// push, enable tunnel et start the server
bool
server_start(struct server *server);
server_start(struct server *server, const struct server_callbacks *cbs,
void *userdata);
// block until the communication with the server is established
bool