wip
This commit is contained in:
@ -461,25 +461,41 @@ run_wait_server(void *data) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static int
|
||||||
server_start(struct server *server) {
|
run_server(void *data) {
|
||||||
|
struct server *server = data;
|
||||||
|
|
||||||
const struct server_params *params = &server->params;
|
const struct server_params *params = &server->params;
|
||||||
|
const struct server_callbacks *cbs = &server->cbs;
|
||||||
|
void *userdata = server->userdata;
|
||||||
|
|
||||||
if (!push_server(params->serial)) {
|
if (!push_server(params->serial)) {
|
||||||
return false;
|
cbs->on_connection_failed(server);
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enable_tunnel_any_port(server, params->port_range,
|
if (!enable_tunnel_any_port(server, params->port_range,
|
||||||
params->force_adb_forward)) {
|
params->force_adb_forward)) {
|
||||||
return false;
|
cbs->on_connection_failed(server);
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// server will connect to our server socket
|
// server will connect to our server socket
|
||||||
server->process = execute_server(server, params);
|
server->process = execute_server(server, params);
|
||||||
if (server->process == PROCESS_NONE) {
|
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
|
// 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
|
// 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
|
// must be able to wake up the accept() call when the server dies. To keep
|
||||||
|
@ -51,6 +51,16 @@ struct server {
|
|||||||
|
|
||||||
// The internal allocated strings are copies owned by the server
|
// The internal allocated strings are copies owned by the server
|
||||||
struct server_params params;
|
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
|
// init server fields
|
||||||
@ -59,7 +69,8 @@ server_init(struct server *server, const struct server_params *params);
|
|||||||
|
|
||||||
// push, enable tunnel et start the server
|
// push, enable tunnel et start the server
|
||||||
bool
|
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
|
// block until the communication with the server is established
|
||||||
bool
|
bool
|
||||||
|
Reference in New Issue
Block a user