From a54cda22abc4e235cc4e67f1588b74e5c33912e5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 30 Jul 2016 23:58:19 +0900 Subject: [PATCH] nghttpx: Do creation of InheritedAddr in a dedicated function for reuse --- src/shrpx.cc | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index 86e789bc..499fc7af 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -660,11 +660,8 @@ int create_tcp_server_socket(UpstreamAddr &faddr, } // namespace namespace { -int create_acceptor_socket() { +std::vector get_inherited_addr_from_env() { int rv; - - auto &listenerconf = mod_config()->conn.listener; - std::vector iaddrs; { @@ -806,6 +803,26 @@ int create_acceptor_socket() { } } + return iaddrs; +} +} // namespace + +namespace { +void closeUnusedInheritedAddr(const std::vector &iaddrs) { + for (auto &ia : iaddrs) { + if (ia.used) { + continue; + } + + close(ia.fd); + } +} +} // namespace + +namespace { +int create_acceptor_socket(std::vector &iaddrs) { + auto &listenerconf = mod_config()->conn.listener; + for (auto &addr : listenerconf.addrs) { if (addr.host_unix) { if (create_unix_domain_server_socket(addr, iaddrs) != 0) { @@ -829,14 +846,6 @@ int create_acceptor_socket() { } } - for (auto &ia : iaddrs) { - if (ia.used) { - continue; - } - - close(ia.fd); - } - return 0; } } // namespace @@ -957,10 +966,14 @@ int event_loop() { util::make_socket_closeonexec(fd); } - if (create_acceptor_socket() != 0) { + auto iaddrs = get_inherited_addr_from_env(); + + if (create_acceptor_socket(iaddrs) != 0) { return -1; } + closeUnusedInheritedAddr(iaddrs); + auto loop = ev_default_loop(get_config()->ev_loop_flags); auto pid = fork_worker_process(&ssv);