From: Mike Brady Date: Wed, 9 May 2018 08:29:47 +0000 (+0100) Subject: Make the UDP sockets blocking rather than non-blocking, but set 2 millisecond limits... X-Git-Tag: 3.2RC8~2^2~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c6e4b8ea4202fdb52c44c2ecc7026ac17b3324f;p=thirdparty%2Fshairport-sync.git Make the UDP sockets blocking rather than non-blocking, but set 2 millisecond limits on the sendto calls. --- diff --git a/rtp.c b/rtp.c index 40c8bc8b..b0f9e84b 100644 --- a/rtp.c +++ b/rtp.c @@ -469,14 +469,12 @@ void *rtp_timing_sender(void *arg) { if ((config.diagnostic_drop_packet_fraction == 0.0) || (drand48() > config.diagnostic_drop_packet_fraction)) { - if (sendto(conn->timing_socket, &req, sizeof(req), 0, (struct sockaddr *)&conn->rtp_client_timing_socket, msgsize) == -1) { char em[1024]; strerror_r(errno, em, sizeof(em)); debug(1, "Error %d using send-to to the timing socket: \"%s\".", errno, em); } - } else { debug(3, "Timing Sender Thread -- dropping outgoing packet to simulate bad network."); } @@ -808,7 +806,17 @@ static uint16_t bind_port(int ip_family, const char *self_ip_address, uint32_t s struct sockaddr_in *sa = (struct sockaddr_in *)&local; sport = ntohs(sa->sin_port); } - fcntl(local_socket, F_SETFL, O_NONBLOCK); + // fcntl(local_socket, F_SETFL, O_NONBLOCK); + + // don't wait if outputting something will take longer than this time. + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 2000; // two milliseconds + + if (setsockopt(local_socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) + debug(1, "bind_port set output timeout failed."); + // else + // debug(1,"bind_port set output timeout succeeded."); *sock = local_socket; return sport; @@ -995,6 +1003,7 @@ void rtp_request_resend(seq_t first, uint32_t count, rtsp_conn_info *conn) { } else { conn->rtp_time_of_last_resend_request_error_fp = 0; } + } else { debug(3, "Dropping resend request packet to simulate a bad network. Backing off for 0.5 " "seconds.");