scheduler_impl_t::wait_result_t scheduler_impl_t::wait_queue(spinlock_t* queue_lock, duration_t* timeout) { ev_timer timer_timeout; watcher_data_t watcher_data(FIBER_IMPL); deferred_unlock_t deferred(queue_lock); ev_tstamp start_wait; if(timeout) { start_wait = ev_now(ev_loop_); ev_init((ev_watcher*)&timer_timeout, switch_to_cb); ev_timer_set(&timer_timeout, timeout->count(), 0.0); ev_timer_start(ev_loop_, &timer_timeout); timer_timeout.data = &watcher_data; } FIBER_IMPL->yield(&deferred); unlink_activate(FIBER_IMPL); if(timeout) { *timeout -= duration_t(ev_now(ev_loop_) - start_wait); ev_timer_stop(ev_loop_, &timer_timeout); } if(timeout && (watcher_data.events & EV_TIMER)) { return TIMEDOUT; } else { return READY; } }
static void timeout_toggle(DBusTimeout *timeout, void *data) { struct timeout *t; (void)data; lem_debug("timeout = %p, interval = %d, enabled = %s", (void *)timeout, dbus_timeout_get_interval(timeout), dbus_timeout_get_enabled(timeout) ? "true" : "false"); t = dbus_timeout_get_data(timeout); if (dbus_timeout_get_enabled(timeout)) { ev_tstamp interval = ((ev_tstamp)dbus_timeout_get_interval(timeout))/1000.0; if (ev_is_active(&t->ev)) ev_timer_stop(EV_G_ &t->ev); ev_timer_set(&t->ev, interval, interval); ev_timer_start(EV_G_ &t->ev); } else ev_timer_stop(EV_G_ &t->ev); }
static void send_request(struct ev_loop *loop, domain_t * domain) { debug("send_request %s, search = %s", domain->domain, search_path[domain->index_search]); char buf[MAXLINE]; ev_io_set(&domain->io, domain->io.fd, EV_READ); ev_set_cb(&domain->io, recv_handler); ev_timer_set(&domain->tw, MAXRECVTIME, 0); size_t len = snprintf(buf, sizeof (buf), http_get, search_path[domain->index_search], domain->domain); /* this is safe */ if (len == writen(domain->io.fd, buf, len)) { //bzero(domain->data.buffer, sizeof(domain->data.buffer)); domain->data.len = 0; ev_io_start(loop, &domain->io); ev_timer_start(loop, &domain->tw); } else { free_domain(domain); } }
struct BufferedSocket *new_buffered_socket(struct ev_loop *loop, const char *address, int port, void (*connect_callback)(struct BufferedSocket *buffsock, void *arg), void (*close_callback)(struct BufferedSocket *buffsock, void *arg), void (*read_callback)(struct BufferedSocket *buffsock, struct Buffer *buf, void *arg), void (*write_callback)(struct BufferedSocket *buffsock, void *arg), void (*error_callback)(struct BufferedSocket *buffsock, void *arg), void *cbarg) { struct BufferedSocket *buffsock; buffsock = malloc(sizeof(struct BufferedSocket)); buffsock->address = strdup(address); buffsock->port = port; buffsock->read_buf = new_buffer(1024 * 16, 1024 * 16); buffsock->write_buf = new_buffer(1024 * 16, 1024 * 16); buffsock->fd = -1; buffsock->state = BS_INIT; buffsock->connect_callback = connect_callback; buffsock->close_callback = close_callback; buffsock->read_callback = read_callback; buffsock->write_callback = write_callback; buffsock->error_callback = error_callback; buffsock->cbarg = cbarg; buffsock->read_bytes_n = 0; buffsock->read_bytes_callback = NULL; buffsock->read_bytes_arg = NULL; buffsock->loop = loop; ev_init(&buffsock->read_bytes_timer_ev, buffered_socket_read_bytes_cb); buffsock->read_bytes_timer_ev.data = buffsock; ev_timer_set(&buffsock->read_bytes_timer_ev, 0., 0.); return buffsock; }
F_NONNULL static void die_gracefully(struct ev_loop* loop) { dmn_assert(loop); dmn_assert(killed_by); static bool done_once = false; if(!done_once) { // avoid repetition done_once = true; // send friendly death message to plugin sendq_enq(emc_encode_exit()); ev_io_start(loop, plugin_write_watcher); // kill interval timers for future invocations // and immediately clamp the remaining timeout // for any running commands to 2.0s. for(unsigned i = 0; i < num_mons; i++) { ev_timer_stop(loop, mons[i].interval_timer); if(ev_is_active(mons[i].cmd_timeout)) { if(ev_timer_remaining(loop, mons[i].cmd_timeout) > 2.0) { ev_timer_stop(loop, mons[i].cmd_timeout); ev_timer_set(mons[i].cmd_timeout, 2.0, 0.); ev_timer_start(loop, mons[i].cmd_timeout); } } } } }
void ConnectionInstance::setDelayClose() { delayClose = true; ev_io_stop(loop, readEvent); ev_timer_stop(loop, timerEvent); ev_timer_set(timerEvent, 1., 1.); ev_timer_start(loop, timerEvent); }
static void zc_asynio_read_timer_reset(zcAsynIO *conn) { if (conn->read_timeout > 0) { float tm = conn->read_timeout/1000.0; ev_timer_set(&conn->rtimer, tm, tm); ev_timer_start(conn->loop, &conn->rtimer); } }
void plugin_http_status_init_monitors(struct ev_loop* mon_loop) { dmn_assert(mon_loop); for(unsigned int i = 0; i < num_mons; i++) { ev_timer* ival_watcher = mons[i]->interval_watcher; dmn_assert(mons[i]->sock == -1); ev_timer_set(ival_watcher, 0, 0); ev_timer_start(mon_loop, ival_watcher); } }
/** * register timer callbacks * first execution of the callback after timeout */ ev_watcher* event_register_timer_w(EV_P_ watcher_cb_t cb, double to) { ev_timer* ev_handle = (ev_timer*) malloc(sizeof(ev_timer)); // ev_init does not case to ev_watcher, while setting callback ev_init( ev_handle, (timer_cb_t)cb); ev_timer_set(ev_handle, 0, to); ev_timer_again(EV_A_ ev_handle); return (ev_watcher*) ev_handle; }
static int gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) { CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms); evcurl_global_data *global = cglobal; ev_timer_stop(EV_DEFAULT, &global->timeev); if (tblock_ms < 0 || 14000 < tblock_ms) tblock_ms = 14000; ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0); ev_timer_start(EV_DEFAULT_UC, &global->timeev); curl_multi_perform(global, &global->nrun); return 0; }
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat) { if (ev_is_active(&timer->timer_watcher)) { return -1; } timer->timer_cb = cb; ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); ev_timer_start(timer->loop->ev, &timer->timer_watcher); ev_unref(timer->loop->ev); return 0; }
static void reset_timer() { struct timeval tvout; struct timeval *tv = ares_timeout(default_ctx.channel, NULL, &tvout); if (tv == NULL) { return; } float repeat = tv->tv_sec + tv->tv_usec / 1000000. + 1e-9; ev_timer_set(&default_ctx.tw, repeat, repeat); ev_timer_again(default_loop, &default_ctx.tw); }
int uv_timer_start(uv_handle_t* handle, uv_loop_cb cb, int64_t timeout, int64_t repeat) { if (ev_is_active(&handle->timer_watcher)) { return -1; } handle->timer_cb = cb; ev_timer_set(&handle->timer_watcher, timeout / 1000.0, repeat / 1000.0); ev_timer_start(EV_DEFAULT_UC_ &handle->timer_watcher); ev_unref(EV_DEFAULT_UC); return 0; }
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat) { if (ev_is_active(&timer->timer_watcher)) { return -1; } timer->timer_cb = cb; ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); ev_timer_start(EV_DEFAULT_UC_ &timer->timer_watcher); ev_unref(EV_DEFAULT_UC); return 0; }
/* * Wrapper for client callback we provide to udns */ static void dns_query_cb(struct dns_ctx *ctx, struct dns_rr_a4 *result, void *data) { struct ResolvQuery *cb_data = (struct ResolvQuery *)data; struct Address *address = NULL; if (result == NULL) { info("resolv: %s\n", dns_strerror(dns_status(ctx))); } else if (result->dnsa4_nrr > 0) { struct sockaddr_in sa = { .sin_family = AF_INET, .sin_port = 0, .sin_addr = result->dnsa4_addr[0], }; address = new_address_sa((struct sockaddr *)&sa, sizeof(sa)); if (address == NULL) err("Failed to allocate memory for DNS query result address"); } cb_data->client_cb(address, cb_data->client_cb_data); cb_data->client_free_cb(cb_data->client_cb_data); free(cb_data); free(result); free(address); } /* * DNS timeout callback */ static void resolv_timeout_cb(struct ev_loop *loop, struct ev_timer *w, int revents) { struct dns_ctx *ctx = (struct dns_ctx *)w->data; dns_timeouts(ctx, 30, ev_now(loop)); } /* * 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); } }
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); } }
// ///////////////////////////////////////////////////////////////////////////// // 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; }
/* * (Re-)starts the clear_indicator timeout. Called after pressing backspace or * after an unsuccessful authentication attempt. * */ void start_clear_indicator_timeout(void) { if (clear_indicator_timeout) { ev_timer_stop(main_loop, clear_indicator_timeout); ev_timer_set(clear_indicator_timeout, 1.0, 0.); ev_timer_start(main_loop, clear_indicator_timeout); } else { /* When there is no memory, we just don’t have a timeout. We cannot * exit() here, since that would effectively unlock the screen. */ if (!(clear_indicator_timeout = calloc(sizeof(struct ev_timer), 1))) return; ev_timer_init(clear_indicator_timeout, clear_indicator, 1.0, 0.); ev_timer_start(main_loop, clear_indicator_timeout); } }
/* * 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); }
ev_timer *start_timer(ev_timer *timer_obj, ev_tstamp timeout, ev_callback_t callback) { if (timer_obj) { ev_timer_stop(main_loop, timer_obj); ev_timer_set(timer_obj, timeout, 0.); ev_timer_start(main_loop, timer_obj); } else { /* When there is no memory, we just don’t have a timeout. We cannot * exit() here, since that would effectively unlock the screen. */ timer_obj = calloc(sizeof(struct ev_timer), 1); if (timer_obj) { ev_timer_init(timer_obj, callback, timeout, 0.); ev_timer_start(main_loop, timer_obj); } } return timer_obj; }
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); } }
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; }
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat) { if (uv__timer_active(timer)) { return -1; } timer->timer_cb = cb; timer->flags |= UV_TIMER_ACTIVE; if (repeat) timer->flags |= UV_TIMER_REPEAT; else timer->flags &= ~UV_TIMER_REPEAT; ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); ev_timer_start(timer->loop->ev, &timer->timer_watcher); ev_unref(timer->loop->ev); return 0; }
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat) { if (uv__is_active(timer)) uv_timer_stop(timer); timer->timer_cb = cb; if (repeat) timer->flags |= UV_TIMER_REPEAT; else timer->flags &= ~UV_TIMER_REPEAT; ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); ev_timer_start(timer->loop->ev, &timer->timer_watcher); uv__handle_start(timer); return 0; }
scheduler_impl_t::wait_result_t scheduler_impl_t::wait_timeout(duration_t* timeout) { assert(timeout); ev_timer timer_ready; watcher_data_t watcher_data(FIBER_IMPL); ev_init((ev_watcher*)&timer_ready, switch_to_cb); ev_timer_set(&timer_ready, timeout->count(), 0.0); ev_timer_start(ev_loop_, &timer_ready); timer_ready.data = &watcher_data; ev_tstamp start_wait = ev_now(ev_loop_); FIBER_IMPL->yield(); *timeout -= duration_t(ev_now(ev_loop_) - start_wait); ev_timer_stop(ev_loop_, &timer_ready); return READY; }
void *interface_thread_start(void *arg) { struct interface_config *cfg = arg; ev_timer if_stats_timer; uinet_initialize_thread(); if (cfg->stats) { ev_init(&if_stats_timer, if_stats_timer_cb); ev_timer_set(&if_stats_timer, 1.0, 2.0); if_stats_timer.data = cfg; ev_timer_start(cfg->loop, &if_stats_timer); } ev_run(cfg->loop, 0); uinet_finalize_thread(); return (NULL); }
static void accept_cb(struct ev_loop *loop, struct ev_io *w, int revents) { struct Listener *listener = (struct Listener *)w->data; if (revents & EV_READ) { int result = accept_connection(listener, loop); if (result == 0 && (errno == EMFILE || errno == ENFILE)) { char address_buf[256]; int backoff_time = 2; err("File descriptor limit reached! " "Suspending accepting new connections on %s for %d seconds", display_address(listener->address, address_buf, sizeof(address_buf)), backoff_time); ev_io_stop(loop, w); ev_timer_set(&listener->backoff_timer, backoff_time, 0.0); ev_timer_start(loop, &listener->backoff_timer); } } }
spx_private void ydb_storage_syncquery_handler(struct ev_loop *loop,\ ev_timer *w,int revents){/*{{{*/ struct spx_job_context *jc = (struct spx_job_context *) w->data; struct ydb_storage_configurtion *c = (struct ydb_storage_configurtion *) \ jc->config; struct spx_vector_iter *iter = spx_vector_iter_init(c->trackers,&(jc->err)); if(NULL == iter){ SpxLog2(jc->log,SpxLogError,jc->err,\ "init the trackers iter is fail."); return; } struct ydb_tracker *t = NULL; while(NULL != (t = spx_vector_iter_next(iter))){ ydb_storage_query_remote(c->log, t,c->groupname,c->machineid,c->syncgroup); } spx_vector_iter_free(&iter); ev_timer_set (sync_timer, (double) 30, 0.); ev_timer_again(sloop,sync_timer); }/*}}}*/
static int sleeper_sleep(lua_State *T) { struct ev_timer *w; luaL_checktype(T, 1, LUA_TUSERDATA); w = lua_touserdata(T, 1); if (w->data != NULL) { lua_pushnil(T); lua_pushliteral(T, "busy"); return 2; } if (lua_gettop(T) > 1 && !lua_isnil(T, 2)) { ev_tstamp delay = (ev_tstamp)luaL_checknumber(T, 2); if (delay <= 0) { /* return nil, "timeout" * ..but yield the thread */ lua_pushnil(T); lua_pushvalue(T, lua_upvalueindex(1)); lem_queue(T, 2); return lua_yield(T, 2); } ev_timer_set(w, delay, 0); ev_timer_start(LEM_ w); } w->data = T; /* yield sleeper, nil, "timeout" */ lua_settop(T, 1); lua_pushnil(T); lua_pushvalue(T, lua_upvalueindex(1)); return lua_yield(T, 3); }