static void stream_wait(struct vconn *vconn, enum vconn_wait_type wait) { struct stream_vconn *s = stream_vconn_cast(vconn); switch (wait) { case WAIT_CONNECT: poll_fd_wait(s->fd, POLLOUT); break; case WAIT_SEND: if (!s->txbuf) { poll_fd_wait(s->fd, POLLOUT); } else { /* Nothing to do: need to drain txbuf first. */ } break; case WAIT_RECV: poll_fd_wait(s->fd, POLLIN); break; default: NOT_REACHED(); } }
static void ssl_wait(struct stream *stream, enum stream_wait_type wait) { struct ssl_stream *sslv = ssl_stream_cast(stream); switch (wait) { case STREAM_CONNECT: if (stream_connect(stream) != EAGAIN) { poll_immediate_wake(); } else { switch (sslv->state) { case STATE_TCP_CONNECTING: poll_fd_wait(sslv->fd, POLLOUT); break; case STATE_SSL_CONNECTING: /* ssl_connect() called SSL_accept() or SSL_connect(), which * set up the status that we test here. */ poll_fd_wait(sslv->fd, want_to_poll_events(SSL_want(sslv->ssl))); break; default: OVS_NOT_REACHED(); } } break; case STREAM_RECV: if (sslv->rx_want != SSL_NOTHING) { poll_fd_wait(sslv->fd, want_to_poll_events(sslv->rx_want)); } else { poll_immediate_wake(); } break; case STREAM_SEND: if (!sslv->txbuf) { /* We have room in our tx queue. */ poll_immediate_wake(); } else { /* stream_run_wait() will do the right thing; don't bother with * redundancy. */ } break; default: OVS_NOT_REACHED(); } }
static void ssl_wait(struct vconn *vconn, enum vconn_wait_type wait) { struct ssl_vconn *sslv = ssl_vconn_cast(vconn); switch (wait) { case WAIT_CONNECT: if (vconn_connect(vconn) != EAGAIN) { poll_immediate_wake(); } else { switch (sslv->state) { case STATE_TCP_CONNECTING: poll_fd_wait(sslv->fd, POLLOUT); break; case STATE_SSL_CONNECTING: /* ssl_connect() called SSL_accept() or SSL_connect(), which * set up the status that we test here. */ poll_fd_wait(sslv->fd, want_to_poll_events(SSL_want(sslv->ssl))); break; default: NOT_REACHED(); } } break; case WAIT_RECV: if (sslv->rx_want != SSL_NOTHING) { poll_fd_wait(sslv->fd, want_to_poll_events(sslv->rx_want)); } else { poll_immediate_wake(); } break; case WAIT_SEND: if (!sslv->txbuf) { /* We have room in our tx queue. */ poll_immediate_wake(); } else { /* The call to ssl_tx_poll_callback() will wake us up. */ } break; default: NOT_REACHED(); } }
static void stream_wait(struct stream *s) { if (s->fds[0] >= 0) { poll_fd_wait(s->fds[0], POLLIN); } }
static void ssl_run_wait(struct stream *stream) { struct ssl_stream *sslv = ssl_stream_cast(stream); if (sslv->tx_want != SSL_NOTHING) { poll_fd_wait(sslv->fd, want_to_poll_events(sslv->tx_want)); } }
/* Causes the next call to poll_block() to wake up when signal_poll(s) would * return true. */ void signal_wait(struct signal *s) { if (signaled[s->signr]) { poll_immediate_wake(); } else { poll_fd_wait(fds[0], POLLIN); } }
static void fd_wait(struct stream *stream, enum stream_wait_type wait) { struct stream_fd *s = stream_fd_cast(stream); switch (wait) { case STREAM_CONNECT: case STREAM_SEND: poll_fd_wait(s->fd, POLLOUT); break; case STREAM_RECV: poll_fd_wait(s->fd, POLLIN); break; default: NOT_REACHED(); } }
/* Causes the next call to poll_block() to wake up when process 'p' has * exited. */ void process_wait(struct process *p) { if (p->exited) { poll_immediate_wake(); } else { poll_fd_wait(fds[0], POLLIN); } }
void fatal_signal_wait(void) { fatal_signal_init(); #ifdef _WIN32 poll_wevent_wait(wevent); #else poll_fd_wait(signal_fds[0], POLLIN); #endif }
int main(int argc, char *argv[]) { struct unixctl_server *server; enum { MAX_RECV = 1500 }; const char *target; struct ofpbuf buf; bool exiting = false; int error; int sock; int n; proctitle_init(argc, argv); set_program_name(argv[0]); parse_options(argc, argv); if (argc - optind != 1) { ovs_fatal(0, "exactly one non-option argument required " "(use --help for help)"); } target = argv[optind]; sock = inet_open_passive(SOCK_DGRAM, target, 0, NULL, 0); if (sock < 0) { ovs_fatal(0, "%s: failed to open (%s)", argv[1], strerror(-sock)); } daemon_save_fd(STDOUT_FILENO); daemonize_start(); error = unixctl_server_create(NULL, &server); if (error) { ovs_fatal(error, "failed to create unixctl server"); } unixctl_command_register("exit", "", 0, 0, test_netflow_exit, &exiting); daemonize_complete(); ofpbuf_init(&buf, MAX_RECV); n = 0; for (;;) { int retval; unixctl_server_run(server); ofpbuf_clear(&buf); do { retval = read(sock, buf.data, buf.allocated); } while (retval < 0 && errno == EINTR); if (retval > 0) { ofpbuf_put_uninit(&buf, retval); if (n++ > 0) { putchar('\n'); } print_netflow(&buf); fflush(stdout); } if (exiting) { break; } poll_fd_wait(sock, POLLIN); unixctl_server_wait(server); poll_block(); } return 0; }
void fatal_signal_wait(void) { fatal_signal_init(); poll_fd_wait(signal_fds[0], POLLIN); }
/* Causes poll_block() to wake up when any of the specified 'events' (which is * a OR'd combination of POLLIN, POLLOUT, etc.) occur on 'sock'. */ void nl_sock_wait(const struct nl_sock *sock, short int events) { poll_fd_wait(sock->fd, events); }
/* Causes the next call to poll_block() to wake up when signal_poll(s) would * return true. */ void signal_wait(struct signal *s) { poll_fd_wait(s->fds[0], POLLIN); }