diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-08-13 18:00:43 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-08-13 18:00:43 +0200 |
commit | f5054cc7ee058cff2226994036949e77725ae454 (patch) | |
tree | d19299f5b04559f7fb195862d978d8f0f1bde984 | |
parent | 4450f06082ea6e337762f9acdfefd012f815411a (diff) |
icmpd cleanup
-rw-r--r-- | icmpd.c | 13 | ||||
-rw-r--r-- | icmpd.h | 10 |
2 files changed, 16 insertions, 7 deletions
@@ -43,11 +43,10 @@ struct icmpd { }; // Global state -bool thread_running = false; -struct mt_mutex thread_mutex; // protecting these global values -struct mt_thread thread; -int thread_in, thread_out; -int host_in, host_out; +static bool thread_running = false; +static struct mt_thread thread; +static int thread_in, thread_out; +static int host_in, host_out; // Arguments to messages are listed in comments. @@ -240,6 +239,8 @@ static void* thread_entry(void *arg) { assert(found); mt_mutex_destroy(&d->mut); + close(d->signal_out); + close(d->signal_in); free(d); break; } @@ -477,8 +478,6 @@ static void spawn_icmpd_thread(void) { host_out = pp[1]; thread_in = pp[0]; - mt_mutex_init(&thread_mutex); - mt_thread_create(&thread, thread_entry, NULL); struct msg_in msg = recv_message(host_in); @@ -13,6 +13,16 @@ struct icmpd_received { }; +// The interface exposed here is NOT thread-safe. Having multiple threads in +// in the same process working with icmpd is unsafe, since internal communication +// assumes one calling thread. + + +// This functions as a "connection" with another party. A server should create +// a new connection for each client it communicates with (in addition to a +// single possible client_addr=0 connection for receiving connection requests), +// and likewise a client should create a new connection for each server it +// communicates with. struct icmpd; // Pass 0 as client_addr to listen for messages from any IP (this channel |