static int poll_setup(struct re *re) { int err; err = fd_setsize(DEFAULT_MAXFDS); if (err) goto out; if (METHOD_NULL == re->method) { err = poll_method_set(poll_method_best()); if (err) goto out; DEBUG_INFO("poll setup: poll method not set - set to `%s'\n", poll_method_name(re->method)); } err = poll_init(re); out: if (err) poll_close(re); return err; }
int main(int argc,char **argv) { pthread_t zputhread; pthread_attr_t zputhreadattr; void *ret; if (argc<2) { return help(); } poll_init(); gui_init(); zpuino_interface_init(); if (load_device_map("device.map")<0) { fprintf(stderr,"SIMULATOR: Error loading device map\n"); return -1; } int infile = open(argv[1],O_RDONLY); read(infile,_memory,32768); close(infile); zpuino_io_post_init(); gui_post_init(); // Spawn terminal /* int pid; switch(pid=vfork()) { case 0: return execl("./terminal/terminal","terminal",uart_get_slave_name(),NULL); default: break; } */ /* if (setup_programmer_port()<0) return -1; */ signal(SIGINT,&sign); _usp=get_initial_stack_location(); zpuino_clock_start(); // start processing thread pthread_attr_init(&zputhreadattr); pthread_create(&zputhread,&zputhreadattr, zpu_thread, NULL); zpu_halt(); poll_loop(); pthread_join(zputhread,&ret); return 0; }
struct libwebrtc_context* libwebrtc_create_context(lwrtc_callback_function callback) { assert( callback != NULL ); libwebrtc_context* ctx = new libwebrtc_context(); ctx->chain = poll_init(); ctx->factory = ILibWrapper_WebRTC_ConnectionFactory_CreateConnectionFactory(ctx->chain, 0); ctx->callback = callback; return ctx; }
/** * Set async I/O polling method. This function can also be called while the * program is running. * * @param method New polling method * * @return 0 if success, otherwise errorcode */ int poll_method_set(enum poll_method method) { struct re *re = re_get(); int err; err = fd_setsize(DEFAULT_MAXFDS); if (err) return err; switch (method) { #ifdef HAVE_POLL case METHOD_POLL: break; #endif #ifdef HAVE_SELECT case METHOD_SELECT: if (re->maxfds > (int)FD_SETSIZE) { DEBUG_WARNING("SELECT: maxfds > FD_SETSIZE\n"); return EMFILE; } break; #endif #ifdef HAVE_EPOLL case METHOD_EPOLL: if (!epoll_check()) return EINVAL; break; #endif #ifdef HAVE_ACTSCHED case METHOD_ACTSCHED: break; #endif #ifdef HAVE_KQUEUE case METHOD_KQUEUE: break; #endif default: DEBUG_WARNING("poll method not supported: '%s'\n", poll_method_name(method)); return EINVAL; } re->method = method; re->update = true; DEBUG_INFO("Setting async I/O polling method to `%s'\n", poll_method_name(re->method)); err = poll_init(re); if (err) return err; return rebuild_fds(re); }
static int test1() { DCB *dcb; int result; int eno = 0; /* Poll tests */ ss_dfprintf(stderr, "testpoll : Initialise the polling system."); init_test_env(NULL); poll_init(); ss_dfprintf(stderr, "\t..done\nAdd a DCB"); dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER); if(dcb == NULL){ ss_dfprintf(stderr, "\nError on function call: dcb_alloc() returned NULL.\n"); return 1; } dcb->fd = socket(AF_UNIX, SOCK_STREAM, 0); if(dcb->fd < 0){ char errbuf[STRERROR_BUFLEN]; ss_dfprintf(stderr, "\nError on function call: socket() returned %d: %s\n",errno,strerror_r(errno,errbuf,sizeof(errbuf))); return 1; } if((eno = poll_add_dcb(dcb)) != 0){ ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno); return 1; } if((eno = poll_remove_dcb(dcb)) != 0){ ss_dfprintf(stderr, "\nError on function call: poll_remove_dcb() returned %d.\n",eno); return 1; } if((eno = poll_add_dcb(dcb)) != 0){ ss_dfprintf(stderr, "\nError on function call: poll_add_dcb() returned %d.\n",eno); return 1; } ss_dfprintf(stderr, "\t..done\nStart wait for events."); sleep(10); poll_shutdown(); ss_dfprintf(stderr, "\t..done\nTidy up."); dcb_close(dcb); ss_dfprintf(stderr, "\t..done\n"); return 0; }
int main(void) { int rc = poll_init(); if ( rc ) { return 1; } for (;;) { rc = poll_select(); if ( rc ) { return 2; } } return 0; }
int main(int argc, const char *argv[]) { if(signal(SIGPIPE, SIG_IGN) == SIG_ERR) ERR_EXIT("signal"); int listenfd = make_socket(); printf("listen %d\n",listenfd); poll_t pol; poll_init(&pol, listenfd, handle); while(1) { poll_do_wait(&pol); poll_handle_accept(&pol); poll_handle_data(&pol); } close(listenfd); return 0; }
int main (int argc, char**argv) { int ret = 0; int heartbeat_usec = 50000; //20Hz is ok by default uint64_t last_beat = 0; Log_info ("cloudvpn starting"); Log (0, "You are using CloudVPN, which is Free software."); Log (0, "For more information please see the GNU GPL license,"); Log (0, "which you should have received along with this program."); setup_sighandler (kill_cloudvpn); /* * initialization */ if (!config_parse (argc, argv) ) { Log_error ("failed to parse config, terminating."); ret = 1; goto failed_config; } if (!config_get_int ("heartbeat", heartbeat_usec) ) heartbeat_usec = 50000; Log_info ("heartbeat is set to %d usec", heartbeat_usec); timestamp_update(); //get initial timestamp status_init(); route_init(); squeue_init(); network_init(); if (poll_init() ) { Log_fatal ("poll initialization failed"); ret = 2; goto failed_poll; } if (do_memlock() ) { Log_fatal ("locking process to memory failed"); ret = 3; goto failed_poll; } if (comm_load() ) { Log_fatal ("failed to load comm data"); ret = 4; goto failed_poll; } if (comm_init() ) { Log_fatal ("communication initialization failed"); ret = 5; goto failed_comm; } if (gate_init() ) { Log_fatal ("gate initialization failed"); ret = 6; goto failed_gate; } if (do_chroot() ) { Log_fatal ("chrooting failed"); ret = 7; goto failed_sec; } if (do_switch_user() ) { Log_fatal ("user switch failed"); ret = 8; goto failed_sec; } /* * main loop */ Log_info ("initialization complete, entering main loop"); last_beat = 0; //update immediately. while (!g_terminate) { timestamp_update(); if ( (timestamp() - last_beat) < (unsigned int) heartbeat_usec) { //poll more stuff poll_wait_for_event (heartbeat_usec - timestamp() + last_beat); //send the results comm_flush_data(); gate_flush_data(); continue; } last_beat = timestamp(); gate_periodic_update(); comm_periodic_update(); route_periodic_update(); status_try_export(); } /* * deinitialization */ Log_info ("shutting down"); failed_sec: gate_shutdown(); failed_gate: comm_shutdown(); failed_comm: if (poll_deinit() ) Log_warn ("poll_deinit somehow failed!"); failed_poll: failed_config: if (!ret) Log_info ("cloudvpn exiting gracefully"); else Log_error ("cloudvpn exiting with code %d", ret); return ret; }
int main(int argc, char **argv) { int ch, longindex, nr; int is_daemon = 1, is_debug = 1; pid_t pid; struct pollfd *poll_array; while ((ch = getopt_long(argc, argv, "fd:vh", long_options, &longindex)) >= 0) { switch (ch) { case 'f': is_daemon = 0; break; case 'd': is_debug = atoi(optarg); break; case 'v': exit(0); break; case 'h': usage(0); break; default: usage(1); break; } } init(is_daemon, is_debug); if (is_daemon) { pid = fork(); if (pid < 0) exit(-1); else if (pid) exit(0); chdir("/"); close(0); open("/dev/null", O_RDWR); dup2(0, 1); dup2(0, 2); setsid(); } nl_fd = nl_open(); if (nl_fd < 0) exit(nl_fd); ipc_fd = ipc_open(); if (ipc_fd < 0) exit(ipc_fd); dl_init(); nr = MAX_DL_HANDLES; poll_array = poll_init(nr); dl_config_load(); event_loop(nr, poll_array); return 0; }