Commit 436b59c5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

net_* API update for encryption (recv / send virtualization)

parent 211bbb87
......@@ -209,6 +209,8 @@ static inline char *vlc_b64_encode( unsigned char *src )
return ret;
}
/* Portable networking layer communication */
#define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) );
......@@ -223,23 +225,31 @@ VLC_EXPORT( int, __net_OpenUDP, ( vlc_object_t *p_this, char *psz_bind, int i_bi
VLC_EXPORT( void, net_Close, ( int fd ) );
#define net_Read(a,b,c,d,e) __net_Read(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_Read, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, vlc_bool_t b_retry ) );
#define net_ReadNonBlock(a,b,c,d,e) __net_ReadNonBlock(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_ReadNonBlock, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, mtime_t i_wait ) );
/* Functions to read from or write to the networking layer */
struct virtual_socket_t
{
void *p_sys;
int (*pf_recv) ( void *, void *, int );
int (*pf_send) ( void *, const void *, int );
};
#define net_Read(a,b,c,d,e,f) __net_Read(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( int, __net_Read, ( vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data, vlc_bool_t b_retry ) );
#define net_Select(a,b,c,d,e,f) __net_Select(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( int, __net_Select, ( vlc_object_t *p_this, int *pi_fd, int i_fd,uint8_t *p_data, int i_data, mtime_t i_wait ) );
#define net_ReadNonBlock(a,b,c,d,e,f) __net_ReadNonBlock(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( int, __net_ReadNonBlock, ( vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data, mtime_t i_wait ) );
#define net_Select(a,b,c,d,e,f,g) __net_Select(VLC_OBJECT(a),b,c,d,e,f,g)
VLC_EXPORT( int, __net_Select, ( vlc_object_t *p_this, int *pi_fd, v_socket_t **, int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait ) );
#define net_Write(a,b,c,d) __net_Write(VLC_OBJECT(a),b,c,d)
VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) );
#define net_Write(a,b,c,d,e) __net_Write(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data ) );
#define net_Gets(a,b) __net_Gets(VLC_OBJECT(a),b)
VLC_EXPORT( char *, __net_Gets, ( vlc_object_t *p_this, int fd ) );
#define net_Gets(a,b,c) __net_Gets(VLC_OBJECT(a),b,c)
VLC_EXPORT( char *, __net_Gets, ( vlc_object_t *p_this, int fd, v_socket_t * ) );
VLC_EXPORT( int, net_Printf, ( vlc_object_t *p_this, int fd, const char *psz_fmt, ... ) );
VLC_EXPORT( int, net_Printf, ( vlc_object_t *p_this, int fd, v_socket_t *, const char *psz_fmt, ... ) );
#define net_vaPrintf(a,b,c,d) __net_vaPrintf(VLC_OBJECT(a),b,c,d)
VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, const char *psz_fmt, va_list args ) );
#define net_vaPrintf(a,b,c,d,e) __net_vaPrintf(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, v_socket_t *, const char *psz_fmt, va_list args ) );
......@@ -340,6 +340,7 @@ typedef struct data_buffer_t data_buffer_t;
typedef struct stream_ctrl_t stream_ctrl_t;
typedef struct pes_packet_t pes_packet_t;
typedef struct network_socket_t network_socket_t;
typedef struct virtual_socket_t v_socket_t;
typedef struct iso639_lang_t iso639_lang_t;
/* block */
......
......@@ -319,7 +319,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_access->info.b_eof )
return 0;
i_read = net_Read( p_access, p_sys->fd_data, p_buffer, i_len, VLC_FALSE );
i_read = net_Read( p_access, p_sys->fd_data, NULL, p_buffer, i_len,
VLC_FALSE );
if( i_read == 0 )
p_access->info.b_eof = VLC_TRUE;
else if( i_read > 0 )
......@@ -404,10 +405,11 @@ static int ftp_SendCommand( access_t *p_access, char *psz_fmt, ... )
va_end( args );
msg_Dbg( p_access, "ftp_SendCommand:\"%s\"", psz_cmd);
if( ( i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd,
if( ( i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, NULL,
"%s", psz_cmd ) ) > 0 )
{
i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, "\r\n" );
i_ret = net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, NULL,
"\r\n" );
}
if( i_ret < 0 )
......@@ -440,7 +442,7 @@ static int ftp_ReadCommand( access_t *p_access,
char *psz_line;
int i_answer;
psz_line = net_Gets( p_access, p_sys->fd_cmd );
psz_line = net_Gets( p_access, p_sys->fd_cmd, NULL );
msg_Dbg( p_access, "answer=%s", psz_line );
if( psz_line == NULL || strlen( psz_line ) < 3 )
{
......@@ -460,7 +462,7 @@ static int ftp_ReadCommand( access_t *p_access,
for( ;; )
{
char *psz_tmp = net_Gets( p_access, p_sys->fd_cmd );
char *psz_tmp = net_Gets( p_access, p_sys->fd_cmd, NULL );
if( psz_tmp == NULL ) /* Error */
break;
......
......@@ -415,7 +415,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_sys->i_chunk <= 0 )
{
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd );
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
/* read the chunk header */
if( psz == NULL )
{
......@@ -440,7 +440,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
}
i_read = net_Read( p_access, p_sys->fd, p_buffer, i_len, VLC_FALSE );
i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
VLC_FALSE );
if( i_read > 0 )
{
p_access->info.i_pos += i_read;
......@@ -451,7 +452,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_sys->i_chunk <= 0 )
{
/* read the empty line */
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd );
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
if( psz ) free( psz );
}
}
......@@ -642,14 +643,14 @@ static int Connect( access_t *p_access, int64_t i_tell )
{
if( p_sys->url.psz_path )
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET http://%s:%d%s HTTP/1.%d\r\n",
p_sys->url.psz_host, p_sys->url.i_port,
p_sys->url.psz_path, p_sys->i_version );
}
else
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET http://%s:%d/ HTTP/1.%d\r\n",
p_sys->url.psz_host, p_sys->url.i_port,
p_sys->i_version );
......@@ -664,25 +665,25 @@ static int Connect( access_t *p_access, int64_t i_tell )
}
if( p_sys->url.i_port != 80)
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.%d\r\nHost: %s:%d\r\n",
psz_path, p_sys->i_version, p_sys->url.psz_host,
p_sys->url.i_port );
}
else
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.%d\r\nHost: %s\r\n",
psz_path, p_sys->i_version, p_sys->url.psz_host );
}
}
/* User Agent */
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "User-Agent: %s\r\n",
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "User-Agent: %s\r\n",
p_sys->psz_user_agent );
/* Offset */
if( p_sys->i_version == 1 )
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Range: bytes="I64Fd"-\r\n", i_tell );
}
/* Authentification */
......@@ -696,13 +697,14 @@ static int Connect( access_t *p_access, int64_t i_tell )
b64 = vlc_b64_encode( buf );
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Authorization: Basic %s\r\n", b64 );
free( b64 );
}
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "Connection: Close\r\n" );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Connection: Close\r\n" );
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 )
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
{
msg_Err( p_access, "failed to send request" );
net_Close( p_sys->fd ); p_sys->fd = -1;
......@@ -710,7 +712,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
}
/* Read Answer */
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL )
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
{
msg_Err( p_access, "failed to read answer" );
goto error;
......@@ -752,7 +754,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
for( ;; )
{
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd );
char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
char *p;
if( psz == NULL )
......
......@@ -374,7 +374,7 @@ static int Describe( access_t *p_access, char **ppsz_location )
}
/* send first request */
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.0\r\n"
"Accept: */*\r\n"
"User-Agent: NSPlayer/4.1.0.3856\r\n"
......@@ -387,14 +387,14 @@ static int Describe( access_t *p_access, char **ppsz_location )
p_sys->i_request_context++,
GUID_PRINT( p_sys->guid ) );
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 )
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
{
msg_Err( p_access, "failed to send request" );
goto error;
}
/* Receive the http header */
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL )
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
{
msg_Err( p_access, "failed to read answer" );
goto error;
......@@ -417,7 +417,7 @@ static int Describe( access_t *p_access, char **ppsz_location )
free( psz );
for( ;; )
{
char *psz = net_Gets( p_access, p_sys->fd );
char *psz = net_Gets( p_access, p_sys->fd, NULL );
char *p;
if( psz == NULL )
......@@ -575,7 +575,7 @@ static int Start( access_t *p_access, off_t i_pos )
msg_Err( p_access, "no stream selected" );
return VLC_EGENERIC;
}
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"GET %s HTTP/1.0\r\n"
"Accept: */*\r\n"
"User-Agent: NSPlayer/4.1.0.3856\r\n"
......@@ -584,19 +584,19 @@ static int Start( access_t *p_access, off_t i_pos )
p_sys->url.psz_host, p_sys->url.i_port );
if( p_sys->b_broadcast )
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
p_sys->i_request_context++ );
}
else
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
(uint32_t)((i_pos >> 32)&0xffffffff),
(uint32_t)(i_pos&0xffffffff),
p_sys->i_request_context++ );
}
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Pragma: xPlayStrm=1\r\n"
"Pragma: xClientGUID={"GUID_FMT"}\r\n"
"Pragma: stream-switch-count=%d\r\n"
......@@ -614,20 +614,21 @@ static int Start( access_t *p_access, off_t i_pos )
i_select = 0;
}
net_Printf( VLC_OBJECT(p_access), p_sys->fd,
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"ffff:%d:%d ", i, i_select );
}
}
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, "Connection: Close\r\n" );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
"Connection: Close\r\n" );
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 )
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
{
msg_Err( p_access, "failed to send request" );
return VLC_EGENERIC;
}
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL )
if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
{
msg_Err( p_access, "cannot read data" );
return VLC_EGENERIC;
......@@ -644,7 +645,7 @@ static int Start( access_t *p_access, off_t i_pos )
/* FIXME check HTTP code */
for( ;; )
{
char *psz = net_Gets( p_access, p_sys->fd );
char *psz = net_Gets( p_access, p_sys->fd, NULL );
if( psz == NULL )
{
msg_Err( p_access, "cannot read data" );
......@@ -691,7 +692,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
memset( p_ck, 0, sizeof( chunk_t ) );
/* Read the chunk header */
if( net_Read( p_access, p_sys->fd, p_sys->buffer, 12, VLC_TRUE ) < 12 )
if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 12, VLC_TRUE ) < 12 )
{
/* msg_Err( p_access, "cannot read data" ); */
return VLC_EGENERIC;
......@@ -725,7 +726,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
}
if( p_ck->i_data > 0 &&
net_Read( p_access, p_sys->fd, &p_sys->buffer[12], p_ck->i_data, VLC_TRUE ) < p_ck->i_data )
net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12], p_ck->i_data, VLC_TRUE ) < p_ck->i_data )
{
msg_Err( p_access, "cannot read data" );
return VLC_EGENERIC;
......
......@@ -155,7 +155,8 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_access->info.b_eof )
return 0;
i_read = net_Read( p_access, p_sys->fd, p_buffer, i_len, VLC_FALSE );
i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
VLC_FALSE );
if( i_read == 0 )
p_access->info.b_eof = VLC_TRUE;
else if( i_read > 0 )
......
......@@ -313,7 +313,9 @@ static block_t *BlockUDP( access_t *p_access )
/* Read data */
p_block = block_New( p_access, p_sys->i_mtu );
p_block->i_buffer = net_Read( p_access, p_sys->fd, p_block->p_buffer, p_sys->i_mtu, VLC_FALSE );
p_block->i_buffer = net_Read( p_access, p_sys->fd, NULL,
p_block->p_buffer, p_sys->i_mtu,
VLC_FALSE );
if( p_block->i_buffer <= 0 )
{
block_Release( p_block );
......
......@@ -112,8 +112,8 @@ void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... )
va_start( args, psz_fmt );
if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
else
{ net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args );
net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, "\r" ); }
{ net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, NULL, "\r" ); }
va_end( args );
}
......@@ -1167,7 +1167,7 @@ vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
(i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket,
0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
{
if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
......
......@@ -769,7 +769,7 @@ static int Demux( demux_t *p_demux )
if( p_sys->b_udp_out )
{
/* Send the complete block */
net_Write( p_demux, p_sys->fd, p_sys->buffer,
net_Write( p_demux, p_sys->fd, NULL, p_sys->buffer,
p_sys->i_ts_read * p_sys->i_packet_size );
}
......
......@@ -377,7 +377,7 @@ static void Run( intf_thread_t *p_intf )
continue;
}
int i_read = net_Select( p_intf, p_intf->p_sys->pi_fd,
int i_read = net_Select( p_intf, p_intf->p_sys->pi_fd, NULL,
p_intf->p_sys->i_fd, p_buffer,
MAX_SAP_BUFFER, 500000 );
#if 0
......
......@@ -296,8 +296,8 @@ void net_Close( int fd )
* If b_rety is true, then we repeat until we have read the right amount of
* data
*****************************************************************************/
int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data,
vlc_bool_t b_retry )
int __net_Read( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
uint8_t *p_data, int i_data, vlc_bool_t b_retry )
{
struct timeval timeout;
fd_set fds_r, fds_e;
......@@ -338,7 +338,9 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data,
return i_total > 0 ? i_total : -1;
}
if( ( i_recv = recv( fd, p_data, i_data, 0 ) ) < 0 )
if( ( i_recv = (p_vs != NULL)
? p_vs->pf_recv( p_vs->p_sys, p_data, i_data )
: recv( fd, p_data, i_data, 0 ) ) < 0 )
{
#if defined(WIN32) || defined(UNDER_CE)
/* For udp only */
......@@ -380,8 +382,8 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data,
*****************************************************************************
* Read from a network socket, non blocking mode (with timeout)
*****************************************************************************/
int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data,
int i_data, mtime_t i_wait)
int __net_ReadNonBlock( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
uint8_t *p_data, int i_data, mtime_t i_wait)
{
struct timeval timeout;
fd_set fds_r, fds_e;
......@@ -421,7 +423,9 @@ int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data,
#if !defined(UNDER_CE)
if( fd == 0/*STDIN_FILENO*/ ) i_recv = read( fd, p_data, i_data ); else
#endif
if( ( i_recv = recv( fd, p_data, i_data, 0 ) ) <= 0 )
if( ( i_recv = (p_vs != NULL)
? p_vs->pf_recv( p_vs->p_sys, p_data, i_data )
: recv( fd, p_data, i_data, 0 ) ) <= 0 )
{
#if defined(WIN32) || defined(UNDER_CE)
/* For udp only */
......@@ -454,8 +458,8 @@ int __net_ReadNonBlock( vlc_object_t *p_this, int fd, uint8_t *p_data,
* Read from several sockets (with timeout). Takes data from the first socket
* that has some.
*****************************************************************************/
int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data,
int i_data, mtime_t i_wait )
int __net_Select( vlc_object_t *p_this, int *pi_fd, v_socket_t **pp_vs,
int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait )
{
struct timeval timeout;
fd_set fds_r, fds_e;
......@@ -499,7 +503,9 @@ int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data,
{
if( FD_ISSET( pi_fd[i], &fds_r ) )
{
i_recv = recv( pi_fd[i], p_data, i_data, 0 );
i_recv = ((pp_vs != NULL) && (pp_vs[i] != NULL))
? pp_vs[i]->pf_recv( pp_vs[i]->p_sys, p_data, i_data )
: recv( pi_fd[i], p_data, i_data, 0 );
if( i_recv <= 0 )
{
#ifdef WIN32
......@@ -532,7 +538,8 @@ int __net_Select( vlc_object_t *p_this, int *pi_fd, int i_fd, uint8_t *p_data,
/* Write exact amount requested */
int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data )
int __net_Write( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
uint8_t *p_data, int i_data )
{
struct timeval timeout;
fd_set fds_w, fds_e;
......@@ -574,7 +581,9 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data )
return i_total > 0 ? i_total : -1;
}
if( ( i_send = send( fd, p_data, i_data, 0 ) ) < 0 )
if( ( i_send = (p_vs != NULL)
? p_vs->pf_send( p_vs->p_sys, p_data, i_data )
: send( fd, p_data, i_data, 0 ) ) < 0 )
{
/* XXX With udp for example, it will issue a message if the host
* isn't listening */
......@@ -589,7 +598,7 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data )
return i_total;
}
char *__net_Gets( vlc_object_t *p_this, int fd )
char *__net_Gets( vlc_object_t *p_this, int fd, v_socket_t *p_vs )
{
char *psz_line = malloc( 1024 );
int i_line = 0;
......@@ -598,7 +607,7 @@ char *__net_Gets( vlc_object_t *p_this, int fd )
for( ;; )
{
if( net_Read( p_this, fd, &psz_line[i_line], 1, VLC_TRUE ) != 1 )
if( net_Read( p_this, fd, p_vs, &psz_line[i_line], 1, VLC_TRUE ) != 1 )
{
psz_line[i_line] = '\0';
break;
......@@ -633,26 +642,27 @@ char *__net_Gets( vlc_object_t *p_this, int fd )
return psz_line;
}
int net_Printf( vlc_object_t *p_this, int fd, const char *psz_fmt, ... )
int net_Printf( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
const char *psz_fmt, ... )
{
int i_ret;
va_list args;
va_start( args, psz_fmt );
i_ret = net_vaPrintf( p_this, fd, psz_fmt, args );
i_ret = net_vaPrintf( p_this, fd, p_vs, psz_fmt, args );
va_end( args );
return i_ret;
}
int __net_vaPrintf( vlc_object_t *p_this, int fd, const char *psz_fmt,
va_list args )
int __net_vaPrintf( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
const char *psz_fmt, va_list args )
{
char *psz;
int i_size, i_ret;
vasprintf( &psz, psz_fmt, args );
i_size = strlen( psz );
i_ret = __net_Write( p_this, fd, psz, i_size ) < i_size ? -1 : i_size;
i_ret = __net_Write( p_this, fd, p_vs, psz, i_size ) < i_size ? -1 : i_size;
free( psz );
return i_ret;
......
......@@ -454,7 +454,7 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
#ifdef EXTRA_DEBUG
msg_Dbg( p_sap, "Sending announce");
#endif
i_ret = net_Write( p_sap, p_session->p_address->i_wfd,
i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL,
p_session->psz_data,
p_session->i_length );
if( i_ret != p_session->i_length )
......@@ -541,7 +541,7 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
do
{
/* Might be too slow if we have huge data */
i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, buffer,
i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, NULL, buffer,
SAP_MAX_BUFFER, 0 );
i_tot += i_read;
} while( i_read > 0 && i_tot < SAP_MAX_BUFFER );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment