[UDP-HTTP] Cancel the TCP thread

Cancel the TCP thread before to join it, because of the blocking recv()
call.
This commit is contained in:
Matteo Cypriani 2011-08-22 17:07:02 +02:00
parent adc05b98c0
commit 632858155a
1 changed files with 6 additions and 1 deletions

View File

@ -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) ;