lib/poll-loop.c
/* Blocks until one or more of the events registered with poll_fd_wait()
 * occurs, or until the minimum duration registered with poll_timer_wait()
 * elapses, or not at all if poll_immediate_wake() has been called. */
Blocks until one or more of the events registered with poll_fd_wait()
occurs, or until the minimum duration registered with poll_timer_wait()
elapses, or not at all if poll_immediate_wake() has been called.
Blocks until one or more of the events registered with poll_fd_wait () occurs or until the minimum duration registered with poll_timer_wait () elapses or not at all if poll_immediate_wake () has been called .
void
poll_block(void)
{
    struct poll_loop *loop = poll_loop();
    struct poll_node *node;
    struct pollfd *pollfds;
    HANDLE *wevents = NULL;
    int elapsed;
    int retval;
    int i;
    fatal_signal_wait();
    if (loop->timeout_when == LLONG_MIN) {
        COVERAGE_INC(poll_zero_timeout);
    }
    timewarp_run();
    pollfds = xmalloc(hmap_count(&loop->poll_nodes) * sizeof *pollfds);
#ifdef _WIN32
    wevents = xmalloc(hmap_count(&loop->poll_nodes) * sizeof *wevents);
#endif
    i = 0;
    HMAP_FOR_EACH (node, hmap_node, &loop->poll_nodes) {
        pollfds[i] = node->pollfd;
#ifdef _WIN32
        wevents[i] = node->wevent;
        if (node->pollfd.fd && node->wevent) {
            short int wsa_events = 0;
            if (node->pollfd.events & POLLIN) {
                wsa_events |= FD_READ | FD_ACCEPT | FD_CLOSE;
            }
            if (node->pollfd.events & POLLOUT) {
                wsa_events |= FD_WRITE | FD_CONNECT | FD_CLOSE;
            }
            WSAEventSelect(node->pollfd.fd, node->wevent, wsa_events);
        }
#endif
        i++;
    }
    retval = time_poll(pollfds, hmap_count(&loop->poll_nodes), wevents,
                       loop->timeout_when, &elapsed);
    if (retval < 0) {
        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
        VLOG_ERR_RL(&rl, "poll: %s", ovs_strerror(-retval));
    } else if (!retval) {
        log_wakeup(loop->timeout_where, NULL, elapsed);
    } else if (get_cpu_usage() > 50 || VLOG_IS_DBG_ENABLED()) {
        i = 0;
        HMAP_FOR_EACH (node, hmap_node, &loop->poll_nodes) {
            if (pollfds[i].revents) {
                log_wakeup(node->where, &pollfds[i], 0);
            }
            i++;
        }
    }
    free_poll_nodes(loop);
    loop->timeout_when = LLONG_MAX;
    loop->timeout_where = NULL;
    free(pollfds);
    free(wevents);
    fatal_signal_run();
    seq_woke();
}
void poll_block ( void ) { struct poll_loop * loop = poll_loop ( ) ; struct poll_node * node ; struct pollfd * pollfds ; HANDLE * wevents = NULL ; int elapsed ; int retval ; int i ; fatal_signal_wait ( ) ; if ( loop -> timeout_when == LLONG_MIN ) { COVERAGE_INC ( poll_zero_timeout ) ; } timewarp_run ( ) ; pollfds = xmalloc ( hmap_count ( & loop -> poll_nodes ) * sizeof * pollfds ) ; #ifdef _WIN32 wevents = xmalloc ( hmap_count ( & loop -> poll_nodes ) * sizeof * wevents ) ; #endif i = 0 ; HMAP_FOR_EACH ( node , hmap_node , & loop -> poll_nodes ) { pollfds [ i ] = node -> pollfd ; #ifdef _WIN32 wevents [ i ] = node -> wevent ; if ( node -> pollfd . fd && node -> wevent ) { short int wsa_events = 0 ; if ( node -> pollfd . events & POLLIN ) { wsa_events |= FD_READ | FD_ACCEPT | FD_CLOSE ; } if ( node -> pollfd . events & POLLOUT ) { wsa_events |= FD_WRITE | FD_CONNECT | FD_CLOSE ; } WSAEventSelect ( node -> pollfd . fd , node -> wevent , wsa_events ) ; } #endif i ++ ; } retval = time_poll ( pollfds , hmap_count ( & loop -> poll_nodes ) , wevents , loop -> timeout_when , & elapsed ) ; if ( retval < 0 ) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT ( 1 , 5 ) ; VLOG_ERR_RL ( & rl , " " , ovs_strerror ( - retval ) ) ; } else if ( ! retval ) { log_wakeup ( loop -> timeout_where , NULL , elapsed ) ; } else if ( get_cpu_usage ( ) > 50 || VLOG_IS_DBG_ENABLED ( ) ) { i = 0 ; HMAP_FOR_EACH ( node , hmap_node , & loop -> poll_nodes ) { if ( pollfds [ i ] . revents ) { log_wakeup ( node -> where , & pollfds [ i ] , 0 ) ; } i ++ ; } } free_poll_nodes ( loop ) ; loop -> timeout_when = LLONG_MAX ; loop -> timeout_where = NULL ; free ( pollfds ) ; free ( wevents ) ; fatal_signal_run ( ) ; seq_woke ( ) ; }
Blocks until one or more of the events registered with poll_fd_wait()
 occurs, or until the minimum duration registered with poll_timer_wait()
 elapses, or not at all if poll_immediate_wake() has been called.
Blocks until one or more of the events registered with poll_fd_wait () occurs or until the minimum duration registered with poll_timer_wait () elapses or not at all if poll_immediate_wake () has been called .
/* Register fatal signal events before actually doing any real work for
     * poll_block. */ /* Populate with all the fds and events. */ /* Handle any pending signals before doing anything else. */