Added a notification mechanism for sending messages from
another thread to the mainthread in a safe manner. This is used for the DNS lookup code, and can also be used by the signal handler to safely report actions back to the application mainloop without using global variables.
This commit is contained in:
@@ -159,8 +159,7 @@ 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;
|
||||
static struct uhub_notify_handle* notify_handle;
|
||||
|
||||
void adm_handle_signal(int sig)
|
||||
{
|
||||
@@ -198,10 +197,6 @@ static int signals[] =
|
||||
0
|
||||
};
|
||||
|
||||
void adm_callback(struct net_connection* con, int event, void* ptr)
|
||||
{
|
||||
}
|
||||
|
||||
void adm_setup_signal_handlers()
|
||||
{
|
||||
sigset_t sig_set;
|
||||
@@ -224,22 +219,13 @@ 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);
|
||||
notify_handle = net_notify_create(NULL, NULL);
|
||||
}
|
||||
|
||||
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;
|
||||
net_notify_destroy(notify_handle);
|
||||
notify_handle = NULL;
|
||||
}
|
||||
|
||||
void adm_shutdown_signal_handlers()
|
||||
|
||||
Reference in New Issue
Block a user