[vlc-devel] [PATCHv2] udp: use more reasonable default buffer size
Rémi Denis-Courmont
remi at remlab.net
Wed Feb 3 17:41:22 CET 2016
This is totally untested and probably breaks some crappy OSes.
---
modules/access/udp.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/modules/access/udp.c b/modules/access/udp.c
index 9e08b55..80e434f 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -45,8 +45,6 @@
#include <vlc_interrupt.h>
#include <fcntl.h>
-#define MTU 65535
-
/*****************************************************************************
* Module descriptor
*****************************************************************************/
@@ -74,6 +72,7 @@ vlc_module_end ()
struct access_sys_t
{
int fd;
+ size_t mtu;
size_t fifo_size;
block_fifo_t *fifo;
vlc_sem_t semaphore;
@@ -178,6 +177,7 @@ static int Open( vlc_object_t *p_this )
goto error;
}
+ sys->mtu = 7 * 188;
sys->fifo_size = var_InheritInteger( p_access, "udp-buffer");
vlc_sem_init( &sys->semaphore, 0 );
@@ -270,7 +270,7 @@ static void* ThreadRead( void *data )
for(;;)
{
- block_t *pkt = block_Alloc(MTU);
+ block_t *pkt = block_Alloc(sys->mtu);
if (unlikely(pkt == NULL))
{ /* OOM - dequeue and discard one packet */
char dummy;
@@ -278,6 +278,17 @@ static void* ThreadRead( void *data )
continue;
}
+ struct iovec iov = {
+ .iov_base = pkt->p_buffer,
+ .iov_len = sys->mtu,
+ };
+ struct msghdr msg = {
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+#ifdef __linux__
+ .msg_flags = MSG_TRUNC,
+#endif
+ };
ssize_t len;
block_cleanup_push(pkt);
@@ -287,12 +298,22 @@ static void* ThreadRead( void *data )
struct pollfd ufd = { .fd = sys->fd, .events = POLLIN };
while (poll(&ufd, 1, -1) <= 0); /* cancellation point */
#endif
- len = recv(sys->fd, pkt->p_buffer, MTU, 0);
+ len = recvmsg(sys->fd, &msg, 0);
}
while (len == -1);
vlc_cleanup_pop();
- pkt->i_buffer = len;
+#ifdef MSG_TRUNC
+ if (msg.msg_flags & MSG_TRUNC)
+ {
+ msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
+ len, sys->mtu);
+ pkt->i_flags |= BLOCK_FLAG_CORRUPTED;
+ sys->mtu = len;
+ }
+ else
+#endif
+ pkt->i_buffer = len;
vlc_fifo_Lock(sys->fifo);
/* Discard old buffers on overflow */
--
2.7.0
More information about the vlc-devel
mailing list