Changeset ff475a9143389b8026408362b900881668db4ea4

Show
Ignore:
Timestamp:
05/01/04 16:07:16 (5 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1073315236 +0000
git-parent:

[fbbfa7bff5904e41cba1f2e64c0527f593f3b823]

git-author:
Laurent Aimar <fenrir@videolan.org> 1073315236 +0000
Message:
  • tcp: use net_*.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access/tcp.c

    r3d6ee48 rff475a9  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003 VideoLAN 
    5  * $Id: tcp.c,v 1.2 2003/12/04 16:49:43 sam Exp $ 
     5 * $Id: tcp.c,v 1.3 2004/01/05 15:07:16 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    3030#include <vlc/input.h> 
    3131 
    32 #include <sys/stat.h> 
    33 #include <errno.h> 
    34 #include <fcntl.h> 
    35  
    36 #ifdef HAVE_SYS_TIME_H 
    37 #    include <sys/time.h> 
    38 #endif 
    39  
    40 #ifdef HAVE_UNISTD_H 
    41 #   include <unistd.h> 
    42 #endif 
    43  
    44 #ifdef WIN32 
    45 #   include <winsock2.h> 
    46 #   include <ws2tcpip.h> 
    47 #   ifndef IN_MULTICAST 
    48 #       define IN_MULTICAST(a) IN_CLASSD(a) 
    49 #   endif 
    50 #else 
    51 #   include <sys/socket.h> 
    52 #endif 
    53  
    5432#include "network.h" 
    5533 
     
    7149    set_capability( "access", 0 ); 
    7250    add_shortcut( "tcp" ); 
    73     add_shortcut( "tcp4" ); 
    74     add_shortcut( "tcp6" ); 
    7551    set_callbacks( Open, Close ); 
    7652vlc_module_end(); 
     
    9571    access_sys_t   *p_sys; 
    9672 
    97     char           *psz_network; 
    9873    char           *psz_dup = strdup(p_input->psz_name); 
    9974    char           *psz_parser = psz_dup; 
    10075 
    101     network_socket_t sock; 
    102     module_t         *p_network; 
    103  
    104     vlc_value_t     val; 
    105  
    106     /* Select ip version */ 
    107     psz_network = ""; 
    108     if( config_GetInt( p_input, "ipv4" ) ) 
    109     { 
    110         psz_network = "ipv4"; 
    111     } 
    112     if( config_GetInt( p_input, "ipv6" ) ) 
    113     { 
    114         psz_network = "ipv6"; 
    115     } 
    116     if( *p_input->psz_access ) 
    117     { 
    118         /* Find out which shortcut was used */ 
    119         if( !strncmp( p_input->psz_access, "tcp6", 5 ) ) 
    120         { 
    121             psz_network = "ipv6"; 
    122         } 
    123         else if( !strncmp( p_input->psz_access, "tcp4", 5 ) ) 
    124         { 
    125             psz_network = "ipv4"; 
    126         } 
    127     } 
     76    vlc_value_t    val; 
    12877 
    12978    /* Parse server:port */ 
     
    14089        psz_parser++; 
    14190    } 
    142  
    14391    if( *psz_parser != ':' || psz_parser == psz_dup ) 
    14492    { 
     
    14795        return VLC_EGENERIC; 
    14896    } 
    149  
    15097    *psz_parser++ = '\0'; 
    15198 
    152     /* Prepare the network_socket_t structure */ 
    153     sock.i_type = NETWORK_TCP; 
    154     sock.psz_bind_addr = ""; 
    155     sock.i_bind_port = 0; 
    156     sock.psz_server_addr = psz_dup; 
    157     sock.i_server_port = atoi( psz_parser ); 
    158     sock.i_ttl           = 0; 
    159  
    160     if( sock.i_server_port <= 0 ) 
     99    if( atoi( psz_parser ) <= 0 ) 
    161100    { 
    162         msg_Err( p_input, "invalid port number (%d)", sock.i_server_port ); 
     101        msg_Err( p_input, "invalid port number (%d)", atoi( psz_parser ) ); 
    163102        free( psz_dup ); 
    164103        return VLC_EGENERIC; 
    165104    } 
    166105 
    167     /* connecting */ 
    168     msg_Dbg( p_input, "opening server=%s:%d", 
    169              sock.psz_server_addr, sock.i_server_port ); 
    170     p_input->p_private = (void*)&sock; 
    171     p_network = module_Need( p_input, "network", psz_network ); 
     106    /* Connect */ 
     107    p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) ); 
     108    p_sys->fd = net_OpenTCP( p_input, psz_dup, atoi( psz_parser ) ); 
    172109    free( psz_dup ); 
    173     if( p_network == NULL ) 
     110 
     111    if( p_sys->fd < 0 ) 
    174112    { 
     113        free( p_sys ); 
    175114        return VLC_EGENERIC; 
    176115    } 
    177     module_Unneed( p_input, p_network ); 
    178  
    179     p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) ); 
    180     p_sys->fd = sock.i_handle; 
    181116 
    182117    p_input->pf_read = Read; 
     
    211146    msg_Info( p_input, "closing TCP target `%s'", p_input->psz_source ); 
    212147 
    213 #ifdef UNDER_CE 
    214     CloseHandle( (HANDLE)p_sys->fd ); 
    215 #elif defined( WIN32 ) 
    216     closesocket( p_sys->fd ); 
    217 #else 
    218     close( p_sys->fd ); 
    219 #endif 
    220  
     148    net_Close( p_sys->fd ); 
    221149    free( p_sys ); 
    222150} 
     
    227155static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len ) 
    228156{ 
    229 #ifdef UNDER_CE 
    230     return -1; 
    231 #else 
    232157    access_sys_t   *p_sys = p_input->p_access_data; 
    233     struct timeval  timeout; 
    234     fd_set          fds; 
    235     ssize_t         i_recv; 
    236     int             i_ret; 
    237158 
    238     do 
    239     { 
    240         if( p_input->b_die || p_input->b_error ) 
    241         { 
    242             return 0; 
    243         } 
    244  
    245         /* Initialize file descriptor set */ 
    246         FD_ZERO( &fds ); 
    247         FD_SET( p_sys->fd, &fds ); 
    248  
    249         /* We'll wait 0.5 second if nothing happens */ 
    250         timeout.tv_sec = 0; 
    251         timeout.tv_usec = 500000; 
    252     } while( ( i_ret = select( p_sys->fd + 1, &fds, NULL, NULL, &timeout )) == 0 || 
    253              ( i_ret < 0 && errno == EINTR ) ); 
    254  
    255     if( i_ret < 0 ) 
    256     { 
    257         msg_Err( p_input, "network select error (%s)", strerror(errno) ); 
    258         return -1; 
    259     } 
    260  
    261     if( ( i_recv = recv( p_sys->fd, p_buffer, i_len, 0 ) ) < 0 ) 
    262     { 
    263         msg_Err( p_input, "recv failed (%s)", strerror(errno) ); 
    264     } 
    265     return i_recv; 
    266 #endif 
     159    return net_Read( p_input, p_sys->fd, p_buffer, i_len, VLC_FALSE ); 
    267160} 
    268161