--- rtp.c 2003-12-09 12:13:15.000000000 -0700 +++ rtp.c-good 2003-12-09 12:13:06.000000000 -0700 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -358,25 +359,39 @@ int payloadtype; int hdrlen = 12; int mark; + int retries = 0; unsigned int timestamp; unsigned int *rtpheader; static struct ast_frame *f, null_frame = { AST_FRAME_NULL, }; struct rtpPayloadType rtpPT; len = sizeof(sin); - - /* Cache where the header will go */ - res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, - 0, (struct sockaddr *)&sin, &len); + while(1){ + + // Cache where the header will go + res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, + 0, (struct sockaddr *)&sin, &len); - rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); - if (res < 0) { - ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno)); - if (errno == EBADF) - CRASH; - return &null_frame; + //ok we successfully returned from recvfrom so lets hop out + if(res >= 0) + break; + + //attempt to retry X times before bailing + if (retries > 3 ) { + ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno)); + if (errno == EBADF) + CRASH; + return &null_frame; + } + + //sleep for a 10th of a second (roughly) + usleep(100000); + retries++; } + + rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); + if (res < hdrlen) { ast_log(LOG_WARNING, "RTP Read too short\n"); return &null_frame;