From: <sri...@us...> - 2009-05-28 11:01:27
|
Revision: 584 http://sipp.svn.sourceforge.net/sipp/?rev=584&view=rev Author: srivanuj Date: 2009-05-28 11:01:17 +0000 (Thu, 28 May 2009) Log Message: ----------- Fix: Media thread was left running after call ends.- Provided by Nic Bellamy. Modified Paths: -------------- sipp/trunk/call.cpp sipp/trunk/send_packets.c Modified: sipp/trunk/call.cpp =================================================================== --- sipp/trunk/call.cpp 2009-04-30 07:44:03 UTC (rev 583) +++ sipp/trunk/call.cpp 2009-05-28 11:01:17 UTC (rev 584) @@ -624,6 +624,14 @@ tdm_map[tdm_map_number] = false; } +# ifdef PCAPPLAY + if (media_thread != 0) { + pthread_cancel(media_thread); + pthread_join(media_thread, NULL); + } +#endif + + free(start_time_rtd); free(rtd_done); free(debugBuffer); @@ -3803,8 +3811,12 @@ #define PTHREAD_STACK_MIN 16384 #endif //pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); - pthread_attr_setdetachstate(&attr, - PTHREAD_CREATE_DETACHED); + if (media_thread != 0) { + // If a media_thread is already active, kill it before starting a new one + pthread_cancel(media_thread); + pthread_join(media_thread, NULL); + media_thread = 0; + } int ret = pthread_create(&media_thread, &attr, send_wrapper, (void *) play_args); if(ret) Modified: sipp/trunk/send_packets.c =================================================================== --- sipp/trunk/send_packets.c 2009-04-30 07:44:03 UTC (rev 583) +++ sipp/trunk/send_packets.c 2009-05-28 11:01:17 UTC (rev 584) @@ -54,6 +54,7 @@ #include <errno.h> #include <string.h> #include <fcntl.h> +#include <pthread.h> #include "send_packets.h" #include "prepare_pcap.h" @@ -112,7 +113,15 @@ /*Safe threaded version*/ void do_sleep (struct timeval *, struct timeval *, struct timeval *, struct timeval *); +void send_packets_cleanup(void *arg) +{ + int sock = (int) arg; + // Close send socket + close(sock); +} + + int send_packets (play_args_t * play_args) { @@ -171,6 +180,13 @@ memcpy(&(from6.sin6_addr.s6_addr), &(((struct sockaddr_in6 *)(void *) from)->sin6_addr.s6_addr), sizeof(from6.sin6_addr.s6_addr)); } + + /* Ensure the sender socket is closed when the thread exits - this + * allows the thread to be cancelled cleanly. + */ + pthread_cleanup_push(send_packets_cleanup, ((void *) sock)); + + while (pkt_index < pkt_max) { memcpy(udp, pkt_index->data, pkt_index->pktlen); port_diff = ntohs (udp->uh_dport) - pkts->base; @@ -228,7 +244,8 @@ pkt_index++; } - close(sock); + /* Closing the socket is handled by pthread_cleanup_push()/pthread_cleanup_pop() */ + pthread_cleanup_pop(1); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |