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

Ilkka Ollakka git at videolan.org
Sun Dec 16 21:35:39 CET 2018


vlc/vlc-3.0 | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Mon Oct 15 17:21:22 2018 +0300| [3b0b6396b44466ebd28c0fe2b32a2e5fa97bad45] | committer: Jean-Baptiste Kempf

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>
(cherry picked from commit 373ee85fe57d29bcf3502c47e29cc2fcde7af983)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=3b0b6396b44466ebd28c0fe2b32a2e5fa97bad45
---

 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 cf6ebb7125..84ae29601a 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -233,6 +233,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,
@@ -240,9 +246,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];
@@ -260,7 +264,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:
@@ -268,8 +273,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);
@@ -277,7 +281,6 @@ skip:
         sys->mtu = len;
     }
     else
-#endif
         pkt->i_buffer = len;
 
     return pkt;



More information about the vlc-commits mailing list