diff options
Diffstat (limited to 'src/tools/oping')
-rw-r--r-- | src/tools/oping/oping_client.c | 8 | ||||
-rw-r--r-- | src/tools/oping/oping_server.c | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index 7693ce41..0d4a10af 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -115,7 +115,8 @@ void * writer(void * o) { int * fdp = (int *) o; struct timespec now; - struct timespec wait = {client.interval / 1000, client.interval % 1000}; + struct timespec wait = {client.interval / 1000, + (client.interval % 1000) * MILLION}; struct oping_msg * msg; char * buf = malloc(client.size); @@ -132,12 +133,15 @@ void * writer(void * o) printf("Pinging %s with %d bytes of data:\n\n", client.s_apn, client.size); + pthread_cleanup_push((void (*) (void *)) free, buf); + while (client.sent < client.count) { nanosleep(&wait, NULL); msg->id = htonl(client.sent); if (flow_write(*fdp, buf, client.size) == -1) { printf("Failed to send SDU.\n"); flow_dealloc(*fdp); + free(buf); return (void *) -1; } @@ -148,6 +152,8 @@ void * writer(void * o) pthread_mutex_unlock(&client.lock); } + pthread_cleanup_pop(true); + return (void *) 0; } diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c index eb0b511b..a5021cba 100644 --- a/src/tools/oping/oping_server.c +++ b/src/tools/oping/oping_server.c @@ -37,9 +37,7 @@ void shutdown_server(int signo, siginfo_t * info, void * c) case SIGINT: case SIGTERM: case SIGHUP: - pthread_cancel(server.server_pt); pthread_cancel(server.accept_pt); - pthread_cancel(server.cleaner_pt); default: return; } @@ -154,8 +152,12 @@ int server_main() pthread_create(&server.accept_pt, NULL, accept_thread, NULL); pthread_create(&server.server_pt, NULL, server_thread, NULL); - pthread_join(server.server_pt, NULL); pthread_join(server.accept_pt, NULL); + + pthread_cancel(server.server_pt); + pthread_cancel(server.cleaner_pt); + + pthread_join(server.server_pt, NULL); pthread_join(server.cleaner_pt, NULL); return 0; |