diff --git a/src/tools/adcclient.c b/src/tools/adcclient.c index 1eae4fe..a445c1d 100644 --- a/src/tools/adcclient.c +++ b/src/tools/adcclient.c @@ -600,6 +600,17 @@ int ADC_client_connect(struct ADC_client* client, const char* address) return 1; } +static void ADC_client_send_handshake(struct ADC_client* client) +{ + ADC_TRACE; + struct adc_message* handshake = adc_msg_create(ADC_HANDSHAKE); + + client->callback(client, ADC_CLIENT_CONNECTED, 0); + net_con_update(client->con, NET_EVENT_READ); + ADC_client_send(client, handshake); + ADC_client_set_state(client, ps_protocol); + adc_msg_free(handshake); +} static void ADC_client_on_connected(struct ADC_client* client) { @@ -610,32 +621,20 @@ static void ADC_client_on_connected(struct ADC_client* client) net_con_update(client->con, NET_EVENT_READ | NET_EVENT_WRITE); client->callback(client, ADC_CLIENT_SSL_HANDSHAKE, 0); ADC_client_set_state(client, ps_conn_ssl); - net_con_ssl_handshake(client->con, net_con_ssl_mode_client, NULL); } else #endif - { - struct adc_message* handshake = adc_msg_create(ADC_HANDSHAKE); - net_con_update(client->con, NET_EVENT_READ); - client->callback(client, ADC_CLIENT_CONNECTED, 0); - ADC_client_send(client, handshake); - ADC_client_set_state(client, ps_protocol); - adc_msg_free(handshake); - } + ADC_client_send_handshake(client); + } #ifdef SSL_SUPPORT static void ADC_client_on_connected_ssl(struct ADC_client* client) { ADC_TRACE; - struct adc_message* handshake = adc_msg_create(ADC_HANDSHAKE); client->callback(client, ADC_CLIENT_SSL_OK, 0); - client->callback(client, ADC_CLIENT_CONNECTED, 0); - net_con_update(client->con, NET_EVENT_READ); - ADC_client_send(client, handshake); - ADC_client_set_state(client, ps_protocol); - adc_msg_free(handshake); + ADC_client_send_handshake(client); } #endif diff --git a/src/tools/admin.c b/src/tools/admin.c index f230576..bf114cd 100644 --- a/src/tools/admin.c +++ b/src/tools/admin.c @@ -159,6 +159,9 @@ static int handle(struct ADC_client* client, enum ADC_client_callback_type type, static int running = 1; #if !defined(WIN32) +static int adm_pipes[2] = { -1, -1 }; +static struct net_connection* adm_con = 0; + void adm_handle_signal(int sig) { switch (sig) @@ -195,6 +198,10 @@ static int signals[] = 0 }; +void adm_callback(struct net_connection* con, int event, void* ptr) +{ +} + void adm_setup_signal_handlers() { sigset_t sig_set; @@ -215,6 +222,26 @@ void adm_setup_signal_handlers() } } +void adm_setup_control_pipe() +{ + int ret = pipe(adm_pipes); + if (ret == -1) + { + LOG_ERROR("Unable to setup control pipes."); + } + adm_con = net_con_create(); + net_con_initialize(adm_con, adm_pipes[0], adm_callback, 0, NET_EVENT_READ); +} + +void adm_shutdown_control_pipe() +{ + net_con_destroy(adm_con); + close(adm_pipes[0]); + close(adm_pipes[1]); + adm_pipes[0] = -1; + adm_pipes[0] = -1; +} + void adm_shutdown_signal_handlers() { } @@ -233,6 +260,7 @@ int main(int argc, char** argv) struct ADC_client* client; net_initialize(); + adm_setup_control_pipe(); memset(g_usermap, 0, sizeof(g_usermap)); @@ -242,6 +270,8 @@ int main(int argc, char** argv) while (running && net_backend_process()) { } + adm_shutdown_control_pipe(); + ADC_client_destroy(client); net_destroy(); adm_shutdown_signal_handlers();