Changeset 8c906d60c6282fc2529209855912920474daa2d8

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

[6db8acaa4945c84c4671c4aeece517ead6deee10]

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

Use poll() directly when you want to listen to multiple sockets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/services_discovery/sap.c

    r3c32591 r8c906d6  
    4444#ifdef HAVE_SYS_TIME_H 
    4545#    include <sys/time.h> 
     46#endif 
     47#ifdef HAVE_POLL 
     48# include <poll.h> 
    4649#endif 
    4750 
     
    537540    while( !p_sd->b_die ) 
    538541    { 
    539         int i_read; 
    540         uint8_t p_buffer[MAX_SAP_BUFFER+1]; 
    541  
    542         i_read = net_Select( p_sd, p_sd->p_sys->pi_fd, 
    543                              p_sd->p_sys->i_fd, p_buffer, 
    544                              MAX_SAP_BUFFER, 500 ); 
     542        unsigned n = p_sd->p_sys->i_fd; 
     543        struct pollfd ufd[n]; 
     544 
     545        for (unsigned i = 0; i < n; i++) 
     546        { 
     547            ufd[i].fd = p_sd->p_sys->pi_fd[i]; 
     548            ufd[i].events = POLLIN; 
     549            ufd[i].revents = 0; 
     550        } 
     551 
     552        /* FIXME FIXME FIXME: short arbitrary timer */ 
     553        if (poll (ufd, n, 500) > 0) 
     554        { 
     555            for (unsigned i = 0; i < n; i++) 
     556            { 
     557                if (ufd[i].revents) 
     558                { 
     559                    uint8_t p_buffer[MAX_SAP_BUFFER+1]; 
     560                    ssize_t i_read; 
     561 
     562                    i_read = net_Read (p_sd, ufd[i].fd, NULL, p_buffer, 
     563                                       MAX_SAP_BUFFER, VLC_FALSE); 
     564                    if (i_read < 0) 
     565                        msg_Warn (p_sd, "receive error: %m"); 
     566                    if (i_read > 6) 
     567                    { 
     568                        /* Parse the packet */ 
     569                        p_buffer[i_read] = '\0'; 
     570                        ParseSAP (p_sd, p_buffer, i_read); 
     571                    } 
     572                } 
     573            } 
     574        } 
     575 
     576        mtime_t now = mdate(); 
    545577 
    546578        /* Check for items that need deletion */ 
     
    549581            mtime_t i_timeout = ( mtime_t ) 1000000 * p_sd->p_sys->i_timeout; 
    550582            sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i]; 
    551             mtime_t i_last_period = mdate() - p_announce->i_last; 
    552              
     583            mtime_t i_last_period = now - p_announce->i_last; 
     584 
    553585            /* Remove the annoucement, if the last announcement was 1 hour ago 
    554586             * or if the last packet emitted was 3 times the average time 
     
    560592            } 
    561593        } 
    562  
    563         /* Minimum length is > 6 */ 
    564         if( i_read <= 6 ) 
    565         { 
    566             if( i_read < 0 ) 
    567             { 
    568                 msg_Warn( p_sd, "socket read error" ); 
    569             } 
    570             continue; 
    571         } 
    572  
    573         p_buffer[i_read] = '\0'; 
    574  
    575         /* Parse the packet */ 
    576         ParseSAP( p_sd, p_buffer, i_read ); 
    577594    } 
    578595}