| 2000 | |
| 2001 | |
| 2002 | static void tcp_main_server(void) |
| 2003 | { |
| 2004 | static unsigned int last_sec = 0; |
| 2005 | struct socket_info_full* sif; |
| 2006 | struct sr_module *m; |
| 2007 | int n; |
| 2008 | |
| 2009 | /* instruct tls_mgm to initialize all TLS domains */ |
| 2010 | for (m=modules; m; m = m->next) { |
| 2011 | if (strcmp(m->exports->name, "tls_mgm") == 0) |
| 2012 | if (init_child(PROC_TCP_MAIN) < 0) { |
| 2013 | LM_ERR("error in init_child for PROC_TCP_MAIN\n"); |
| 2014 | goto error; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | /* we run in a separate, dedicated process, with its own reactor |
| 2019 | * (reactors are per process) */ |
| 2020 | if (init_worker_reactor("TCP_main", RCT_PRIO_MAX)<0) |
| 2021 | goto error; |
| 2022 | |
| 2023 | /* now start watching all the fds */ |
| 2024 | |
| 2025 | /* add all the sockets we listens on for connections */ |
| 2026 | for (n = PROTO_FIRST; n < PROTO_LAST; n++) |
| 2027 | if (is_tcp_based_proto(n)) |
| 2028 | for (sif = protos[n].listeners; sif; sif = sif->next) { |
| 2029 | struct socket_info* si = &sif->socket_info; |
| 2030 | if (protos[n].tran.bind_listener && |
| 2031 | protos[n].tran.bind_listener(si) < 0) { |
| 2032 | LM_ERR("failed to bind listener [%.*s], proto %s\n", |
| 2033 | si->name.len, si->name.s, protos[n].name); |
| 2034 | goto error; |
| 2035 | } |
| 2036 | if (si->socket != -1 && |
| 2037 | reactor_add_reader(si->socket, F_TCP_LISTENER, |
| 2038 | RCT_PRIO_NET, si) < 0) { |
| 2039 | LM_ERR("failed to add listen socket to reactor\n"); |
| 2040 | goto error; |
| 2041 | } |
| 2042 | } |
| 2043 | /* init: start watching for the IPC jobs */ |
| 2044 | if (reactor_add_reader(IPC_FD_READ_SELF, F_IPC, RCT_PRIO_ASYNC, NULL)<0){ |
| 2045 | LM_CRIT("failed to add IPC pipe to reactor\n"); |
| 2046 | goto error; |
| 2047 | } |
| 2048 | |
| 2049 | if (tcp_pool_init() < 0) |
| 2050 | goto error; |
| 2051 | |
| 2052 | is_tcp_main = 1; |
| 2053 | |
| 2054 | /* main loop (requires "handle_io()" implementation) */ |
| 2055 | reactor_main_loop( TCP_MAIN_SELECT_TIMEOUT, error, |
| 2056 | tcpconn_lifetime(last_sec) ); |
| 2057 | |
| 2058 | error: |
| 2059 | tcp_pool_destroy(); |
no test coverage detected