From 524a7f456097348a91944a5c42da6dea9a20be47 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 15 Jul 2018 21:34:16 +0200 Subject: [PATCH] Listen: simplify code flow in listen_global_init() --- src/Listen.cxx | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Listen.cxx b/src/Listen.cxx index b8e012061..06eec9dad 100644 --- a/src/Listen.cxx +++ b/src/Listen.cxx @@ -82,27 +82,24 @@ void listen_global_init(ClientListener &listener) { int port = config_get_positive(ConfigOption::PORT, DEFAULT_PORT); - const auto *param = config_get_param(ConfigOption::BIND_TO_ADDRESS); #ifdef ENABLE_SYSTEMD_DAEMON if (listen_systemd_activation(listener)) return; #endif - if (param != nullptr) { - /* "bind_to_address" is configured, create listeners - for all values */ + for (const auto *param = config_get_param(ConfigOption::BIND_TO_ADDRESS); + param != nullptr; param = param->next) { + try { + listen_add_config_param(listener, port, param); + } catch (...) { + std::throw_with_nested(FormatRuntimeError("Failed to listen on %s (line %i)", + param->value.c_str(), + param->line)); + } + } - do { - try { - listen_add_config_param(listener, port, param); - } catch (...) { - std::throw_with_nested(FormatRuntimeError("Failed to listen on %s (line %i)", - param->value.c_str(), - param->line)); - } - } while ((param = param->next) != nullptr); - } else { + if (listener.IsEmpty()) { /* no "bind_to_address" configured, bind the configured port on all interfaces */