diff options
author | 2019-05-29 13:07:28 +0300 | |
---|---|---|
committer | 2019-05-29 13:07:28 +0300 | |
commit | 96d7d31534921889c219a5c9e00a46c3e94d0124 (patch) | |
tree | 99ec8522ea1eecc8e79912b28272d3cb31d8c886 /src/daemon/proto_stdio.c | |
parent | a7c5c9ed96462d1b28139c04fba679403a412164 (diff) | |
parent | 187fe61700fc97fff565ec53aac65c664042feae (diff) | |
download | usurpation-96d7d31534921889c219a5c9e00a46c3e94d0124.tar.gz usurpation-96d7d31534921889c219a5c9e00a46c3e94d0124.tar.bz2 usurpation-96d7d31534921889c219a5c9e00a46c3e94d0124.zip |
Merge branch 'net_improvements'
NOTE: this removes the adhoc discovery implementation.
If working discovery is required either use an earlier version or
whicherver later version that hopefully implements it.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/daemon/proto_stdio.c')
-rw-r--r-- | src/daemon/proto_stdio.c | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/daemon/proto_stdio.c b/src/daemon/proto_stdio.c index f0a22a6..9aecdf0 100644 --- a/src/daemon/proto_stdio.c +++ b/src/daemon/proto_stdio.c @@ -27,32 +27,31 @@ void message_receive(char *arg) { int cancelstate; - int done = 0; - while (!done) { - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate); - pthread_mutex_lock(&state.out_m); - if (!state.writebuf) { - state.writebuf = strdup(arg); - done = 1; - } - pthread_mutex_unlock(&state.out_m); - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &cancelstate); - pthread_testcancel(); - } + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate); + pthread_mutex_lock(&state.out_m); + state.writebuf = strdup(arg); + pthread_mutex_unlock(&state.out_m); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &cancelstate); + pthread_testcancel(); + nanosleep(&respite, NULL); } char *message_send(void) { - char *ret; + char *ret = NULL; int cancelstate; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate); pthread_mutex_lock(&state.out_m); - ret = strdup(state.readbuf); - free(state.readbuf); - state.readbuf = NULL; - state.readbufsize = 0; + + if (state.readbuf) { + ret = strdup(state.readbuf); + free(state.readbuf); + state.readbuf = NULL; + state.readbufsize = 0; + } + pthread_mutex_unlock(&state.out_m); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &cancelstate); pthread_testcancel(); @@ -140,12 +139,16 @@ int proto_stdio_init(void) void proto_stdio_close(void) { - if (pthread_mutex_trylock(&state.mutex) == EBUSY) { + int status; + + status = pthread_mutex_trylock(&state.mutex); + + if (status == EBUSY) { pthread_cancel(state.stdio_in); pthread_cancel(state.stdio_out); pthread_join(state.stdio_in, NULL); pthread_join(state.stdio_out, NULL); + } else if (!status) { + pthread_mutex_unlock(&state.mutex); } - - pthread_mutex_unlock(&state.mutex); } |