Changeset 590701d6b366c7fd7cfa4defb7fd4e5f706a3a50

Show
Ignore:
Timestamp:
12/22/07 11:02:50 (9 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1198317770 +0000
git-parent:

[8c906d60c6282fc2529209855912920474daa2d8]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1198317770 +0000
Message:

Remove net_Select. Simplify net_Read consequently.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_network.h

    rb3819c3 r590701d  
    124124VLC_EXPORT( ssize_t, __net_Read, ( vlc_object_t *p_this, int fd, const v_socket_t *, uint8_t *p_data, size_t i_data, vlc_bool_t b_retry ) ); 
    125125 
    126 #define net_Select(a,b,c,d,e) __net_Select(VLC_OBJECT(a),b,c,d,e) 
    127 VLC_EXPORT( ssize_t, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, int i_fd, uint8_t *p_data, size_t i_data ) ); 
    128  
    129126#define net_Write(a,b,c,d,e) __net_Write(VLC_OBJECT(a),b,c,d,e) 
    130127VLC_EXPORT( ssize_t, __net_Write, ( vlc_object_t *p_this, int fd, const v_socket_t *, const uint8_t *p_data, size_t i_data ) ); 
  • src/libvlc.sym

    r3ca1fe8 r590701d  
    175175net_Printf 
    176176__net_Read 
    177 __net_Select 
    178177net_SetCSCov 
    179178__net_vaPrintf 
  • src/network/io.c

    red9144b r590701d  
    254254 
    255255 
    256 static ssize_t 
    257 net_ReadInner (vlc_object_t *restrict p_this, unsigned fdc, const int *fdv, 
    258                const v_socket_t *const *restrict vsv, 
    259                uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) 
     256/***************************************************************************** 
     257 * __net_Read: 
     258 ***************************************************************************** 
     259 * Read from a network socket 
     260 * If waitall is true, then we repeat until we have read the right amount of 
     261 * data; in that case, a short count means EOF has been reached. 
     262 *****************************************************************************/ 
     263ssize_t 
     264__net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, 
     265            uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) 
    260266{ 
    261267    size_t i_total = 0; 
     268    struct pollfd ufd[1]; 
     269    ufd[0].fd = fd; 
     270    ufd[0].events = POLLIN; 
     271 
    262272 
    263273    while (i_buflen > 0) 
     
    273283        } 
    274284 
    275         struct pollfd ufd[fdc]; 
    276  
    277         for (unsigned i = 0; i < fdc; i++) 
    278         { 
    279             ufd[i].fd = fdv[i]; 
    280             ufd[i].events = POLLIN; 
    281             ufd[i].revents = 0; 
    282         } 
    283  
    284         switch (poll (ufd, fdc, 500)) 
     285        ufd[0].revents = 0; 
     286        /* TODO: don't use arbitrary timer just for b_die */ 
     287        switch (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), 500)) 
    285288        { 
    286289            case -1: 
     
    291294        } 
    292295 
    293         for (unsigned i = 0;; i++) 
    294         { 
    295             assert (i < fdc); /* no events found = bug ! */ 
    296  
    297             if (ufd[i].revents == 0) 
    298                 continue; 
     296        assert (ufd[0].revents); 
    299297 
    300298#ifndef POLLRDHUP /* This is nice but non-portable */ 
    301299# define POLLRDHUP 0 
    302300#endif 
    303             if (i_total > 0) 
    304             { 
    305                 // Errors (-1) and EOF (0) will be returned on next run 
    306                 if (ufd[i].revents & (POLLERR|POLLNVAL|POLLRDHUP)) 
    307                     return i_total; 
    308             } 
    309             else 
    310             { 
    311                 if (ufd[i].revents & POLLRDHUP) 
    312                     return 0; // EOF, read() would yield 0 
    313             } 
    314  
    315             fdc = 1; 
    316             fdv += i; 
    317             vsv += i; 
    318  
    319             break; 
     301        if (i_total > 0) 
     302        { 
     303            /* Errors (-1) and EOF (0) will be returned on next call, 
     304             * otherwise we'd "hide" the error from the caller, which is a 
     305             * bad idea™. */ 
     306            if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) 
     307                return i_total; 
    320308        } 
    321309 
    322310        ssize_t n; 
    323         if (*vsv != NULL) 
    324         { 
    325             n = (*vsv)->pf_recv ((*vsv)->p_sys, p_buf, i_buflen); 
     311        if (vs != NULL) 
     312        { 
     313            n = vs->pf_recv (vs->p_sys, p_buf, i_buflen); 
    326314        } 
    327315        else 
    328316        { 
    329317#ifdef WIN32 
    330             n = recv (*fdv, p_buf, i_buflen, 0); 
     318            n = recv (fd, p_buf, i_buflen, 0); 
    331319#else 
    332             n = read (*fdv, p_buf, i_buflen); 
    333 #endif 
    334         } 
    335  
    336         if (n == 0) 
    337             /* For streams, this means end of file, and there will not be any 
    338              * further data ever on the stream. For datagram sockets, this 
    339              * means empty datagram, and there could be more data coming. 
    340              * However, it makes no sense to set <waitall> with datagrams. 
    341              */ 
    342             break; // EOF 
     320            n = read (fd, p_buf, i_buflen); 
     321#endif 
     322        } 
    343323 
    344324        if (n == -1) 
     
    348328            { 
    349329                case WSAEWOULDBLOCK: 
    350                 /* only happens with vs != NULL (SSL) - not really an error */ 
     330                /* only happens with vs != NULL (TLS) - not really an error */ 
    351331                    continue; 
    352332 
     
    372352        } 
    373353 
     354        if (n == 0) 
     355            /* For streams, this means end of file, and there will not be any 
     356             * further data ever on the stream. For datagram sockets, this 
     357             * means empty datagram, and there could be more data coming. 
     358             * However, it makes no sense to set <waitall> with datagrams in the 
     359             * first place. 
     360             */ 
     361            break; // EOF 
     362 
    374363        i_total += n; 
    375364        p_buf += n; 
     
    384373    msg_Err (p_this, "Read error: %m"); 
    385374    return i_total ? (ssize_t)i_total : -1; 
    386 } 
    387  
    388  
    389 /***************************************************************************** 
    390  * __net_Read: 
    391  ***************************************************************************** 
    392  * Read from a network socket 
    393  * If b_retry is true, then we repeat until we have read the right amount of 
    394  * data; in that case, a short count means EOF has been reached. 
    395  *****************************************************************************/ 
    396 ssize_t __net_Read( vlc_object_t *restrict p_this, int fd, 
    397                     const v_socket_t *restrict p_vs, 
    398                     uint8_t *restrict buf, size_t len, vlc_bool_t b_retry ) 
    399 { 
    400     return net_ReadInner( p_this, 1, &(int){ fd }, 
    401                           &(const v_socket_t *){ p_vs }, 
    402                           buf, len, b_retry ); 
    403 } 
    404  
    405  
    406 /***************************************************************************** 
    407  * __net_Select: 
    408  ***************************************************************************** 
    409  * Read from several sockets. Takes data from the first socket that has some. 
    410  *****************************************************************************/ 
    411 ssize_t __net_Select( vlc_object_t *restrict p_this, 
    412                       const int *restrict fds, int nfd, 
    413                       uint8_t *restrict buf, size_t len ) 
    414 { 
    415     const v_socket_t *vsv[nfd]; 
    416     memset( vsv, 0, sizeof (vsv) ); 
    417  
    418     return net_ReadInner( p_this, nfd, fds, vsv, 
    419                           buf, len, VLC_FALSE ); 
    420375} 
    421376