nghttpx: Do creation of InheritedAddr in a dedicated function for reuse

This commit is contained in:
Tatsuhiro Tsujikawa 2016-07-30 23:58:19 +09:00
parent f4a4abd180
commit a54cda22ab
1 changed files with 26 additions and 13 deletions

View File

@ -660,11 +660,8 @@ int create_tcp_server_socket(UpstreamAddr &faddr,
} // namespace
namespace {
int create_acceptor_socket() {
std::vector<InheritedAddr> get_inherited_addr_from_env() {
int rv;
auto &listenerconf = mod_config()->conn.listener;
std::vector<InheritedAddr> iaddrs;
{
@ -806,6 +803,26 @@ int create_acceptor_socket() {
}
}
return iaddrs;
}
} // namespace
namespace {
void closeUnusedInheritedAddr(const std::vector<InheritedAddr> &iaddrs) {
for (auto &ia : iaddrs) {
if (ia.used) {
continue;
}
close(ia.fd);
}
}
} // namespace
namespace {
int create_acceptor_socket(std::vector<InheritedAddr> &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);