struct multi_tcp * multi_tcp_init(int maxevents, int *maxclients) { struct multi_tcp *mtcp; const int extra_events = BASE_N_EVENTS; ASSERT(maxevents >= 1); ASSERT(maxclients); ALLOC_OBJ_CLEAR(mtcp, struct multi_tcp); mtcp->maxevents = maxevents + extra_events; mtcp->es = event_set_init(&mtcp->maxevents, 0); wait_signal(mtcp->es, MTCP_SIG); ALLOC_ARRAY(mtcp->esr, struct event_set_return, mtcp->maxevents); *maxclients = max_int(min_int(mtcp->maxevents - extra_events, *maxclients), 1); msg(D_MULTI_LOW, "MULTI: TCP INIT maxclients=%d maxevents=%d", *maxclients, mtcp->maxevents); return mtcp; }
/* * This is the main function for the port share proxy background process. */ static void port_share_proxy (const in_addr_t hostaddr, const int port, const socket_descriptor_t sd_control, const int max_initial_buf, const char *journal_dir) { if (send_control (sd_control, RESPONSE_INIT_SUCCEEDED) >= 0) { void *sd_control_marker = (void *)1; int maxevents = 256; struct event_set *es; struct event_set_return esr[64]; struct proxy_connection *list = NULL; time_t last_housekeeping = 0; msg (D_PS_PROXY, "PORT SHARE PROXY: proxy starting"); es = event_set_init (&maxevents, 0); event_ctl (es, sd_control, EVENT_READ, sd_control_marker); while (true) { int n_events; struct timeval tv; time_t current; tv.tv_sec = 10; tv.tv_usec = 0; n_events = event_wait (es, &tv, esr, SIZE(esr)); /*dmsg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: event_wait returned %d", n_events);*/ current = time(NULL); if (n_events > 0) { int i; for (i = 0; i < n_events; ++i) { const struct event_set_return *e = &esr[i]; if (e->arg == sd_control_marker) { if (!control_message_from_parent (sd_control, &list, es, hostaddr, port, max_initial_buf, journal_dir)) goto done; } else { struct proxy_connection *pc = (struct proxy_connection *)e->arg; if (pc->defined) proxy_connection_io_dispatch (pc, e->rwflags, es); } } } else if (n_events < 0) { dmsg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: event_wait failed"); } if (current > last_housekeeping) { proxy_list_housekeeping (&list); last_housekeeping = current; } } done: proxy_list_close (&list); event_free (es); } msg (M_INFO, "PORT SHARE PROXY: proxy exiting"); }