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

Ilkka Ollakka ileoo at videolan.org
Sat Oct 13 20:03:50 CEST 2018


Allows receiving the data size additional to trunced flag.

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 rtp input constantly complains about trunced
input and doesn't adjust the receiving amount.
---
 modules/access/udp.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/modules/access/udp.c b/modules/access/udp.c
index d84cb7b99a..e2069278ea 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__
+    int trunc_flag = MSG_TRUNC;
+#else
+    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,7 +271,6 @@ skip:
         return NULL;
     }
 
-#ifdef MSG_TRUNC
     if (msg.msg_flags & MSG_TRUNC)
     {
         msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
@@ -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