static void plugin_write_cb(struct ev_loop* loop, ev_io* w, int revents V_UNUSED) { dmn_assert(loop); dmn_assert(w); dmn_assert(revents == EV_WRITE); while(!sendq_empty()) { const uint32_t data = sendq_deq_peek(); int rv = write(plugin_write_fd, &data, 4); if(rv != 4) { if(rv < 0) { if(errno == EAGAIN) return; // pipe full, wait for more libev notification of write-ready else if(errno == EINTR) continue; // try this write again immediately else { ev_break(loop, EVBREAK_ALL); return; } } else if(rv == 0) { ev_break(loop, EVBREAK_ALL); return; } else { log_fatal("BUG: atomic pipe write of 4 bytes was not atomic, retval was %u", rv); } } sendq_deq_commit(); } ev_io_stop(loop, w); // queue now empty }
static void plugin_write_cb(struct ev_loop* loop, ev_io* w, int revents V_UNUSED) { dmn_assert(loop); dmn_assert(w); dmn_assert(revents == EV_WRITE); dmn_assert(plugin_write_fd > -1); while(!sendq_empty()) { const uint32_t data = sendq_deq_peek(); ssize_t write_rv = write(plugin_write_fd, &data, 4); if(write_rv != 4) { if(write_rv < 0) { if(errno == EAGAIN || errno == EWOULDBLOCK) return; // pipe full, wait for more libev notification of write-ready else if(errno == EINTR) continue; // try this write again immediately else { ev_break(loop, EVBREAK_ALL); return; } } else if(write_rv == 0) { ev_break(loop, EVBREAK_ALL); return; } else { log_fatal("BUG: atomic pipe write of 4 bytes was not atomic, retval was %zi", write_rv); } } sendq_deq_commit(); } ev_io_stop(loop, w); // queue now empty if(killed_by) { // we've sent our final message, close close(plugin_write_fd); plugin_write_fd = -1; } }
static void connection_error_callback(int fd) { connection_t *conn = connections + fd; bool client = conn->client; int remote_fd = valid_remote_fd(fd) ? conn->remote_fd : REMOTE_NULL; connection_reset(conn); ev_io_stop(EV_DEFAULT_ &conn->watcher); close(fd); if (client) { if (remote_fd >= 0) { server_t *server = find_server(remote_fd); if (server && server->pid >= 0) kill(server->pid, SIGHUP); } } else { server_t *server = find_server(fd); if (server) { server->pid = -1; server->fd = -1; --server_size; if (proxy_shutdown) { if (!server_size) ev_break(EV_DEFAULT_ EVBREAK_ALL); } else { spawn_server(server); } } } }
static void timeout_cb (EV_P_ ev_timer *w, int revents) { printf("timeout\n"); printf("getpid(): %d\n",getpid()); ev_break (EV_A_ EVBREAK_ONE); }
void exit_bc_thread() { enter_func(); close(sockfd); ev_break(bc_loop, EVBREAK_ALL); }
void signal_action (struct ev_loop *loop,ev_signal *signal_w,int e) { puts("in signal cb \n"); ev_signal_stop(loop,signal_w); ev_break (loop,EVBREAK_ALL); }
static void idle_cb (EV_P_ ev_idle *w, int revents) { puts ("idle"); // this causes the innermost ev_run to stop iterating ev_break (EV_A_ EVBREAK_ONE); }
static void ev_x_loopexit_cb (int revents, void *base) { dLOOPbase; ev_break (EV_A_ EVBREAK_ONE); }
/** * Called when a message is sent to netconf->loop_async. * This is usually to signal that some internal control * flow related to the event loop needs to take place. * For example, we might need to re-enable some ev_io* watchers, * or exit the loop. */ static void handle_async_event(ev_async *watcher, int revents) { // Get the user data worker_ev_userdata *data = ev_userdata(); // Get a reference to the head, set the head to NULL async_event *event = (async_event*)data->netconf->events; data->netconf->events = NULL; async_event *next; while (event) { // Handle based on the event switch (event->event_type) { case EXIT: ev_break(EVBREAK_ALL); break; case SCHEDULE_WATCHER: ev_io_start(event->watcher); break; default: syslog(LOG_ERR, "Unknown async event type!"); break; } // Grab the next event, free this one, and repeat next = event->next; free(event); event = next; } }
static void nitro_async_handle(nitro_async_t *a) { switch (a->type) { case NITRO_ASYNC_ENABLE_WRITES: if (a->u.enable_writes.pipe) { Stcp_pipe_enable_write(a->u.enable_writes.pipe); } else { SOCKET_CALL(a->u.enable_writes.socket, enable_writes); } break; case NITRO_ASYNC_ENABLE_READS: SOCKET_CALL(a->u.bind_listen.socket, enable_reads); break; case NITRO_ASYNC_DIE: ev_break(the_runtime->the_loop, EVBREAK_ALL); break; case NITRO_ASYNC_BIND_LISTEN: SOCKET_CALL(a->u.bind_listen.socket, bind_listen); break; case NITRO_ASYNC_CONNECT: SOCKET_CALL(a->u.connect.socket, start_connect); break; case NITRO_ASYNC_CLOSE: SOCKET_CALL(a->u.close.socket, start_shutdown); break; } }
static void usb_cb (EV_P_ ev_io *w, int revents) { switch(usb_in_buf[0]) { case 'N': { if(status==READY) { http_request(REQ_SUBMIT); net_io=1; status=SUBMIT; update_display("qrcode.png",1); } break; } case 'C': { if(status==WAIT) { http_request(REQ_CANCEL); net_io=1; status=CANCEL; } else { status=READY; update_display("default.png",0); } break; } } memset(usb_in_buf,0,USB_BUF_SIZE); ev_break (EV_A_ EVBREAK_ALL); }
// another callback, this time for a time-out static void timeout_cb (EV_P_ ev_timer *w, int revents) { puts ("timeout"); // this causes the innermost ev_run to stop iterating ev_break (EV_A_ EVBREAK_ONE); }
/** * Invoked to handle async notifications via the thread pipes */ static void handle_worker_notification(ev_loop *lp, ev_io *watcher, int ready_events) { // Get the user data worker_ev_userdata *data = ev_userdata(lp); // Attempt to read a single character from the pipe char cmd; if (read(data->pipefd[0], &cmd, 1) != 1) return; // Handle the command conn_info *conn; switch (cmd) { // Accept new connection case 'a': // Read the address of conn from the pipe if (read(data->pipefd[0], &conn, sizeof(conn_info*)) < 0) { perror("Failed to read from async pipe"); return; } // Schedule this connection on this thread conn->thread_ev = data; ev_io_start(data->loop, &conn->client); break; // Quit case 'q': ev_break(lp, EVBREAK_ALL); break; default: syslog(LOG_WARNING, "Received unknown comand: %c", cmd); } }
/* callback for timeout */ static void timeout_cb(EV_P_ ev_timer *w, int revents) { puts("timeout"); /* stop innermost ev_run */ ev_break(EV_A_ EVBREAK_ONE); }
static int main_f(va_list ap) { (void) ap; fiber_cond_basic(); ev_break(loop(), EVBREAK_ALL); return 0; }
spx_private err_t spx_nio_thread_context_free(void **arg){ struct spx_nio_thread_context **context = (struct spx_nio_thread_context **) arg; ev_break((*context)->loop,EVBREAK_ALL); ev_loop_destroy((*context)->loop); SpxClose((*context)->pipe[0]); SpxClose((*context)->pipe[1]); SpxFree(*context); return 0; }
void lwqq_async_global_quit() { if(ev_thread_status == THREAD_NOW_WAITING) { ev_thread_status = THREAD_NOT_CREATED; pthread_cond_signal(&ev_thread_cond); } else if(ev_thread_status == THREAD_NOW_RUNNING) { ev_break(EV_DEFAULT,0); } }
void DataSink::Stop() { LOG(INFO) << "stopping DataSink..."; BOOST_FOREACH (WatcherMap::value_type &item, _watcherMap) _DeleteAndCleanupWatcher(*item.first); ev_break(_loop, EVBREAK_ALL); //_thread.join(); // Can take up to several seconds LOG(INFO) << "DataSink stopped"; }
F_NONNULL static void terminal_signal(struct ev_loop* loop, struct ev_signal *w, const int revents V_UNUSED) { dmn_assert(loop); dmn_assert(w); dmn_assert(revents == EV_SIGNAL); dmn_assert(w->signum == SIGTERM || w->signum == SIGINT); log_info("Received terminating signal %i, exiting", w->signum); ev_break(loop, EVBREAK_ALL); }
/** * @brief Callback called by the event loop watcher when a signal is caught. */ static void sr_pd_signal_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { CHECK_NULL_ARG_VOID2(loop, w); SR_LOG_DBG("Signal %d caught, breaking the event loop.", w->signum); ev_break(loop, EVBREAK_ALL); }
spx_private err_t spx_thread_context_free(void **arg){/*{{{*/ struct spx_thread_context **tc = (struct spx_thread_context **) arg; ev_break((*tc)->loop,EVBREAK_ALL); ev_loop_destroy((*tc)->loop); SpxClose((*tc)->pipe[0]); SpxClose((*tc)->pipe[1]); SpxFree(*tc); return 0; }/*}}}*/
static void lcb_io_stop_event_loop(struct lcb_io_opt_st *iops) { struct libev_cookie *io_cookie = iops->v.v2.cookie; #ifdef HAVE_LIBEV4 ev_break(io_cookie->loop, EVBREAK_ONE); #else ev_unloop(io_cookie->loop, EVUNLOOP_ONE); #endif }
static struct tlv_packet *core_shutdown(struct tlv_handler_ctx *ctx) { struct tlv_packet *p = tlv_packet_response_result(ctx, TLV_RESULT_SUCCESS); // We're done, allow main() to cleanup... struct mettle *m = ctx->arg; ev_break(mettle_get_loop(m), EVBREAK_ALL); return p; }
static void _prepare_cb(UNUSED EV_P_ UNUSED ev_prepare *w, UNUSED int revents) { mnbtrie_node_t *node; mrkthr_ctx_t *ctx = NULL; if (!(mrkthr_flags & CO_FLAG_SHUTDOWN)) { timecounter_now = (uint64_t)(ev_now(the_loop) * 1000000000.); #ifdef TRACE_VERBOSE CTRACE(FRED("Sifting sleepq ...")); #endif /* this will make sure there are no expired ctxes in the sleepq */ poller_sift_sleepq(); /* get the first to wake sleeping mrkthr */ if ((node = BTRIE_MIN(&the_sleepq)) != NULL) { ev_tstamp secs; ctx = node->value; assert(ctx != NULL); if (ctx->expire_ticks > timecounter_now) { secs = (ev_tstamp)(ctx->expire_ticks - timecounter_now) / 1000000000.; } else { /* * some time has elapsed after the call to * sift_sleepq() that made an event expire. */ secs = 0.00000095367431640625; } #ifdef TRACE_VERBOSE CTRACE("wait %f", secs); #endif etimer.repeat = secs; ev_timer_again(the_loop, &etimer); } else { #ifdef TRACE_VERBOSE CTRACE("no wait"); #endif //etimer.repeat = 1.00000095367431640625; //etimer.repeat = INFINITY; etimer.repeat = 59.0; /* <MAX_BLOCKTIME */ ev_timer_again(the_loop, &etimer); //ev_timer_stop(the_loop, &etimer); //ev_unref(the_loop); } } else { CTRACE("breaking the loop"); ev_break(the_loop, EVBREAK_ALL); } //CTRACE("revents=%08x", revents); }
static PyObject * Loop_stop(Loop *self, PyObject *args) { int how = EVBREAK_ONE; if (!PyArg_ParseTuple(args, "|i:stop", &how)) { return NULL; } ev_break(self->loop, how); Py_RETURN_NONE; }
/* callback for watcher */ static void stdin_cb(EV_P_ ev_io *w, int revents) { puts("stdin ready"); /* One shot event, stop the watcher */ ev_io_stop(EV_A_ w); /* stop all nested ev_runs */ ev_break(EV_A_ EVBREAK_ALL); }
// all watcher callbacks have a similar signature // this callback is called when data is readable on stdin static void stdin_cb (EV_P_ ev_io *w, int revents) { puts ("stdin ready"); // for one-shot events, one must manually stop the watcher // with its corresponding stop function. ev_io_stop (EV_A_ w); // this causes all nested ev_run's to stop iterating ev_break (EV_A_ EVBREAK_ALL); }
void list_timer_cb (struct ev_loop *loop, ev_timer *w, int revents) { static int i = 100; zlist_t *l = w->data; if (--i == 0) { ev_break (loop, EVBREAK_ALL); } else { zmsg_t *zmsg; if (!(zmsg = zmsg_new ()) || zlist_append (l, zmsg) < 0) oom (); } }
void Loop::quit() { _quit = true; if (nullptr != _loop) { if (std::this_thread::get_id() == _owner) { ev_break(_loop); } else { SLOG(INFO) << "quit async!"; ev_async_send(_loop, &_async); } } }
static void shutdown_cb(struct ev_loop *loop, ev_signal *w, int revents) { (void) revents; fprintf(stderr, "Caught signal, shutting down bar...\n"); Bar *bar = (Bar *)w->data; ev_unloop(loop, EVUNLOOP_ALL); ev_break(loop, EVBREAK_ALL); // Consider putting this in the cleanup watcher. //close(0); // close stdin. bar_free(bar); }