X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Ftcp.c;h=7b111f0ca055c7d77c1d4450cf569626e1e91365;hb=2e3a8c064b0bbe7cccec85b4a2bb9082ef7d8433;hp=e8f6a76a08e903a07df86db61574def78171eb3a;hpb=9bfb547eac3c2ac3ee3c457d096e4424f7cdefb3;p=vlc diff --git a/modules/access/tcp.c b/modules/access/tcp.c index e8f6a76a08..7b111f0ca0 100644 --- a/modules/access/tcp.c +++ b/modules/access/tcp.c @@ -1,7 +1,7 @@ /***************************************************************************** * tcp.c: TCP input module ***************************************************************************** - * Copyright (C) 2003-2004 VideoLAN + * Copyright (C) 2003-2004 the VideoLAN team * $Id$ * * Authors: Laurent Aimar @@ -18,40 +18,48 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include "network.h" +#include +#include +#include + +#include /***************************************************************************** * Module descriptor *****************************************************************************/ #define CACHING_TEXT N_("Caching value in ms") #define CACHING_LONGTEXT N_( \ - "Allows you to modify the default caching value for TCP streams. This " \ - "value should be set in millisecond units." ) + "Caching value for TCP streams. This " \ + "value should be set in milliseconds." ) static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); -vlc_module_begin(); - set_description( _("TCP input") ); +vlc_module_begin () + set_shortname( N_("TCP") ) + set_description( N_("TCP input") ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_ACCESS ) add_integer( "tcp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, - CACHING_LONGTEXT, VLC_TRUE ); + CACHING_LONGTEXT, true ) + change_safe() - set_capability( "access2", 0 ); - add_shortcut( "tcp" ); - set_callbacks( Open, Close ); -vlc_module_end(); + set_capability( "access", 0 ) + add_shortcut( "tcp" ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Local prototypes @@ -62,7 +70,7 @@ struct access_sys_t }; -static int Read( access_t *, uint8_t *, int ); +static ssize_t Read( access_t *, uint8_t *, size_t ); static int Control( access_t *, int, va_list ); /***************************************************************************** @@ -73,51 +81,38 @@ static int Open( vlc_object_t *p_this ) access_t *p_access = (access_t *)p_this; access_sys_t *p_sys; - char *psz_dup = strdup(p_access->psz_path); + char *psz_dup = strdup(p_access->psz_location); char *psz_parser = psz_dup; /* Parse server:port */ - while( *psz_parser && *psz_parser != ':' ) + if( *psz_parser == '[' ) { - if( *psz_parser == '[' ) - { - /* IPV6 */ - while( *psz_parser && *psz_parser != ']' ) - { - psz_parser++; - } - } - psz_parser++; + psz_parser = strchr( psz_parser, ']' ); + if( psz_parser == NULL ) + psz_parser = psz_dup; } - if( *psz_parser != ':' || psz_parser == psz_dup ) + psz_parser = strchr( psz_parser, ':' ); + + if( psz_parser == NULL ) { - msg_Err( p_access, "you have to provide server:port addresse" ); + msg_Err( p_access, "missing port number : %s", psz_dup ); free( psz_dup ); return VLC_EGENERIC; } + *psz_parser++ = '\0'; - if( atoi( psz_parser ) <= 0 ) + /* Init p_access */ + access_InitFields( p_access ); + ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL ); + p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) ); + if( !p_sys ) { - msg_Err( p_access, "invalid port number (%d)", atoi( psz_parser ) ); free( psz_dup ); - return VLC_EGENERIC; + return VLC_ENOMEM; } - /* Init p_access */ - p_access->pf_read = Read; - p_access->pf_block = NULL; - p_access->pf_control = Control; - p_access->pf_seek = NULL; - p_access->info.i_update = 0; - p_access->info.i_size = 0; - p_access->info.i_pos = 0; - p_access->info.b_eof = VLC_FALSE; - p_access->info.i_title = 0; - p_access->info.i_seekpoint = 0; - p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) ); - - p_sys->fd = net_OpenTCP( p_access, psz_dup, atoi( psz_parser ) ); + p_sys->fd = net_ConnectTCP( p_access, psz_dup, atoi( psz_parser ) ); free( psz_dup ); if( p_sys->fd < 0 ) @@ -145,9 +140,9 @@ static void Close( vlc_object_t *p_this ) } /***************************************************************************** - * Read: read on a file descriptor, checking b_die periodically + * Read: read on a file descriptor *****************************************************************************/ -static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) +static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) { access_sys_t *p_sys = p_access->p_sys; int i_read; @@ -155,9 +150,10 @@ 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, + false ); if( i_read == 0 ) - p_access->info.b_eof = VLC_TRUE; + p_access->info.b_eof = true; else if( i_read > 0 ) p_access->info.i_pos += i_read; @@ -169,36 +165,29 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) *****************************************************************************/ static int Control( access_t *p_access, int i_query, va_list args ) { - vlc_bool_t *pb_bool; - int *pi_int; - int64_t *pi_64; + bool *pb_bool; + int64_t *pi_64; switch( i_query ) { /* */ case ACCESS_CAN_SEEK: case ACCESS_CAN_FASTSEEK: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); - *pb_bool = VLC_FALSE; + pb_bool = (bool*)va_arg( args, bool* ); + *pb_bool = false; break; case ACCESS_CAN_PAUSE: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); - *pb_bool = VLC_TRUE; /* FIXME */ + pb_bool = (bool*)va_arg( args, bool* ); + *pb_bool = true; /* FIXME */ break; case ACCESS_CAN_CONTROL_PACE: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); - *pb_bool = VLC_TRUE; /* FIXME */ - break; - - /* */ - case ACCESS_GET_MTU: - pi_int = (int*)va_arg( args, int * ); - *pi_int = 0; + pb_bool = (bool*)va_arg( args, bool* ); + *pb_bool = true; /* FIXME */ break; case ACCESS_GET_PTS_DELAY: pi_64 = (int64_t*)va_arg( args, int64_t * ); - *pi_64 = (int64_t)var_GetInteger( p_access, "tcp-caching" ) * I64C(1000); + *pi_64 = var_GetInteger( p_access, "tcp-caching" ) * INT64_C(1000); break; /* */ @@ -210,6 +199,7 @@ static int Control( access_t *p_access, int i_query, va_list args ) case ACCESS_SET_TITLE: case ACCESS_SET_SEEKPOINT: case ACCESS_SET_PRIVATE_ID_STATE: + case ACCESS_GET_CONTENT_TYPE: return VLC_EGENERIC; default: