1 /*****************************************************************************
2 * input_ts.h: structures of the input not exported to other modules
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: input_ts.h,v 1.10 2001/07/12 23:06:54 gbazin Exp $
7 * Authors: Henri Fallon <henri@via.ecp.fr>
8 * Boris Dorès <babal@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
28 #define BUFFER_SIZE (7 * TS_PACKET_SIZE)
30 /*****************************************************************************
31 * thread_ts_data_t: private input data
32 *****************************************************************************/
33 typedef struct thread_ts_data_s
35 /* The file descriptor we select() on */
39 char p_buffer[ BUFFER_SIZE ]; /* temporary buffer for readv_network */
40 int i_length; /* length of the UDP packet */
41 int i_offset; /* number of bytes already read from the buffer */
46 /*****************************************************************************
47 * network readv() replacement for iovec-impaired C libraries
48 *****************************************************************************/
50 static __inline__ int read_network( int i_fd, char * p_base,
51 thread_ts_data_t *p_sys, int i_len )
55 if( p_sys->i_offset >= p_sys->i_length )
57 p_sys->i_length = recv( i_fd, p_sys->p_buffer, BUFFER_SIZE, 0 );
58 if ( p_sys->i_length == SOCKET_ERROR )
65 if( i_len <= p_sys->i_length - p_sys->i_offset )
71 i_bytes = p_sys->i_length - p_sys->i_offset;
74 memcpy( p_base, p_sys->p_buffer + p_sys->i_offset, i_bytes );
75 p_sys->i_offset += i_bytes;
80 static __inline__ int readv_network( int i_fd, struct iovec *p_iovec,
81 int i_count, thread_ts_data_t *p_sys )
83 int i_index, i_len, i_total = 0;
86 for( i_index = i_count; i_index; i_index-- )
88 register signed int i_bytes;
90 i_len = p_iovec->iov_len;
91 p_base = p_iovec->iov_base;
93 /* Loop is unrolled one time to spare the (i_bytes <= 0) test */
96 i_bytes = read_network( i_fd, p_base, p_sys, i_len );
98 if( ( i_total == 0 ) && ( i_bytes < 0 ) )
108 i_len -= i_bytes; i_total += i_bytes; p_base += i_bytes;
112 i_bytes = read_network( i_fd, p_base, p_sys, i_len );
119 i_len -= i_bytes; i_total += i_bytes; p_base += i_bytes;