int threads_process(intrace_t * intrace) { int err; pthread_attr_t attr; pthread_t t; if (pthread_mutex_init(&intrace->mutex, NULL) != 0) { debug_printf(dlFatal, "threads: Mutex initialization failed\n"); return errMutex; } debug_printf(dlDebug, "Resolving '%s'\n", intrace->hostname); if (!threads_resolveIP(intrace, intrace->hostname)) { debug_printf(dlFatal, "Resolving '%s' failed\n", intrace->hostname); return errResolve; } char haddr[INET6_ADDRSTRLEN]; if (!inet_ntop(_IT_AF(intrace), _IT_RIP(intrace), haddr, sizeof(haddr))) { debug_printf(dlFatal, "Cannot convert IP addr to a text form\n"); return errResolve; } debug_printf(dlDebug, "%s for '%s' resolved='%s'\n", _IT_IPSTR(intrace), intrace->hostname, haddr); if ((err = listener_init(intrace)) != errNone) { debug_printf(dlFatal, "threads: Listener initialization failed, err=%d'\n", err); return err; } if ((err = sender_init(intrace)) != errNone) { debug_printf(dlFatal, "threads: Packet sender initialization failed, err=%d\n", err); return err; } if ((err = threads_dropPrivs()) != errNone) { debug_printf(dlFatal, "threads: Couldn't drop privileges, err=%d\n", err); return err; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (pthread_create(&t, &attr, listener_thr, (void *)intrace) < 0) { debug_printf(dlFatal, "threads: Cannot create listener thread\n"); return errThread; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (pthread_create(&t, &attr, sender_thr, (void *)intrace) < 0) { debug_printf(dlFatal, "threads: Cannot create sender thread\n"); return errThread; } display_process(intrace); return errNone; }
struct listener *listener_create() { struct listener *self = (struct listener *)netpool_createlisten(); if (!self) { log_error(" struct listener *self = (struct listener *)netpool_createlisten();"); return NULL; } listener_init(self); return self; }
static void _test_build_parser_context(ParserContext *context) { listener_init(&context->parse_setup_lexer, NULL, context); listener_init(&context->parse_setup_fsm, NULL, context); listener_init(&context->parse_start, _test_parse_start, context); listener_init(&context->parse_loop, control_loop_ast, context); listener_init(&context->parse_end, _test_parse_end, context); listener_init(&context->parse_error, _test_parse_error, context); listener_init(&context->lexer_pipe, test_lexer_pipe, context); listener_init(&context->parser_pipe, test_parser_pipe, context); }
int mod_main (flux_t h, int argc, char **argv) { ctx_t *ctx = getctx (h); char *sockpath = NULL, *dfltpath = NULL; int rc = -1; /* Parse args. */ if (argc > 0) sockpath = argv[0]; if (!sockpath) sockpath = dfltpath = xasprintf ("%s/flux-api", flux_get_tmpdir ()); /* Create listen socket and watcher to handle new connections */ if ((ctx->listen_fd = listener_init (ctx, sockpath)) < 0) goto done; if (!(ctx->listen_w = flux_fd_watcher_create (ctx->listen_fd, FLUX_POLLIN | FLUX_POLLERR, listener_cb, ctx))) { flux_log (h, LOG_ERR, "flux_fd_watcher_create: %s", strerror (errno)); goto done; } flux_fd_watcher_start (h, ctx->listen_w); /* Create/start event/response message watchers */ if (flux_msg_watcher_addvec (h, htab, ctx) < 0) { flux_log (h, LOG_ERR, "flux_msg_watcher_addvec: %s", strerror (errno)); goto done; } /* Start reactor */ if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); goto done; } rc = 0; done: if (dfltpath) free (dfltpath); flux_msg_watcher_delvec (h, htab); flux_fd_watcher_destroy (ctx->listen_w); if (ctx->listen_fd >= 0) { if (close (ctx->listen_fd) < 0) flux_log (h, LOG_ERR, "close listen_fd: %s", strerror (errno)); } if (ctx->clients) { client_t *c; while ((c = zlist_pop (ctx->clients))) client_destroy (c); } return rc; }
int main(int argc, char **argv) { struct listenparams p; struct packet *pk; char *c; u_int32_t *u; int active_listener = -1; int i; listener_init(); if (argc < 5) { fprintf(stderr, "Usage: testlistener <listenername> <online_mode> <ifname> <targetmachine>\n"); fprintf(stderr, "\nAvailable listeners:\n"); for (i=0; i<N_LISTENERS; i++) { fprintf(stderr, listeners[i].name); fprintf(stderr, "\n"); } exit(1); } for (i=0; i<N_LISTENERS; i++) if (strcmp(argv[1],listeners[i].name) == 0) { active_listener = i; break; } if (active_listener == -1) { fprintf(stderr, "Listener not found\n"); exit(1); } signal(SIGINT,stop); p.online_mode = atoi(argv[2]); strcpy(p.ifname,argv[3]); // HORRIBLE OVERFLOW :)) strcpy(p.targetmachine,argv[4]); // also here printf("TESTLISTENER [listener=%s] [online_mode=%d] [ifname=%s] [targetip=%s]\n",listeners[active_listener].name,p.online_mode,p.ifname,p.targetmachine); listener_start(&p,active_listener); while (1) { printf("Waiting packets...\n"); pk = listener_receivepkt(); // for (i=0;i<2000000;i++); //introduce Overhead... printf("PKT: %lld) curtime: %5.4f ---- pkt_in_queue: %d --",pk->n_pkt,pk->curtime,listener_packetsqueued()); c = (char *) pk->pkt + 14; u = (u_int32_t *) (c+20+4) ; printf(" Sequencenum: %d\n",ntohs(*u)); listener_freepkt(pk); } // not reached return 0; }
int main(int argc, char *argv[]) { serverstate_set_event_loop(uv_default_loop()); config_init(); listener_init(); client_init(); module_init(); server_init(); command_init(); connection_init(); process_commandline(argv, argc); config_load(); listener_start_listeners(); module_load_all_modules(); connection_init_tls(); uv_run(serverstate_get_event_loop(), UV_RUN_DEFAULT); return 0; }
static int luaSetupListener(lua_State *L) { lua_pushboolean(L, listener_init(luaL_checkstring(L, 1), luaL_checklong(L, 2))); return 1; }