/* Handle --exec if appropriate, otherwise start the initial read events and set the idle timeout. */ static void post_connect(nsock_pool nsp, nsock_iod iod) { /* Command to execute. */ if (o.cmdexec) { struct fdinfo info; info.fd = nsi_getsd(iod); #ifdef HAVE_OPENSSL info.ssl = (SSL *) nsi_getssl(iod); #endif /* Convert Nsock's non-blocking socket to an ordinary blocking one. It's possible for a program to write fast enough that it will get an EAGAIN on write on a non-blocking socket. */ block_socket(info.fd); netexec(&info, o.cmdexec); } /* Start the initial reads. */ if (!o.sendonly) nsock_read(nsp, cs.sock_nsi, read_socket_handler, -1, NULL); if (!o.recvonly) nsock_readbytes(nsp, cs.stdin_nsi, read_stdin_handler, -1, NULL, 0); /* The --idle-timeout option says to exit after a certain period of inactivity. We start a timer here and reset it on every read event; see refresh_idle_timer. */ if (o.idletimeout > 0) { cs.idle_timer_event_id = nsock_timer_create(nsp, idle_timer_handler, o.idletimeout, NULL); } }
static int check_errlevel(struct log_test_data *ltd, nsock_loglevel_t level) { nsock_event_id id; nsock_set_loglevel(level); ltd->current_level = level; ltd->got_dbgfull = 0; ltd->got_dbg = 0; ltd->got_info = 0; ltd->got_error = 0; ltd->total = 0; ltd->errcode = 0; id = nsock_timer_create(ltd->nsp, nop_handler, 200, NULL); nsock_event_cancel(ltd->nsp, id, 0); if (ltd->errcode) return ltd->errcode; if (ltd->total > 0) return -EINVAL; return 0; }
static void refresh_idle_timer(nsock_pool nsp) { if (o.idletimeout <= 0) return; nsock_event_cancel(nsp, cs.idle_timer_event_id, 0); cs.idle_timer_event_id = nsock_timer_create(nsp, idle_timer_handler, o.idletimeout, NULL); }
nsock_event_id request_timer(nsock_pool nsp, nsock_ev_handler handler, int timeout_msecs, void *userdata) { nsock_event_id id; id = nsock_timer_create(nsp, handler, timeout_msecs, userdata); printf("%ld: Created timer ID %li for %d ms from now\n", time(NULL), id, timeout_msecs); return id; }
static void add_timer(struct timer_test_data *ttd, int timeout) { nsock_event_id id; id = nsock_timer_create(ttd->nsp, timer_handler, timeout, ttd); ttd->timer_list[ttd->timer_count++] = id; }