[vlc-devel] [PATCH] udp: use more reasonable default buffer size

Rémi Denis-Courmont remi at remlab.net
Sun Jan 31 18:30:35 CET 2016


This is totally untested and probably breaks some crappy OSes.
---
 modules/access/udp.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/modules/access/udp.c b/modules/access/udp.c
index 9e08b55..b243fce 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -45,8 +45,6 @@
 #include <vlc_interrupt.h>
 #include <fcntl.h>
 
-#define MTU 65535
-
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -74,6 +72,7 @@ vlc_module_end ()
 struct access_sys_t
 {
     int fd;
+    size_t mtu;
     size_t fifo_size;
     block_fifo_t *fifo;
     vlc_sem_t semaphore;
@@ -178,6 +177,7 @@ static int Open( vlc_object_t *p_this )
         goto error;
     }
 
+    sys->mtu = 7 * 188;
     sys->fifo_size = var_InheritInteger( p_access, "udp-buffer");
     vlc_sem_init( &sys->semaphore, 0 );
 
@@ -270,7 +270,7 @@ static void* ThreadRead( void *data )
 
     for(;;)
     {
-        block_t *pkt = block_Alloc(MTU);
+        block_t *pkt = block_Alloc(sys->mtu);
         if (unlikely(pkt == NULL))
         {   /* OOM - dequeue and discard one packet */
             char dummy;
@@ -278,6 +278,14 @@ static void* ThreadRead( void *data )
             continue;
         }
 
+        struct iovec iov = {
+            .iov_base = pkt->p_buffer,
+            .iov_len = sys->mtu,
+        };
+        struct msghdr msg = {
+            .msg_iov = &iov,
+            .msg_iovlen = 1,
+        };
         ssize_t len;
 
         block_cleanup_push(pkt);
@@ -287,12 +295,20 @@ static void* ThreadRead( void *data )
             struct pollfd ufd = { .fd = sys->fd, .events = POLLIN };
             while (poll(&ufd, 1, -1) <= 0); /* cancellation point */
 #endif
-            len = recv(sys->fd, pkt->p_buffer, MTU, 0);
+            len = recvmsg(sys->fd, &msg, 0);
         }
         while (len == -1);
         vlc_cleanup_pop();
 
-        pkt->i_buffer = len;
+        if (msg.msg_flags & MSG_TRUNC)
+        {
+            msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
+                    len, sys->mtu);
+            pkt->i_flags |= BLOCK_FLAG_CORRUPTED;
+            sys->mtu = len;
+        }
+        else
+            pkt->i_buffer = len;
 
         vlc_fifo_Lock(sys->fifo);
         /* Discard old buffers on overflow */
-- 
1.9.1



More information about the vlc-devel mailing list