[vlc-devel] [PATCH] access/udp: use MSG_PEEK for non-linux cases to check new size
Ilkka Ollakka
ileoo at videolan.org
Thu Oct 18 19:15:47 CEST 2018
---
modules/access/udp.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/modules/access/udp.c b/modules/access/udp.c
index 654ecf83c3..0279956fa9 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -231,11 +231,6 @@ 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,
@@ -244,7 +239,6 @@ static block_t *BlockUDP(stream_t *access, bool *restrict eof)
struct msghdr msg = {
.msg_iov = &iov,
.msg_iovlen = 1,
- .msg_flags = trunc_flag,
};
struct pollfd ufd[1];
@@ -262,6 +256,15 @@ static block_t *BlockUDP(stream_t *access, bool *restrict eof)
goto skip;
}
+#ifdef __linux__
+ /* We define MSG_TRUNC only for linux
+ * as for other systems it's not defined flag for input
+ */
+ const int trunc_flag = MSG_TRUNC;
+#else
+ const int trunc_flag = 0;
+#endif
+
ssize_t len = recvmsg(sys->fd, &msg, trunc_flag);
if (len < 0)
@@ -271,14 +274,31 @@ skip:
return NULL;
}
- if (msg.msg_flags & trunc_flag)
+#ifdef MSG_TRUNC
+ if (msg.msg_flags & MSG_TRUNC)
{
+ pkt->i_flags |= BLOCK_FLAG_CORRUPTED;
+ /* On linux systems MSG_TRUNC tells the available data,
+ on other cases, I think we need to use MSG_PEEK to get how much
+ there would be availabled in case of trunced message.
+ In MSG_PEEK case, assumption is also, that in real world
+ the size don't fluctuate huge amounts in streaming and the result
+ is most likely correct mtu size if current was truncated.
+ */
+# ifdef __linux__
msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
len, sys->mtu);
- pkt->i_flags |= BLOCK_FLAG_CORRUPTED;
sys->mtu = len;
+# else
+ unsigned char peek_buffer[65536];
+ size_t old_mtu = sys->mtu;
+ sys->mtu = recv(sys->fd, peek_buffer, 65536, MSG_PEEK);
+ msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
+ sys->mtu, old_mtu);
+# endif
}
else
+#endif
pkt->i_buffer = len;
return pkt;
--
2.19.1
More information about the vlc-devel
mailing list