void async_network_task_push(struct async_network_task_s *task) { static int thread_started = 0; if (!thread_started) { pthread_t t; evthread_use_pthreads(); event_b = event_base_new(); evdns_b = evdns_base_new(event_b, 0); evdns_base_resolv_conf_parse(evdns_b, DNS_OPTIONS_ALL, "/etc/resolv.conf"); if (config.randomize_dns_case == 0) evdns_base_set_option(evdns_b, "randomize-case:", "0"); pthread_create(&t, NULL, network_worker_thread, NULL); pthread_detach(t); thread_started = 1; } switch (task->type) { case ASYNC_NETWORK_TCP_CONNECT: handle_tcp_connect_stage1(task); break; case ASYNC_NETWORK_TCP_CONNECT_WITH_NETADDRESS: handle_tcp_connect_with_net_address(task); break; case ASYNC_NETWORK_DISCONNECT: handle_disconnect_stage1(task); break; case ASYNC_NETWORK_TCP_READ: handle_tcp_read_stage1(task); break; case ASYNC_NETWORK_TCP_WRITE: handle_tcp_write_stage1(task); break; case ASYNC_NETWORK_UDP_RECV: handle_udp_recv_stage1(task); break; case ASYNC_NETWORK_UDP_SEND: handle_udp_send_stage1(task); break; case ASYNC_NETWORK_HOST_RESOLVE: handle_host_resolve_stage1(task); break; } }
int eooqd_main(int argc, char *argv[]) { int r; size_t len; char *pid_file_name, *interface_name, *instance_id_str; char *check; struct event *checkQueueEvent, *rePostEvent; struct timeval tv; struct rlimit limit; struct stat sb; atlas_id= NULL; interface_name= NULL; instance_id_str= NULL; pid_file_name= NULL; queue_id= ""; (void)getopt32(argv, "A:I:i:P:q:", &atlas_id, &interface_name, &instance_id_str, &pid_file_name, &queue_id); if (argc != optind+1) { bb_show_usage(); return 1; } instance_id= 0; if (instance_id_str) { instance_id= strtoul(instance_id_str, &check, 0); if (check[0] != '\0') { report("unable to parse instance id '%s'", instance_id_str); return 1; } } if (interface_name) { len= strlen(RESOLV_CONF) + 1 + strlen(interface_name) + 1; resolv_conf= malloc(len); snprintf(resolv_conf, len, "%s.%s", RESOLV_CONF, interface_name); /* Check if this resolv.conf exists. If it doen't, switch * to the standard one. */ if (stat(resolv_conf, &sb) == -1) { free(resolv_conf); resolv_conf= strdup(RESOLV_CONF); } } else { resolv_conf= strdup(RESOLV_CONF); } if(pid_file_name) { write_pidfile(pid_file_name); } state = xzalloc(sizeof(*state)); state->atlas_id= atlas_id; state->queue_file= argv[optind]; state->max_busy= 10; state->slots= xzalloc(sizeof(*state->slots) * state->max_busy); if (strlen(state->queue_file) + strlen(SUFFIX) + 1 > sizeof(state->curr_qfile)) { report("filename too long ('%s')", state->queue_file); return 1; } strlcpy(state->curr_qfile, state->queue_file, sizeof(state->curr_qfile)); strlcat(state->curr_qfile, SUFFIX, sizeof(state->curr_qfile)); snprintf(output_filename, sizeof(output_filename), OOQD_OUT_PREFIX "%s/ooq.out", queue_id); signal(SIGQUIT, SIG_DFL); limit.rlim_cur= RLIM_INFINITY; limit.rlim_max= RLIM_INFINITY; setrlimit(RLIMIT_CORE, &limit); /* Ignore SIGPIPE, broken TCP sessions may trigger them */ signal(SIGPIPE, SIG_IGN); /* Create libevent event base */ EventBase= event_base_new(); if (!EventBase) { crondlog(DIE9 "event_base_new failed"); /* exits */ } DnsBase= evdns_base_new(EventBase, 0 /*initialize*/); if (!DnsBase) { event_base_free(EventBase); crondlog(DIE9 "evdns_base_new failed"); /* exits */ } if (interface_name) { r= evdns_base_set_interface(DnsBase, interface_name); if (r == -1) { event_base_free(EventBase); crondlog(DIE9 "evdns_base_set_interface failed"); /* exits */ } } r = evdns_base_resolv_conf_parse(DnsBase, DNS_OPTIONS_ALL, resolv_conf); if (r == -1) { event_base_free(EventBase); crondlog(DIE9 "evdns_base_resolv_conf_parse failed"); /* exits */ } checkQueueEvent= event_new(EventBase, -1, EV_TIMEOUT|EV_PERSIST, checkQueue, NULL); if (!checkQueueEvent) crondlog(DIE9 "event_new failed"); /* exits */ tv.tv_sec= 1; tv.tv_usec= 0; event_add(checkQueueEvent, &tv); rePostEvent= event_new(EventBase, -1, EV_TIMEOUT|EV_PERSIST, re_post, NULL); if (!rePostEvent) crondlog(DIE9 "event_new failed"); /* exits */ tv.tv_sec= 60; tv.tv_usec= 0; event_add(rePostEvent, &tv); r= event_base_loop(EventBase, 0); if (r != 0) crondlog(LVL9 "event_base_loop failed"); return 0; }