[vlc-commits] access/udp: Define MSG_TRUNC on recv call

Ilkka Ollakka git at videolan.org
Mon Oct 15 18:17:19 CEST 2018


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Mon Oct 15 17:21:22 2018 +0300| [373ee85fe57d29bcf3502c47e29cc2fcde7af983] | committer: Rémi Denis-Courmont

access/udp: Define MSG_TRUNC on recv call

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

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=373ee85fe57d29bcf3502c47e29cc2fcde7af983
---

 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..654ecf83c3 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;



More information about the vlc-commits mailing list