chiark / gitweb /
lib/uaudio-rtp.c: Factor out setting the send-buffer size on a socket.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 4 May 2020 18:24:21 +0000 (19:24 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 5 May 2020 22:18:28 +0000 (23:18 +0100)
This is a preliminary step.  We'll want the same logic for other sockets
soon.

lib/uaudio-rtp.c

index 8313054fbc3e43101e9afc858b28a0239fb3d907..745113604ffe41a5e61945b24120ed21591b2946 100644 (file)
@@ -242,11 +242,29 @@ static size_t rtp_play(void *buffer, size_t nsamples, unsigned flags) {
   return nsamples;
 }
 
+static void hack_send_buffer_size(int fd, const char *what) {
+  int sndbuf, target_sndbuf = 131072;
+  socklen_t len = sizeof sndbuf;
+
+  if(getsockopt(fd, SOL_SOCKET, SO_SNDBUF,
+                &sndbuf, &len) < 0)
+    disorder_fatal(errno, "error getting SO_SNDBUF on %s socket", what);
+  if(target_sndbuf > sndbuf) {
+    if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
+                  &target_sndbuf, sizeof target_sndbuf) < 0)
+      disorder_error(errno, "error setting SO_SNDBUF on %s socket to %d",
+                     what, target_sndbuf);
+    else
+      disorder_info("changed socket send buffer size on %socket from %d to %d",
+                    what, sndbuf, target_sndbuf);
+  } else
+    disorder_info("default socket send buffer on %s socket is %d",
+                  what, sndbuf);
+}
+
 static void rtp_open(void) {
   struct addrinfo *dres, *sres;
   static const int one = 1;
-  int sndbuf, target_sndbuf = 131072;
-  socklen_t len;
   struct netaddress dst[1], src[1];
   const char *mode;
   
@@ -369,20 +387,8 @@ static void rtp_open(void) {
     break;
   }
   }
-  /* Enlarge the socket buffer */
-  len = sizeof sndbuf;
-  if(getsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF,
-                &sndbuf, &len) < 0)
-    disorder_fatal(errno, "error getting SO_SNDBUF");
-  if(target_sndbuf > sndbuf) {
-    if(setsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF,
-                  &target_sndbuf, sizeof target_sndbuf) < 0)
-      disorder_error(errno, "error setting SO_SNDBUF to %d", target_sndbuf);
-    else
-      disorder_info("changed socket send buffer size from %d to %d",
-                    sndbuf, target_sndbuf);
-  } else
-    disorder_info("default socket send buffer is %d", sndbuf);
+  /* Enlarge the socket buffers */
+  hack_send_buffer_size(rtp_fd, "master socket");
   /* We might well want to set additional broadcast- or multicast-related
    * options here */
   if(rtp_mode != RTP_REQUEST) {