Changeset ecbbbc15c84f94dba5d9d3a1d54ae9802256a7bf

Show
Ignore:
Timestamp:
01/05/08 19:04:10 (8 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1199556250 +0000
git-parent:

[318d3056c5234df7651172ba8a89e346c478d5cd]

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

Use the event pipe in net_Read instead of an arbitrary timer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/network/io.c

    r590701d recbbbc1  
    257257 * __net_Read: 
    258258 ***************************************************************************** 
    259  * Read from a network socket 
     259 * Reads from a network socket. 
    260260 * If waitall is true, then we repeat until we have read the right amount of 
    261261 * data; in that case, a short count means EOF has been reached. 
     
    266266{ 
    267267    size_t i_total = 0; 
    268     struct pollfd ufd[1]; 
    269     ufd[0].fd = fd; 
    270     ufd[0].events = POLLIN; 
    271  
     268    struct pollfd ufd[2] = { 
     269        { .fd = fd, .events = POLLIN }, 
     270        { .fd = -1, .events = POLLIN }, 
     271    }; 
     272 
     273    msg_Dbg (p_this, "reading socket %d", fd); 
     274    vlc_object_lock (p_this); 
     275    ufd[1].fd = vlc_object_waitpipe (p_this); 
    272276 
    273277    while (i_buflen > 0) 
    274278    { 
    275         if( ( p_this->b_die ) || ( p_this->p_libvlc->b_die ) ) 
     279        int val; 
     280 
     281        if (!vlc_object_alive (p_this)) 
    276282        { 
    277283#if defined(WIN32) || defined(UNDER_CE) 
     
    282288            goto error; 
    283289        } 
    284  
    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)) 
    288         { 
    289             case -1: 
    290                 goto error; 
    291  
    292             case 0: // timeout 
    293                 continue; 
     290        ufd[0].revents = ufd[1].revents = 0; 
     291 
     292        vlc_object_unlock (p_this); 
     293        val = poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1); 
     294        vlc_object_lock (p_this); 
     295 
     296        if (val < 0) 
     297            goto error; 
     298 
     299        if (ufd[1].revents) 
     300        { 
     301            msg_Dbg (p_this, "socket %d polling interrupted", fd); 
     302            vlc_object_wait (p_this); 
     303            msg_Dbg (p_this, "socket %d polling restarting", fd); 
     304            continue; 
    294305        } 
    295306 
     
    305316             * bad idea™. */ 
    306317            if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) 
    307                 return i_total
     318                break
    308319        } 
    309320 
     
    368379            break; 
    369380    } 
     381 
     382    vlc_object_unlock (p_this); 
     383    msg_Dbg (p_this, "read %u bytes from socket %d", (unsigned)i_total, fd); 
    370384    return i_total; 
    371385 
    372386error: 
    373387    msg_Err (p_this, "Read error: %m"); 
    374     return i_total ? (ssize_t)i_total : -1; 
     388 
     389    vlc_object_unlock (p_this); 
     390    return -1; 
    375391} 
    376392