From 632858155a2e392889475386c60a2d136e63f9b6 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 22 Aug 2011 17:07:02 +0200 Subject: [PATCH] [UDP-HTTP] Cancel the TCP thread Cancel the TCP thread before to join it, because of the blocking recv() call. --- owlps-udp-to-http/owlps-udp-to-http.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/owlps-udp-to-http/owlps-udp-to-http.c b/owlps-udp-to-http/owlps-udp-to-http.c index f0aec91..3879726 100644 --- a/owlps-udp-to-http/owlps-udp-to-http.c +++ b/owlps-udp-to-http/owlps-udp-to-http.c @@ -109,11 +109,15 @@ int main(int argc, char *argv[]) ret = receive_udp() ; /* Stop the TCP thread */ + // We must cancel the thread because it can be blocked on the + // recv() call: + if (pthread_cancel(tcp_server_thread)) + perror("Cannot cancel the TCP server thread") ; if (pthread_join(tcp_server_thread, NULL)) perror("Cannot join the TCP server thread") ; - /* Cleaning */ exit: + /* Close sockets */ if (tcp_sockfd >= 0) if (close(tcp_sockfd)) perror("Error closing the TCP socket") ; @@ -121,6 +125,7 @@ int main(int argc, char *argv[]) if (close(udp_sockfd)) perror("Error closing the UDP socket") ; + /* Last cleaning */ free(answer) ; free_results_list() ; sem_destroy(&lock_results) ;