vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Sun Jan 31 19:30:35 2016 +0200| [256919fcff9dabe84c35435f315fac2d42219cb6] | committer: Rémi Denis-Courmont
udp: use more reasonable default buffer size (fixes #16315) > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=256919fcff9dabe84c35435f315fac2d42219cb6 --- 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 d860fb4..f1f4047 100644 --- a/modules/access/udp.c +++ b/modules/access/udp.c @@ -48,8 +48,6 @@ #endif #include <fcntl.h> -#define MTU 65535 - /***************************************************************************** * Module descriptor *****************************************************************************/ @@ -80,6 +78,7 @@ struct access_sys_t { int fd; int timeout; + size_t mtu; size_t fifo_size; block_fifo_t *fifo; vlc_sem_t semaphore; @@ -185,6 +184,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 ); @@ -287,7 +287,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; @@ -295,6 +295,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); @@ -316,12 +327,22 @@ static void* ThreadRead( void *data ) len=0; break; } - 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 */ _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
