IoObject *IoEventManager_setListenTimeout(IoEventManager *self, IoObject *locals, IoMessage *m) { double timeout = IoMessage_locals_doubleArgAt_(m, locals, 0); struct timeval tv = timevalFromDouble(timeout); event_loopexit(&tv); return self; }
static void http_chunked_request_done(struct evhttp_request *req, void *arg) { if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Transfer-Encoding") == NULL) { fprintf(stderr, "FAILED\n"); exit(1); } if (EVBUFFER_LENGTH(req->input_buffer) != 13 + 18 + 8) { fprintf(stderr, "FAILED\n"); exit(1); } if (strncmp((char *)EVBUFFER_DATA(req->input_buffer), "This is funnybut not hilarious.bwv 1052", 13 + 18 + 8)) { fprintf(stderr, "FAILED\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
static void http_readcb(struct bufferevent *bev, void *arg) { const char *what = "This is funny"; event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(bev->input))); if (evbuffer_find(bev->input, (const unsigned char*) what, strlen(what)) != NULL) { struct evhttp_request *req = evhttp_request_new(NULL, NULL); enum message_read_status done; req->kind = EVHTTP_RESPONSE; done = evhttp_parse_firstline(req, bev->input); if (done != ALL_DATA_READ) goto out; done = evhttp_parse_headers(req, bev->input); if (done != ALL_DATA_READ) goto out; if (done == 1 && evhttp_find_header(req->input_headers, "Content-Type") != NULL) test_ok++; out: evhttp_request_free(req); bufferevent_disable(bev, EV_READ); if (base) event_base_loopexit(base, NULL); else event_loopexit(NULL); } }
void part_cb_done(struct dht_rpc * rpc, struct dht_group_msg_reply *reply, void * arg) { static int count; struct dht_group *group = arg; char *channel_name; unsigned int error_code; char *error_reason; CU_ASSERT(reply != NULL); EVTAG_GET(reply, channel_name, &channel_name); EVTAG_GET(reply, error_code, &error_code); EVTAG_GET(reply, error_reason, &error_reason); fprintf(stderr, "%s: channel: %s -> %d - %s\n", dht_node_id_ascii(dht_myid(group->dht)), channel_name, error_code, error_reason); if (++count == 2) { struct timeval tv; /* We have just two parts - so quit shortly after they * are done */ timerclear(&tv); tv.tv_sec = 5; /* exit the loop after 5 second */ event_loopexit(&tv); } }
void http_request_empty_done(struct evhttp_request *req, void *arg) { if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Date") == NULL) { fprintf(stderr, "FAILED\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Content-Length") == NULL) { fprintf(stderr, "FAILED\n"); exit(1); } if (strcmp(evhttp_find_header(req->input_headers, "Content-Length"), "0")) { fprintf(stderr, "FAILED\n"); exit(1); } if (EVBUFFER_LENGTH(req->input_buffer) != 0) { fprintf(stderr, "FAILED\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
void http_postrequest_done(struct evhttp_request *req, void *arg) { const char *what = "This is funny"; if (req == NULL) { fprintf(stderr, "FAILED (timeout)\n"); exit(1); } if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED (response code)\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Content-Type") == NULL) { fprintf(stderr, "FAILED (content type)\n"); exit(1); } if (EVBUFFER_LENGTH(req->input_buffer) != strlen(what)) { fprintf(stderr, "FAILED (length %zu vs %zu)\n", EVBUFFER_LENGTH(req->input_buffer), strlen(what)); exit(1); } if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) { fprintf(stderr, "FAILED (data)\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
static void packet_timer_cb(int fd, short reason, void *userdata) { int i; uint8_t packet[188]; struct context *context = userdata; evtimer_add(&context->ev, &context->tv); for (i = 0; i < BATCH_SIZE; i++) { /* read a packet */ if (fread(packet, 188, 1, stdin) != 1) { event_del(&context->ev); event_loopexit(NULL); break; } /* check sync byte */ if (packet[0] == 0x47) { tssp_push_packet(context->parser, packet); #if 0 if (context->n && context->n % 10000 == 0) printf("sent %d packets\n", context->n); #endif } else { printf("invalid sync byte\n"); } context->n++; } }
static void pop3e_imsgev(struct imsgev *iev, int code, struct imsg *imsg) { switch (code) { case IMSGEV_IMSG: switch (imsg->hdr.type) { case IMSG_AUTH: authenticate(iev, imsg); break; default: logit(LOG_DEBUG, "%s: unexpected imsg %u", __func__, imsg->hdr.type); break; } break; case IMSGEV_EREAD: case IMSGEV_EWRITE: case IMSGEV_EIMSG: fatal("pop3d: imsgev read/write error"); break; case IMSGEV_DONE: event_loopexit(NULL); break; } }
static void dns_server_gethostbyname_cb(int result, char type, int count, int ttl, void *addresses, void *arg) { if (result != DNS_ERR_NONE) { fprintf(stdout, "Unexpected result %d. ", result); dns_ok = 0; goto out; } if (count != 1) { fprintf(stdout, "Unexpected answer count %d. ", count); dns_ok = 0; goto out; } switch (type) { case DNS_IPv4_A: { struct in_addr *in_addrs = addresses; if (in_addrs[0].s_addr != htonl(0xc0a80b0bUL) || ttl != 12345) { fprintf(stdout, "Bad IPv4 response \"%s\" %d. ", inet_ntoa(in_addrs[0]), ttl); dns_ok = 0; goto out; } break; } case DNS_IPv6_AAAA: { #if defined (HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN) struct in6_addr *in6_addrs = addresses; char buf[INET6_ADDRSTRLEN+1]; if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16) || ttl != 123) { const char *b = inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf)); fprintf(stdout, "Bad IPv6 response \"%s\" %d. ", b, ttl); dns_ok = 0; goto out; } #endif break; } case DNS_PTR: { char **addrs = addresses; if (strcmp(addrs[0], "ZZ.EXAMPLE.COM") || ttl != 54321) { fprintf(stdout, "Bad PTR response \"%s\" %d. ", addrs[0], ttl); dns_ok = 0; goto out; } break; } default: fprintf(stdout, "Bad response type %d. ", type); dns_ok = 0; } out: if (++n_server_responses == 3) { event_loopexit(NULL); } }
void do_command(char c) { switch (c) { case '.': case '\004': /* ^D */ event_loopexit(NULL); break; case '\032': /* ^Z */ restore_termios(); kill(getpid(), SIGTSTP); set_termios(); break; case 'C': connect_command(); break; case 'D': ioctl(line_fd, TIOCCDTR, NULL); sleep(1); ioctl(line_fd, TIOCSDTR, NULL); break; case 'R': start_record(); break; case 'S': set_speed(); break; case 'X': send_xmodem(); break; case '$': pipe_command(); break; case '>': send_file(); break; case '#': ioctl(line_fd, TIOCSBRK, NULL); sleep(1); ioctl(line_fd, TIOCCBRK, NULL); break; case '~': bufferevent_write(line_ev, "~", 1); break; case '?': printf("\r\n" "~# send break\r\n" "~$ pipe local command to remote host\r\n" "~> send file to remote host\r\n" "~C connect program to remote host\r\n" "~D de-assert DTR line briefly\r\n" "~R start recording to file\r\n" "~S set speed\r\n" "~X send file with XMODEM\r\n" "~? get this summary\r\n" ); break; } }
static void rspamd_http_server_term (int fd, short what, void *arg) { pid_t *sfd = arg; rspamd_http_stop_servers (sfd); event_loopexit (NULL); }
void rrdtool_test_done(char *something, void *arg) { struct timeval tv; timerclear(&tv); tv.tv_sec = 1; event_loopexit(&tv); }
void signal_cb(int fd, short event, void *arg) { /*struct event *signal = arg; printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));*/ struct timeval tv = {0,0}; event_loopexit(&tv); }
static void rpc_rpc_grneral_requestuest_cb(struct evhttp_request *req, void *arg) { if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED (response code)\n"); exit(1); } event_loopexit(NULL); }
static void stat_cb(struct evrpc_status *status, struct stat_request *request , struct stat_response * response , void *arg) { struct mds_req_ctx * ctx = (struct mds_req_ctx *) arg; struct file_stat *o_stat = file_stat_new(); struct file_stat *stat; EVTAG_ARRAY_GET(response, stat_arr, 0, &stat); file_stat_copy(o_stat, stat); if (ctx->cb(ctx, o_stat) == 0) event_loopexit(NULL); }
void BeatBoard::IRCConnection::bb_event_finish(){ if(ev_base != NULL){ struct timeval time; time.tv_sec = 0; time.tv_usec = 0; event_base_loopexit (ev_base,&time); event_loopexit(&time); } }
static void sig_handler(int sig, short event, void *arg) { switch (sig) { case SIGINT: case SIGTERM: event_loopexit(NULL); } }
static void http_failure_readcb(struct bufferevent *bev, void *arg) { const char *what = "400 Bad Request"; if (evbuffer_find(bev->input, (const unsigned char*) what, strlen(what)) != NULL) { test_ok = 2; bufferevent_disable(bev, EV_READ); event_loopexit(NULL); } }
void sighandler(int sig, short event, void *arg) { switch (sig) { case SIGTERM: case SIGINT: (void)event_loopexit(NULL); terminate_handler(); } }
/* * Trigger the exit of the program. This will happen once control is returned * to the event handler. Main program catches the exitcode and prints the last * status message (if not already set) */ void chopstix_exit(void) { exitcode = 1; /* this can fail in out-of-memory conditions, oh well */ exitmsg = strdup(status.status); event_loopexit(NULL); }
static gboolean session_fin (gpointer unused) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; event_loopexit (&tv); return TRUE; }
static void http_request_bad(struct evhttp_request *req, void *arg) { if (req != NULL) { fprintf(stderr, "FAILED\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
static void sig_handler(int sig, short event, void *arg) { int status; switch (sig) { case SIGINT: case SIGHUP: case SIGTERM: imsgev_clear(&iev_pop3e); event_loopexit(NULL); break; case SIGCHLD: if (waitpid(WAIT_ANY, &status, WNOHANG) > 0) if ((WIFEXITED(status) && WEXITSTATUS(status) != 0) || WIFSIGNALED(status)) { logit(LOG_ERR, "Lost pop3 engine"); event_loopexit(NULL); } break; } }
static void shutdown_master(void) { struct timeval tv; struct scan_peer *peer; event_del(&listen_event); (void)close(listen_event_socket); LIST_FOREACH(peer, &inactive_peers, peer_link) (void)shutdown(peer->fd, SHUT_RDWR); tv.tv_sec = 1; tv.tv_usec = 0; event_loopexit(&tv); }
static void dns_callback(int result, char type, int count, int ttl, void *addresses, void *arg) { Url * ourl = (Url *)arg; struct in_addr *addrs = (in_addr *)addresses; if (result != DNS_ERR_NONE || count == 0) { SPIDER_LOG(SPIDER_LEVEL_WARN, "Dns resolve fail: %s", ourl->domain); } else { char * ip = inet_ntoa(addrs[0]); SPIDER_LOG(SPIDER_LEVEL_DEBUG, "Dns resolve OK: %s -> %s", ourl->domain, ip); host_ip_map[ourl->domain] = strdup(ip); ourl->ip = strdup(ip); push_ourlqueue(ourl); } event_loopexit(NULL); // not safe for multithreads }
void signal_handler(int sig) { deprintf("Received signal: %d\n", sig); switch (sig) { case SIGTERM: case SIGHUP: case SIGINT: event_loopexit(NULL); break; case SIGPIPE: deprintf("Received SIGPIPE\n"); break; default: syslog(LOG_WARNING, "Uhandled signal %d", sig); break; } }
void evt_server_stop() { if (event_loopexit(&min_time) != 0) { event_loopbreak(); } if (pool.nr > 0) { int i; for (i = 0; i < pool.nr; ++i) { cq_push_back(&pool.conns[i], -1, 0, NULL); while (pool.conns[i].size > 1) { usleep(THREAD_POLL_TIME); } } free(pool.conns); } freeaddrinfo(serv.ai); }
static void close_detect_done(struct evhttp_request *req, void *arg) { struct timeval tv; if (req == NULL || req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); exit(1); } test_ok = 1; timerclear(&tv); tv.tv_sec = 3; /* longer than the http time out */ event_loopexit(&tv); }
static void session_imsgev(struct imsgev *iev, int code, struct imsg *imsg) { struct m_backend *mb = iev->data; switch (code) { case IMSGEV_IMSG: switch (imsg->hdr.type) { case IMSG_MAILDROP_INIT: maildrop_init(iev, imsg, mb); break; case IMSG_MAILDROP_UPDATE: update(iev, imsg, mb); break; case IMSG_MAILDROP_RETR: retr(iev, imsg, mb); break; case IMSG_MAILDROP_DELE: dele(iev, imsg, mb); break; case IMSG_MAILDROP_RSET: rset(iev, imsg, mb); break; case IMSG_MAILDROP_LIST: list(iev, imsg, mb); break; case IMSG_MAILDROP_LISTALL: list_all(iev, imsg, mb); break; default: logit(LOG_DEBUG, "%s: unexpected imsg %u", __func__, imsg->hdr.type); break; } break; case IMSGEV_EREAD: case IMSGEV_EWRITE: case IMSGEV_EIMSG: fatal("maildrop: imsgev read/write error"); break; case IMSGEV_DONE: event_loopexit(NULL); break; } }
/** Handles service control requests, such as stopping or starting the * Tor service. */ static void nt_service_control(DWORD request) { static struct timeval exit_now; exit_now.tv_sec = 0; exit_now.tv_usec = 0; nt_service_loadlibrary(); switch (request) { case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: log_notice(LD_GENERAL,get_lang_str(LANG_LOG_NTMAIN_SHUTDOWN)); service_status.dwCurrentState = SERVICE_STOP_PENDING; event_loopexit(&exit_now); return; } service_fns.SetServiceStatus_fn(hStatus, &service_status); }