/* * something to read from stdin * read one char at a time, even if this is not efficient. */ static void on_stdin( struct ev_loop *loop, struct ev_io *w, int revents ) { static char pipecmd[128] = {0}; char c; int r; r = read( 0, &c, 1 ); if (r < 0) { /* read failed on stdin. time to exit */ ev_unloop( loop, EVUNLOOP_ALL); return; } if (c != '\n') { /* queue into cmdpipe */ int l = strlen(pipecmd); if (l < sizeof(pipecmd)-2) { pipecmd[l] = c; pipecmd[l+1] = '\0'; } } else { /* execute the command */ dbg("pipecmd: '%s'", pipecmd); if (!strcmp(pipecmd, "q")) { warn("quit"); ev_unloop( loop, EVUNLOOP_ALL); return; } /* reset the pipecmd */ pipecmd[0] = '\0'; } }
//---------------------------------------------------------------------------- void dir_watcher_t::exit_ev_loop() { if( p_loop_) { ev_unloop(p_loop_, EVUNLOOP_ONE); } }
// all watcher callbacks have a similar signature // this callback is called when data is readable on stdin static void stdin_cb (EV_P_ struct ev_io *w, int revents) { // Read a line char *line = 0; unsigned int len = 0; getline(&line, &len, stdin); char cmd[64] = {0}; // this will crash if you enter bad strings in stdin! sscanf(line, " %s ", cmd); // Main interactive command dispatch if (!strcmp(cmd, "ping")) { printf("you said ping\n"); } else if (!strcmp(cmd, "help")) { printf("Commands: [cmd] [argument] ... \n"); printf(" help : shows this message\n"); printf(" quit : quits\n"); printf(" version : sends version message client\n"); printf(" ping : sends ping message to connected client\n"); printf("\n"); } else if (!strcmp(cmd, "version")) { printf("sending version\n"); send_version(); } else if (!strcmp(cmd, "quit")) { printf("Quitting...\n"); ev_unloop(EV_A_ EVUNLOOP_ALL); } else if (!strcmp(cmd, "")) { } else { printf("command not recognized: '%s'\n", cmd); } }
static void ev_x_loopexit_cb (int revents, void *base) { dLOOPbase; ev_unloop (EV_A_ EVUNLOOP_ONE); }
/** * @brief Send the disconnection signal to a single client * * @param element The RTSP_Client object from @ref feng::clients * @brief user_data unused */ static void client_disconnect(gpointer element, ATTR_UNUSED gpointer user_data) { RTSP_Client *client = (RTSP_Client*)element; ev_unloop(client->loop, EVUNLOOP_ONE); }
static void ev_signal_on_sigint(struct ev_loop* mainloop, ev_signal* watcher, const int events) { /* Clean up and shut down this thread. * (Shuts down the Python interpreter if this is the main thread) */ ev_unloop(mainloop, EVUNLOOP_ALL); PyErr_SetInterrupt(); }
static void sigint_cb(struct ev_loop *loop, ev_signal *w, int revents) { struct emc_server_context *ctx = w->data; log_printf(DEBUG_LEVEL_INFO, "INFO termination signal caught, exiting"); ctx->continue_processing = 0; ev_unloop (loop, EVUNLOOP_ALL); }
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 }
/** * signal SIGHUP callback */ static void sighup_cb (struct ev_loop *loop, struct ev_signal *w, int revents) { stats.cmd_count = 0; stats.get = 0; stats.set = 0; stats.del = 0; stats.miss = 0; stats.err = 0; time(&stats.uptime); is_finish = 1; if (!max_clients) ev_unloop (loop, EVUNLOOP_ALL); if (!stats.connections) ev_unloop (loop, EVUNLOOP_ONE); is_finish = 0; sophiadb_t* ctx = ev_userdata(EV_A); free_config(); if (confilename) parse(confilename, &server_ctx); else parse("config.ini", &server_ctx); // ctx->types = malloc((server_ctx.max_num+1) * sizeof(int)); // ctx->types[0] = server_ctx.max_num; datatype_t * p = (datatype_t *)server_ctx.list_datatypes; // printf("max banks=%d\n", ctx->conf->max_num); while(p) { // ctx->types[p->number] = p->datalen; printf("%s:%d %d:%d [%s] \n", __FUNCTION__,__LINE__, p->number,p->type, p->comment); p = p->next; } ev_loop(loop,0); }
static void signal_cb(EV_P_ ev_signal *w, int revents) { if (revents & EV_SIGNAL) { switch (w->signum) { case SIGINT: case SIGTERM: ev_unloop(EV_A_ EVUNLOOP_ALL); } } }
/*---------------------------Idle------------------------*/ static void Idle (struct ev_loop *loop, ev_idle *w, int revents) { if (SHUTDOWN) { LogDebug("Idle processing (SHUTDOWN=%d)", SHUTDOWN); ev_idle_stop(loop, w); ev_unloop (loop, EVUNLOOP_ALL); } else { ev_tstamp yieldtime = 0.10; ev_sleep(yieldtime); } }
static void on_exit_signal(struct ev_loop *loop, ev_signal *w, int revents) { switch (w->signum) { case SIGTERM: dbg("SIGTERM"); break; case SIGINT: dbg("SIGINT"); break; } ev_unloop(loop, EVUNLOOP_ALL); }
static void vcmd_cmddonecb(int32_t cmdid, pid_t pid, int status, void *data) { vcmd_t *vcmd = data; if (vcmd->cmdio->iotype == VCMD_IO_PTY) { ev_io_stop(vcmd->client->loop, &vcmd->stdin_watcher); ev_io_stop(vcmd->client->loop, &vcmd->ptymaster_watcher); /* drain command output */ for (;;) { char buf[BUFSIZ]; ssize_t rcount, wcount; rcount = read(vcmd->ptymaster_watcher.fd, buf, sizeof(buf)); if (rcount <= 0) break; wcount = write(STDOUT_FILENO, buf, rcount); if (wcount != rcount) WARN("write() error: %d of %d bytes", wcount, rcount); } } vnode_close_clientcmdio(vcmd->cmdio); #ifdef DEBUG WARNX("cmdid %u; pid %d; status: 0x%x", cmdid, pid, status); #endif if (WIFEXITED(status)) /* normal terminataion */ vcmd->cmdstatus = WEXITSTATUS(status); else if (WIFSIGNALED(status)) { if (verbose) INFO("command %u terminated by signal: %d", cmdid, WTERMSIG(status)); vcmd->cmdstatus = 255; } else { INFO("unexpected termination status for command %u: 0x%x", cmdid, status); vcmd->cmdstatus = 255; } vcmd->cmdid = -1; ev_unloop(vcmd->client->loop, EVUNLOOP_ALL); return; }
/** * signal SIGINT callback */ static void sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents) { // printf("recv signal SIGINT cnn=%d\n", stats.connections); is_finish = 1; if (!stats.connections) { // printf("cnn = 0\n"); ev_unloop (loop, EVUNLOOP_ALL); return; } }
/* * We watch various signals, that are there to make our application stop. * If we get one of those, we ev_unloop() and invoke the cleanup-routines * in main() with that * */ void sig_cb(struct ev_loop *loop, ev_signal *watcher, int revents) { switch (watcher->signum) { case SIGTERM: DLOG("Got a SIGTERM, stopping\n"); break; case SIGINT: DLOG("Got a SIGINT, stopping\n"); break; case SIGHUP: DLOG("Got a SIGHUP, stopping\n"); } ev_unloop(main_loop, EVUNLOOP_ALL); }
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); }
static void as_ev_close_loop(as_event_loop* event_loop) { ev_async_stop(event_loop->loop, &event_loop->wakeup); // Only stop event loop if client created event loop. if (as_event_threads_created) { ev_unloop(event_loop->loop, EVUNLOOP_ALL); } // Cleanup event loop resources. as_queue_destroy(&event_loop->queue); as_queue_destroy(&event_loop->pipe_cb_queue); }
static void signal_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { if (revents & EV_SIGNAL) { switch (w->signum) { case SIGHUP: reload_config(config, loop); break; case SIGUSR1: print_connections(); break; case SIGINT: case SIGTERM: ev_unloop(loop, EVUNLOOP_ALL); } } }
void delete_cb(bsc *client, struct bsc_delete_info *info) { evbsc *evclient = (evbsc *)client; fail_if( info->response.code != BSC_DELETE_RES_DELETED, "bsp_delete: response.code != BSC_DELETE_RES_DELETED"); if (info->user_data) { exp_data = (char *)"bababuba12341234"; bsc_error = bsc_put(client, put_cb, client, 1, 0, 10, strlen(exp_data), exp_data, false); fail_if(bsc_error != BSC_ERROR_NONE, "bsc_put failed (%d)", bsc_error); bsc_error = bsc_reserve(client, reserve_cb, NULL, -1); fail_if(bsc_error != BSC_ERROR_NONE, "bsc_reserve failed (%d)", bsc_error); } else ev_unloop(evclient->loop, EVUNLOOP_ONE); }
void rtsp_tcp_read_cb(struct ev_loop *loop, ev_io *w, ATTR_UNUSED int revents) { guint8 buffer[RTSP_BUFFERSIZE + 1] = { 0, }; /* +1 to control the final '\0' */ int read_size; RTSP_Client *rtsp = w->data; int sd = rtsp->sd; /* if we're receiving data for an HTTP tunnel, we have to run it through the HTTP client's buffer. */ if ( rtsp->pair != NULL ) rtsp = rtsp->pair->http_client; if ( (read_size = recv(sd, buffer, sizeof(buffer), 0) ) <= 0 ) goto client_close; stats_account_read(rtsp, read_size); if (rtsp->input->len + read_size > RTSP_BUFFERSIZE) { xlog(LOG_DBG, "RTSP buffer overflow (input RTSP message is most likely invalid).\n"); goto server_close; } g_byte_array_append(rtsp->input, (guint8*)buffer, read_size); xlog(LOG_DBG, "rtsp request probe is %d. localhost:%s remote:%s", rtsp->pending_request, rtsp->local_host, rtsp->remote_host); RTSP_handler(rtsp); return; client_close: xlog(LOG_INF, "RTSP connection closed by client."); goto disconnect; server_close: xlog(LOG_INF, "RTSP connection closed by server."); goto disconnect; disconnect: ev_unloop(loop, EVUNLOOP_ONE); }
static void spawn(child* c) { pid_t pid; if (c->tries++ > opts.retry) { g_printerr("Child[%i] died to often, not forking again\n", c->id); return; } switch (pid = fork()) { case -1: g_printerr("Fatal Error: Couldn't fork child[%i]: %s\n", c->id, g_strerror(errno)); if (0 == c->d->running) { g_printerr("No child running and fork failed -> exit\n"); c->d->return_status = -100; ev_unloop(c->d->loop, EVUNLOOP_ALL); } /* Do not retry... */ break; case 0: /* child */ /* Need to reset the signal mask; signal actions don't need to be reset * according to libev documentation: * http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#The_special_problem_of_inheritance_o */ { sigset_t set; sigemptyset(&set); sigprocmask(SIG_SETMASK, &set, NULL); } execv(opts.app[0], opts.app); g_printerr("Exec failed: %s\n", g_strerror(errno)); exit(errno); break; default: c->pid = pid; c->d->running++; c->last_spawn = ev_now(c->d->loop); ev_child_set(&c->watcher, c->pid, 0); ev_child_start(c->d->loop, &c->watcher); break; } }
static void sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents) { LOG_DEBUG("caught SIGINT!\n"); supervisor_thread_t *thiz = get_supervisor_thread(); if(thiz) { int kill_pill = -1; size_t len = sizeof(kill_pill); ev_io_stop(thiz->event_loop, &thiz->udp_read_watcher); int th = 0; for(th = 0; th < thiz->config->num_workers; th++) { if (write(thiz->worker_threads[th]->ext_fd, &kill_pill, len) != len) { LOG_ERROR("Fail to writing to connection notify pipe\n"); } pthread_join(thiz->worker_threads[th]->thread, NULL); LOG_DEBUG("{%s} JOINED\n", get_thread_string()); } //ev_unloop(supervisor_thread->event_loop, EVUNLOOP_ONE); ev_unloop(thiz->event_loop, EVUNLOOP_ALL); } }
/** Cleanup and destroy the Server */ static inline void cleanup(wr_svr_t *server) { LOG_FUNCTION // Delete 'webroar.sock' file remove(WR_TMP_SOCK_FILE); // Stop event loop ev_unloop(server->ebb_svr.loop, EVUNLOOP_ALL); // Destroy the Server structure wr_svr_free(server); // Delete 'webroar.pid' file remove(WR_PID_FILE); LOG_INFO("Shutting down network server. No more request can be served"); // Destroy logger object close_logger(); }
static void signal_cb(EV_P_ ev_signal *w, int revents) { if (revents & EV_SIGNAL) { switch (w->signum) { case SIGCHLD: if (!is_plugin_running()) LOGE("plugin service exit unexpectedly"); else return; case SIGINT: case SIGTERM: ev_signal_stop(EV_DEFAULT, &sigint_watcher); ev_signal_stop(EV_DEFAULT, &sigterm_watcher); ev_signal_stop(EV_DEFAULT, &sigchld_watcher); keep_resolving = 0; ev_unloop(EV_A_ EVUNLOOP_ALL); } } }
static void check_if_any_rtp_session_timedout(gpointer element, ATTR_UNUSED gpointer user_data) { RTP_session *session = (RTP_session *)element; time_t now = time(NULL); /* Check if we didn't send any data for more then STREAM_BYE_TIMEOUT seconds * this will happen if we are not receiving any more from live producer or * if the stored stream ended. */ if ((session->track->parent->source == LIVE_SOURCE) && (now - session->last_packet_send_time) >= LIVE_STREAM_BYE_TIMEOUT) { fnc_log(FNC_LOG_INFO, "[client] Soft stream timeout"); rtcp_send_sr(session, BYE); } /* If we were not able to serve any packet and the client ignored our BYE * kick it by closing everything */ if ((now - session->last_packet_send_time) >= STREAM_TIMEOUT) { fnc_log(FNC_LOG_INFO, "[client] Stream Timeout, client kicked off!"); ev_unloop(session->client->loop, EVUNLOOP_ONE); } }
static void sigint_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { (void) w; (void) revents; ev_unloop(loop, EVUNLOOP_ALL); }
static void sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents) { printf("sigint received, exiting.\n"); ev_unloop (loop, EVUNLOOP_ALL); }
/** * Handler to cleanly shut down feng */ static void sigint_cb (struct ev_loop *loop, ATTR_UNUSED ev_signal * w, ATTR_UNUSED int revents) { ev_unloop (loop, EVUNLOOP_ALL); }
/** Quit awesome. * \param L The Lua VM state. * \return The number of elements pushed on stack. */ static int luaA_quit(lua_State *L) { ev_unloop(globalconf.loop, 1); return 0; }
void reserve_cb(bsc *client, struct bsc_reserve_info *info) { printf("%s\n", "got reserve cb"); ev_unloop(EVBSCIFY(client)->loop, EVUNLOOP_ONE); }