/** * Initializes the networking interfaces * @arg config Takes the bloom server configuration * @arg mgr The filter manager to pass up to the connection handlers * @arg netconf Output. The configuration for the networking stack. */ int init_networking(statsite_config *config, statsite_networking **netconf_out) { // Initialize the netconf structure statsite_networking *netconf = calloc(1, sizeof(struct statsite_networking)); netconf->config = config; /** * Check if we can use kqueue instead of select. * By default, libev will not use kqueue since it only * works for sockets, which is all we need. */ int ev_mode = EVFLAG_AUTO; if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) { ev_mode = EVBACKEND_KQUEUE; } if (!ev_default_loop (ev_mode)) { syslog(LOG_CRIT, "Failed to initialize libev!"); free(netconf); return 1; } // Setup the TCP listener int res = setup_tcp_listener(netconf); if (res != 0) { free(netconf); return 1; } // Setup the UDP listener res = setup_udp_listener(netconf); if (res != 0) { ev_io_stop(&netconf->tcp_client); close(netconf->tcp_client.fd); free(netconf); return 1; } syslog(LOG_INFO, "Listening on tcp '%s:%d' udp '%s:%d'.", netconf->config->bind_address, netconf->config->tcp_port, netconf->config->bind_address, netconf->config->udp_port); // Setup the timer ev_timer_init(&netconf->flush_timer, handle_flush_event, config->flush_interval, config->flush_interval); ev_timer_start(&netconf->flush_timer); // Prepare the conn handlers init_conn_handler(config); // Success! *netconf_out = netconf; return 0; }
/* Update the event timer after curl_multi library calls */ static int multi_timer_cb(CURLM *multi, long timeout_ms) { g_debug("%s %li", __PRETTY_FUNCTION__, timeout_ms); ev_timer_stop(g_dionaea->loop, &curl_runtime.timer_event); if( timeout_ms > 0 ) { double t = timeout_ms / 1000; ev_timer_init(&curl_runtime.timer_event, timer_cb, t, 0.); ev_timer_start(g_dionaea->loop, &curl_runtime.timer_event); } else timer_cb(g_dionaea->loop, &curl_runtime.timer_event, 0); return 0; }
int main() { loop = ev_create_loop(); ev_io_start(loop, 100, 1); ev_io_register(loop, 0, EV_READ, cb_stdin1, NULL); ev_timer_start(loop, 10); ev_timer_register(loop, 5.0, cb_timer1, 1, NULL); ev_run_loop(loop); return 0; }
void plugin_http_status_start_monitors(struct ev_loop* mon_loop) { dmn_assert(mon_loop); for(unsigned int i = 0; i < num_mons; i++) { http_events_t* mon = mons[i]; dmn_assert(mon->sock == -1); const unsigned ival = mon->http_svc->interval; const double stagger = (((double)i) / ((double)num_mons)) * ((double)ival); ev_timer* ival_watcher = mon->interval_watcher; ev_timer_set(ival_watcher, stagger, ival); ev_timer_start(mon_loop, ival_watcher); } }
/* Update the event timer after curl_multi library calls */ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) { DPRINT("%s %li\n", __PRETTY_FUNCTION__, timeout_ms); ev_timer_stop(g->loop, &g->timer_event); if (timeout_ms > 0) { double t = timeout_ms / 1000; ev_timer_init(&g->timer_event, timer_cb, t, 0.); ev_timer_start(g->loop, &g->timer_event); }else timer_cb(g->loop, &g->timer_event, 0); return 0; }
static void input_done(void) { if (clear_pam_wrong_timeout) { ev_timer_stop(main_loop, clear_pam_wrong_timeout); free(clear_pam_wrong_timeout); clear_pam_wrong_timeout = NULL; } pam_state = STATE_PAM_VERIFY; redraw_screen(); if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) { DEBUG("successfully authenticated\n"); clear_password_memory(); if (shell_auth_done_command) { system(shell_auth_done_command); } exit(0); } else { if (shell_auth_fail_command) { system(shell_auth_fail_command); } } if (debug_mode) fprintf(stderr, "Authentication failure\n"); pam_state = STATE_PAM_WRONG; clear_input(); redraw_screen(); /* Clear this state after 2 seconds (unless the user enters another * password during that time). */ ev_now_update(main_loop); if ((clear_pam_wrong_timeout = calloc(sizeof(struct ev_timer), 1))) { ev_timer_init(clear_pam_wrong_timeout, clear_pam_wrong, 2.0, 0.); ev_timer_start(main_loop, clear_pam_wrong_timeout); } /* Cancel the clear_indicator_timeout, it would hide the unlock indicator * too early. */ stop_clear_indicator_timeout(); /* beep on authentication failure, if enabled */ if (beep) { xcb_bell(conn, 100); xcb_flush(conn); } }
// ///////////////////////////////////////////////////////////////////////////// // main loop SCM joystick_loop(SCM jsdevice) { /* open the joystick device */ /* we're only waiting on one joystick at a time for now, so we're going to use a single * variable. TODO: handle multiple joysticks. */ char* jsdevice_c = scm_to_locale_string(jsdevice); jsfd = open(jsdevice_c, O_RDONLY); // check to make sure our joystick is real if (jsfd < 0) { printf("Could not open device %s: %s\n", jsdevice_c, strerror(errno)); return SCM_BOOL_F; } // clean up the filename string. free(jsdevice_c); // set up event loop struct ev_loop* loop = ev_default_loop(0); // set up and run watchers // file watcher waiting for new events from the joystick. this is where joystick data gets into // xbindjoy and where procedures bound to buttons are called from. ev_io js_watcher; ev_init(&js_watcher, js_callback); ev_io_set(&js_watcher, jsfd, EV_READ); ev_io_start(loop, &js_watcher); // timer watcher that pings at a regular (30hz-ish) rate. this is where procedures bound to // axes are called from. ev_timer timer_watcher; ev_init(&timer_watcher, timer_callback); ev_timer_set(&timer_watcher, 0.0, target_timing); ev_timer_start(loop, &timer_watcher); clock_gettime(CLOCK_MONOTONIC, &last_time); // signal watcher. safely clean up and exit on SIGINT. ev_signal sigint_watcher; ev_signal_init(&sigint_watcher, sigint_callback, SIGINT); ev_signal_start(loop, &sigint_watcher); // run the event loop and wait for events to start coming in ev_run(loop, 0); // close file descriptors. close(jsfd); // return success return SCM_BOOL_T; }
/* * Callback to setup DNS timeout callback */ static void dns_timer_setup_cb(struct dns_ctx *ctx, int timeout, void *data) { struct ev_loop *loop = (struct ev_loop *)data; if (ev_is_active(&resolv_timeout_watcher)) { ev_timer_stop(loop, &resolv_timeout_watcher); } if (ctx != NULL && timeout >= 0) { ev_timer_set(&resolv_timeout_watcher, timeout, 0.0); ev_timer_start(loop, &resolv_timeout_watcher); } }
static void time_restart(pa_time_event *ev, const struct timeval *tv) { ev_tstamp timeout = timeval_to_stamp(tv); lem_debug("resetting to %f seconds", timeout - ev_now(LEM)); ev->tv.tv_sec = tv->tv_sec; ev->tv.tv_usec = tv->tv_usec; ev_timer_stop(LEM_ &ev->w); ev_timer_set(&ev->w, timeout - ev_now(LEM), 0); ev_timer_start(LEM_ &ev->w); }
static void foreign_event_loop_init_and_run_libev(void) { /* we create and start our "foreign loop" */ loop_ev = ev_loop_new(0); ev_signal_init(&sighandler_ev, signal_cb_ev, SIGINT); ev_signal_start(loop_ev, &sighandler_ev); ev_timer_init(&timer_outer_ev, timer_cb_ev, 0, 1); ev_timer_start(loop_ev, &timer_outer_ev); ev_run(loop_ev, 0); }
/** * Called when a message is sent from the server **/ static void nol_s_ev_master(EV_P_ ev_io *w, int revents) { if ((revents & EV_ERROR) || nolp_recv(srv.m_nolp) != 0) { /* reach here if connection was closed or a socket error occured */ syslog(LOG_WARNING, "master has gone away, reconnecting in 5s"); close(w->fd); ev_io_stop(EV_A_ w); ev_timer_init(&srv.master_timer, &nol_s_ev_master_timer, 5.0f, 0.f); srv.master_timer.repeat = 5; ev_timer_start(EV_A_ &srv.master_timer); } }
int main (void) { // use the default event loop unless you have special needs struct ev_loop *loop = ev_default_loop (0); printf("Type help for a list of commands\n"); CBByteArray *ip = CBNewByteArrayWithDataCopy((uint8_t [16]){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 128, 8, 126, 25}, 16); CBNetworkAddress *peeraddr = CBNewNetworkAddress(0, ip, DEFAULT_PORT, CB_SERVICE_FULL_BLOCKS, false); peer = CBNewPeerByTakingNetworkAddress(peeraddr); // Create client socket if( (sd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("socket error"); return -1; } memset(&addr, sizeof(addr), 0); addr.sin_family = AF_INET; addr.sin_port = htons(DEFAULT_PORT); addr.sin_addr.s_addr = (((((25 << 8) | 126) << 8) | 8) << 8) | 128; // Connect to server socket if(connect(sd, (struct sockaddr *)&addr, sizeof addr) < 0) { perror("Connect error"); return -1; } printf("Connected to %s:%d\n", DEFAULT_IP, DEFAULT_PORT); // initialise an io watcher, then start it // this one will watch for stdin to become readable ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); ev_io_start (loop, &stdin_watcher); // io watcher for the socket ev_io_init (&sock_watcher, sockread_cb, sd, EV_READ); ev_io_start (loop, &sock_watcher); // initialise a timer watcher, then start it ev_timer_init (&timeout_watcher, timeout_cb, 2.0, 0.); ev_timer_start (loop, &timeout_watcher); // now wait for events to arrive ev_loop (loop, 0); // unloop was called, so exit return 0; }
static void accept_cb(EV_P_ ev_io *w, int revents) { struct listen_ctx *listener = (struct listen_ctx *)w; int serverfd = accept(listener->fd, NULL, NULL); if (serverfd == -1) { ERROR("accept"); return; } setnonblocking(serverfd); int opt = 1; setsockopt(serverfd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); #ifdef SO_NOSIGPIPE setsockopt(serverfd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)); #endif int index = rand() % listener->remote_num; struct sockaddr *remote_addr = listener->remote_addr[index]; int remotefd = socket(remote_addr->sa_family, SOCK_STREAM, IPPROTO_TCP); if (remotefd < 0) { ERROR("socket"); return; } setsockopt(remotefd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); #ifdef SO_NOSIGPIPE setsockopt(remotefd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)); #endif // Setup setnonblocking(remotefd); #ifdef SET_INTERFACE if (listener->iface) { setinterface(remotefd, listener->iface); } #endif struct server *server = new_server(serverfd, listener->method); struct remote *remote = new_remote(remotefd, listener->timeout); server->destaddr = listener->tunnel_addr; server->remote = remote; remote->server = server; connect(remotefd, remote_addr, get_sockaddr_len(remote_addr)); // listen to remote connected event ev_io_start(EV_A_ & remote->send_ctx->io); ev_timer_start(EV_A_ & remote->send_ctx->watcher); }
void ldap_bind(int msgid, BindRequest_t *req, ev_loop *loop, ev_io *watcher) { ev_tstamp delay = 0.0; LDAPMessage_t *res = XNEW0(LDAPMessage_t, 1); res->messageID = msgid; res->protocolOp.present = LDAPMessage__protocolOp_PR_bindResponse; BindResponse_t *bindResponse = &res->protocolOp.choice.bindResponse; OCTET_STRING_fromBuf(&bindResponse->matchedDN, (const char *)req->name.buf, req->name.size); if (setting_anonymous && req->name.size == 0) { /* allow anonymous */ asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_success); } else if (req->authentication.present == AuthenticationChoice_PR_simple) { /* simple auth */ char *user = cn2name((const char *)req->name.buf); char *pw = (char *)req->authentication.choice.simple.buf; char *status = NULL; if (!user) { asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_invalidDNSyntax); } else if (PAM_SUCCESS != auth_pam(user, pw, &status, &delay)) { asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_invalidCredentials); OCTET_STRING_fromString(&bindResponse->diagnosticMessage, status); } else { /* Success! */ asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_success); } free(user); free(status); } else { /* sasl or anonymous auth */ asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_authMethodNotSupported); } if (delay > 0.0) { ev_timer *delay_timer = XNEW(ev_timer, 1); delay_data_t *data = XNEW(delay_data_t, 1); data->message = res; data->watcher = watcher; ev_timer_init(delay_timer, delay_cb, delay, 0.0); delay_timer->data = data; /* Stop the connection watcher to stop other requests while delayed. */ ev_io_stop(loop, watcher); ev_timer_start(loop, delay_timer); } else { ldap_send(res, loop, watcher); ldapmessage_free(res); } }
void zc_asynio_write_start(zcAsynIO *conn) { if (!conn->w_init) { zc_asynio_write_init(conn); conn->w_init = 1; } ev_io_start(conn->loop, &conn->w); if (conn->write_timeout > 0) { float tm = conn->write_timeout/1000.0; ev_timer_set(&conn->wtimer, tm, tm); //ev_timer_init(&conn->wtimer, zc_asynio_write_ev_timeout, tm, tm); //conn->wtimer.data = conn; ev_timer_start(conn->loop, &conn->wtimer); } }
void connection_start(backend_t *backend, int fd, struct sockaddr_in remote_addr) { connection_t *c = (connection_t *) queue_pop(&backend->connections); /* no free connection found, add more */ if (c == NULL) { connections_push(backend); c = (connection_t *) queue_pop(&backend->connections); } assert(c != NULL); /* init connection */ c->finished = 0; c->loop = backend->loop; c->backend = backend; c->content_length = 0; c->fd = fd; c->remote_addr = inet_ntoa(remote_addr.sin_addr); c->thread.obj = Qnil; c->thread.active = 0; /* mark as used to Ruby GC */ c->env = rb_hash_new(); rb_gc_register_address(&c->env); /* reset buffers */ buffer_reset(&c->read_buffer); buffer_reset(&c->write_buffer); /* reinit parser */ http_parser_init(&c->parser); c->parser.data = c; /* init libev stuff */ c->read_watcher.data = c; c->write_watcher.data = c; c->timeout_watcher.data = c; ev_io_init(&c->read_watcher, connection_readable_cb, c->fd, EV_READ | EV_ERROR); ev_io_init(&c->write_watcher, connection_writable_cb, c->fd, EV_WRITE | EV_ERROR); ev_timer_init(&c->timeout_watcher, connection_timeout_cb, backend->timeout, backend->timeout); /* start event watchers */ ev_timer_start(c->loop, &c->timeout_watcher); ev_io_start(c->loop, &c->read_watcher); }
/* Procedure exposed in Python will generate and start the event loop */ static PyObject *py_run_loop(PyObject *self, PyObject *args) { char *backend=""; int i; ev_io accept_watcher; ev_signal signal_watcher, signal_watcher2, signal_watcher3; struct TimerObj *timer; loop = ev_default_loop (0); switch (ev_backend(loop)) { case 1: backend="select"; break; case 2: backend="poll"; break; case 4: backend="epoll"; break; case 8: backend="kqueue"; break; } printf("Using %s as event backend\n", backend); ev_io_init(&accept_watcher,accept_cb,sockfd,EV_READ); ev_io_start(loop,&accept_watcher); ev_signal_init(&signal_watcher, sigint_cb, SIGINT); ev_signal_start(loop, &signal_watcher); ev_signal_init(&signal_watcher2, sigpipe_cb, SIGPIPE); ev_signal_start(loop, &signal_watcher2); ev_signal_init(&signal_watcher3, sigterm_cb, SIGTERM); ev_signal_start(loop, &signal_watcher3); idle_watcher = malloc(sizeof(ev_idle)); ev_idle_init(idle_watcher, idle_cb); if (list_timers_i>=0) { for (i=0; i<list_timers_i; i++) { timer=list_timers[i]; ev_timer_init(&timer->timerwatcher, timer_cb, timer->delay, timer->delay); ev_timer_start(loop, &timer->timerwatcher); } } ev_loop (loop, 0); return Py_None; }
/*============================================================================== * Name : void Client_switch_to_stop(CONN_INFO* conn) * Abstr : Stop the socket io watcher and close it after a moment * Params : CONN_INFO* conn : connection with db server * Return : * Modify : *=============================================================================*/ void Client_switch_to_stop(CONN_INFO* conn) { /* reset connection alive flag */ conn->is_alive = FALSE; log_fatal(log_cat, "%s: catch exception", &conn->name[0]); /* stop connection io watcher */ ev_io_stop(host_loop, &conn->io_wt); /* do stopping handle after 10s */ ev_timer_init(&conn->t_wt, Client_stop_cb, timer_array[TID_STOP_DELAY].t_val, 0.); ev_timer_start(host_loop, &conn->t_wt); /* notice the host loop */ ev_async_send(host_loop, &async_wt); }
void accept_cb(struct ev_loop *loop, ev_io *w, int revents) { int client_sd = 0; struct sockaddr_in client_addr; socklen_t client_len = sizeof(struct sockaddr_in); if(EV_ERROR &revents) { printf("Error event in accpet, code %d:%s\r\n", errno, strerror(errno)); return; } client_sd = accept(w->fd, (struct sockaddr *)(&client_addr), &client_len); if(client_sd < 0) { printf("Accept error, code %d:%s\r\n", errno, strerror(errno)); return ; } if(client_sd > MAX_FD) { printf("Max fd thread\r\n"); goto err_sd; } client[client_sd] = (struct libev_context *)malloc(sizeof(struct libev_context)); if(client[client_sd] == NULL) { printf("Alloc context error, code %d:%s\r\n", errno, strerror(errno)); goto err_sd; } printf("Context alloc ok for client_fd=%d \r\n", client_sd); ev_io_init(&(client[client_sd]->watcher), client_cb, client_sd, EV_READ); ev_io_start(loop, &(*client[client_sd]).watcher); ev_timer_init(&((*client[client_sd]).timer), client_timer_cb, CONNECT_TIMEOUT, 0); ev_timer_start(loop, &((*client[client_sd]).timer)); printf("client connected success\r\n"); return ; err_sd: close(client_sd); }
void start_process(procnanny_t *pn, process_t *process) { program_t *program = pn_proc_program(process); program->state_cb = pn_proc_state_cb; pn_proc_start(process); ev_child *newwatcher = calloc(1, sizeof(ev_child)); ev_child_init(newwatcher, child_proc_cb, pn_proc_pid(process), 0); ev_child_start(pn->loop, newwatcher); newwatcher->data = process; pn_proc_watch_io(pn->loop, process); //publish_proc_event(process, "starting"); struct proc_data *procdata = process->data; procdata->running_state_timer = calloc(1, sizeof(ev_timer)); procdata->running_state_timer->data = process; ev_timer_init(procdata->running_state_timer, running_state_timer_cb, program->minimum_run_duration, program->minimum_run_duration); ev_timer_start(pn->loop, procdata->running_state_timer); } /* start_process */
F_NONNULL static void handle_req_repl(css_conn_t* c, css_t* css) { if (css->replacement_pid) { log_info("Deferring replace request while another replace already in progress"); respond(c, RESP_LATR, 0, 0, NULL, false); return; } log_debug("REPLACE[old daemon]: Accepting replace command, spawning replacement server..."); gdnsd_assert(!css->replace_conn_ctl); gdnsd_assert(!css->replace_conn_dmn); css->replace_conn_ctl = c; css->replacement_pid = spawn_replacement(css->argv0); log_info("REPLACE[old daemon]: Accepted replace command, spawned replacement daemon at PID %li", (long)css->replacement_pid); ev_timer* w_replace = &css->w_replace; ev_timer_start(css->loop, w_replace); latr_all_reloaders(css); }
static int _curl_timer_cb(CURLM *multi, long timeout_ms, struct curlev *cuev) { if (cuev->timered) { ev_timer_stop(cuev->loop, &cuev->timer); cuev->timered = false; } xsyslog(LOG_INFO, "curl update timer to %ldms", timeout_ms); if (timeout_ms > 0) { double _t = timeout_ms / 1000.0; ev_timer_set(&cuev->timer, _t, 0.); ev_timer_start(cuev->loop, &cuev->timer); cuev->timered = true; } else { _ev_timer_curl_cb(cuev->loop, &cuev->timer, 0); } return 0; }
static getdns_return_t getdns_libev_schedule_timeout(struct getdns_context* context, void* eventloop_data, uint16_t timeout, getdns_timeout_data_t* timeout_data, void** eventloop_timer) { struct ev_timer *timer; struct getdns_libev_data* ev_data = (struct getdns_libev_data*) eventloop_data; ev_tstamp to = timeout; to /= 1000; timer = (struct ev_timer*) malloc(sizeof(struct ev_timer)); ev_timer_init(timer, getdns_libev_timeout_cb, to, 0); timer->data = timeout_data; ev_timer_start(ev_data->loop, timer); *eventloop_timer = timer; return GETDNS_RETURN_GOOD; }
int zc_asynio_call_later(zcAsynIO *conn, int after, int repeat, int (*callback)(zcAsynIO*, void *data), void *data) { struct zc_asyn_callback_value_t *v = zc_calloct(struct zc_asyn_callback_value_t); //ev_timer timer; double after2 = after/1000.0; double repeat2 = repeat/1000.0; ev_timer_init(&v->timer, _call_later_ev_timeout, after2, repeat2); v->callback = callback; v->conn = conn; v->data = data; v->timer.data = v; ev_timer_start(conn->loop, &v->timer); return ZC_OK; }
bool LinkageWorker::RegisterTimer(int64_t interval, Runnable *runnable, bool auto_release) { if (!interval || !runnable) { return false; } double i = static_cast<double>(interval) / 1000000000; struct timer_t *timer = new struct timer_t; struct ev_timer *t = &timer->ev_timer; ev_timer_init(t, timer_cb, i, i); timer->auto_release = auto_release; timer->runnable = runnable; _timers.insert(timer); ev_timer_start(_loop, &timer->ev_timer); return true; }
void lwqq_async_global_quit() { //no need to destroy thread if(ev_thread_status == THREAD_NOT_CREATED) return ; global_quit_lock = 1; if(ev_thread_status == THREAD_NOW_WAITING){ pthread_cond_signal(&ev_thread_cond); }else if(ev_thread_status == THREAD_NOW_RUNNING){ ev_timer_init(&bomb,ev_bomb,0.001,0.001); ev_timer_start(ev_default,&bomb); } ev_thread_status = THREAD_NOT_CREATED; pthread_join(pid,NULL); ev_loop_destroy(ev_default); ev_default = NULL; pid = 0; global_quit_lock = 0; }
/** * Event loop for a client context. * * Usage of the loop is the following: * - client_injector_signal: send new client socket to the loop. Callback is * client_injector_cb(). * - client_writer_signal: if a write is needed, ask for removal of client socket. * from the loop and process to write by poping write event from a per-client * message queue. Callback is client_writer_cb(). * - client_destructor_signal: ask for removal a client socket from the loop. This * is used by the command_mode to trigger disconnection. Callback is * client_destructor_cb(). * - client_accept_cb(): treat new client. This call back is called by watcher * other server socket. * - loop_fini_signal: async signal used to trigger loop end * */ void tls_user_main_loop(struct tls_user_context_t *context, GMutex * mutex) { ev_io client_watcher; ev_timer timer; context->loop = ev_loop_new(0); /* register injector cb */ ev_async_init(&context->client_injector_signal, client_injector_cb); ev_async_start(context->loop, &context->client_injector_signal); context->client_injector_signal.data = context; /* register writer cb */ ev_async_init(&context->client_writer_signal, client_writer_cb); ev_async_start(context->loop, &context->client_writer_signal); context->client_writer_signal.data = context; ev_timer_init (&timer, client_timeout_cb, 0, 0.200); ev_timer_start (context->loop, &timer); /* register destructor cb */ ev_async_init(&context->client_destructor_signal, client_destructor_cb); ev_async_start(context->loop, &context->client_destructor_signal); context->client_destructor_signal.data = context; /* register destructor cb */ ev_async_init(&context->loop_fini_signal, loop_destructor_cb); ev_async_start(context->loop, &context->loop_fini_signal); context->loop_fini_signal.data = context; /* register accept cb */ fcntl(context->sck_inet,F_SETFL,(fcntl(context->sck_inet,F_GETFL)|O_NONBLOCK)); ev_io_init(&client_watcher, client_accept_cb, context->sck_inet, EV_READ); ev_io_start(context->loop, &client_watcher); client_watcher.data = context; log_message(INFO, DEBUG_AREA_USER, "[+] NuAuth is waiting for client connections."); ev_loop(context->loop, 0); ev_loop_destroy(context->loop); close(context->sck_inet); }
void as_event_command_begin(as_event_command* cmd) { // Always initialize timer first when timeouts are specified. if (cmd->timeout_ms) { ev_timer_init(&cmd->timer, as_ev_timeout, (double)cmd->timeout_ms / 1000.0, 0.0); cmd->timer.data = cmd; ev_timer_start(cmd->event_loop->loop, &cmd->timer); } as_connection_status status = cmd->pipe_listener != NULL ? as_pipe_get_connection(cmd) : as_event_get_connection(cmd); if (status == AS_CONNECTION_FROM_POOL) { as_ev_command_write_start(cmd); } else if (status == AS_CONNECTION_NEW) { as_ev_connect(cmd); } }
static int lcb_io_update_timer(struct lcb_io_opt_st *iops, void *timer, lcb_uint32_t usec, void *cb_data, void (*handler)(lcb_socket_t sock, short which, void *cb_data)) { struct libev_cookie *io_cookie = iops->v.v2.cookie; struct libev_event *evt = timer; ev_tstamp start; evt->data = cb_data; evt->handler = handler; start = usec / (ev_tstamp)1000000; ev_timer_stop(io_cookie->loop, &evt->ev.timer); ev_timer_init(&evt->ev.timer, timer_thunk, start, 0); ev_timer_start(io_cookie->loop, &evt->ev.timer); return 0; }
zcAsynIO* zc_asynio_new(zcSocket *sock, zcProtocol *p, struct ev_loop *loop, int rbufsize, int wbufsize) { zcAsynIO *conn = NULL; conn = zc_calloct(zcAsynIO); zc_socket_setblock(sock, ZC_FALSE); conn->rbuf = zc_buffer_new(rbufsize); conn->wbuf = zc_buffer_new(wbufsize); conn->rbuf_free = 1; conn->wbuf_free = 1; conn->rbuf_auto_compact = 1; /*conn->connected = ZC_FALSE; conn->accepting = ZC_FALSE; conn->close= ZC_FALSE; conn->ssl = ZC_FALSE;*/ conn->sock = sock; conn->loop = loop; if (p) { zc_asynio_set_protocol(conn, p); }else{ //default zc_protocol_init(&conn->p); } ev_io_init(&conn->r, zc_asynio_ev_read, conn->sock->fd, EV_READ); conn->r.data = conn; ev_io_start(conn->loop, &conn->r); int timeout = sock->timeout; conn->read_timeout = conn->write_timeout = conn->conn_timeout = timeout; //ZCINFO("timeout:%d\n", timeout); if (timeout > 0) { //ev_timer_init(&conn->timer, zc_asynio_ev_timeout, timeout, 1); float tm = timeout/1000.0; ev_timer_init(&conn->rtimer, zc_asynio_read_ev_timeout, tm, tm); conn->rtimer.data = conn; ev_timer_start(conn->loop, &conn->rtimer); } return conn; }