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 ) );
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 ) );
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 */
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 )
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 )
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 )
{
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;
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 )
{
}
- 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;
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 );
}
}
{
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 );
}
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 */
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;
}
/* 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;
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 )
}
/* 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"
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;
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 )
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"
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"
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;
/* 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" );
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;
}
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;
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 )
/* 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 );
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 );
}
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' )
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 );
}
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
* 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;
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 */
*****************************************************************************
* 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;
#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 */
* 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;
{
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
/* 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;
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 */
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;
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;
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;
#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 )
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 );