[vlc-devel] [PATCH 2/2] access/udp: Define MSG_TRUNC on recv call

Ilkka Ollakka ileoo at videolan.org
Mon Oct 15 16:21:22 CEST 2018


recv() needs MSG_TRUNC flag so it will tell actual data-size if truncate
would happen additional to setting flag for it.

Tested adjustment of MTU by sending data to localhost via netcat:

cat ~/tmp/myfile.mp3|netcat -u 127.0.0.1 1234

and vlc -Idummy -vv udp://@127.0.0.1:1234 --sout="#stat"

without this patch the udp input constantly complains about trunced
input and doesn't adjust the receiving amount.

udp fixup
---
 modules/access/udp.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/modules/access/udp.c b/modules/access/udp.c
index d84cb7b99a..b5ba292e48 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -231,6 +231,12 @@ static block_t *BlockUDP(stream_t *access, bool *restrict eof)
         return NULL;
     }
 
+#ifdef __linux__
+    const int trunc_flag = MSG_TRUNC;
+#else
+    const int trunc_flag = 0;
+#endif
+
     struct iovec iov = {
         .iov_base = pkt->p_buffer,
         .iov_len = sys->mtu,
@@ -238,9 +244,7 @@ static block_t *BlockUDP(stream_t *access, bool *restrict eof)
     struct msghdr msg = {
         .msg_iov = &iov,
         .msg_iovlen = 1,
-#ifdef __linux__
-        .msg_flags = MSG_TRUNC,
-#endif
+        .msg_flags = trunc_flag,
     };
 
     struct pollfd ufd[1];
@@ -258,7 +262,8 @@ static block_t *BlockUDP(stream_t *access, bool *restrict eof)
             goto skip;
      }
 
-    ssize_t len = recvmsg(sys->fd, &msg, 0);
+    ssize_t len = recvmsg(sys->fd, &msg, trunc_flag);
+
     if (len < 0)
     {
 skip:
@@ -266,8 +271,7 @@ skip:
         return NULL;
     }
 
-#ifdef MSG_TRUNC
-    if (msg.msg_flags & MSG_TRUNC)
+    if (msg.msg_flags & trunc_flag )
     {
         msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
                 len, sys->mtu);
@@ -275,7 +279,6 @@ skip:
         sys->mtu = len;
     }
     else
-#endif
         pkt->i_buffer = len;
 
     return pkt;
-- 
2.19.0



More information about the vlc-devel mailing list