@@ -56,6 +56,34 @@ namespace vix::websocket
5656 log.setFormatFromEnv (" VIX_LOG_FORMAT" );
5757 });
5858 }
59+
60+ std::string get_config_string_fallback (
61+ vix::config::Config &config,
62+ const std::string &primary,
63+ const std::string &fallback,
64+ const std::string &defaultValue)
65+ {
66+ const std::string value = config.getString (primary, " " );
67+
68+ if (!value.empty ())
69+ return value;
70+
71+ return config.getString (fallback, defaultValue);
72+ }
73+
74+ int get_config_int_fallback (
75+ vix::config::Config &config,
76+ const std::string &primary,
77+ const std::string &fallback,
78+ int defaultValue)
79+ {
80+ const int primaryValue = config.getInt (primary, -1 );
81+
82+ if (primaryValue >= 0 )
83+ return primaryValue;
84+
85+ return config.getInt (fallback, defaultValue);
86+ }
5987 } // namespace
6088
6189 LowLevelServer::LowLevelServer (
@@ -81,7 +109,12 @@ namespace vix::websocket
81109 " vix::websocket::LowLevelServer requires a valid runtime executor" );
82110 }
83111
84- const int port = coreConfig_.getInt (" websocket.port" , 9090 );
112+ const int port =
113+ get_config_int_fallback (
114+ coreConfig_,
115+ " websocket.port" ,
116+ " websocket_port" ,
117+ 9090 );
85118 if ((port != 0 && port < 1024 ) || port > 65535 )
86119 {
87120 logger ().log (
@@ -111,8 +144,20 @@ namespace vix::websocket
111144 vix::async::net::tcp_endpoint LowLevelServer::make_bind_endpoint () const
112145 {
113146 vix::async::net::tcp_endpoint ep{};
114- ep.host = coreConfig_.getString (" websocket.host" , " 0.0.0.0" );
115- ep.port = static_cast <std::uint16_t >(coreConfig_.getInt (" websocket.port" , 9090 ));
147+ ep.host =
148+ get_config_string_fallback (
149+ const_cast <vix::config::Config &>(coreConfig_),
150+ " websocket.host" ,
151+ " websocket_host" ,
152+ " 0.0.0.0" );
153+
154+ ep.port =
155+ static_cast <std::uint16_t >(
156+ get_config_int_fallback (
157+ const_cast <vix::config::Config &>(coreConfig_),
158+ " websocket.port" ,
159+ " websocket_port" ,
160+ 9090 ));
116161 return ep;
117162 }
118163
@@ -127,7 +172,13 @@ namespace vix::websocket
127172 try
128173 {
129174 vix::async::net::tcp_endpoint endpoint{};
130- endpoint.host = coreConfig_.getString (" websocket.host" , " 0.0.0.0" );
175+ endpoint.host =
176+ get_config_string_fallback (
177+ coreConfig_,
178+ " websocket.host" ,
179+ " websocket_host" ,
180+ " 0.0.0.0" );
181+
131182 endpoint.port = port;
132183
133184 co_await listener_->async_listen (endpoint);
@@ -149,7 +200,12 @@ namespace vix::websocket
149200
150201 vix::async::core::task<void > LowLevelServer::start_server ()
151202 {
152- const int port = coreConfig_.getInt (" websocket.port" , 9090 );
203+ const int port =
204+ get_config_int_fallback (
205+ coreConfig_,
206+ " websocket.port" ,
207+ " websocket_port" ,
208+ 9090 );
153209
154210 co_await init_listener (static_cast <unsigned short >(port));
155211
@@ -176,8 +232,8 @@ namespace vix::websocket
176232 init_logger_from_env_once ();
177233 vix::utils::console_wait_banner ();
178234
179- start_io_threads ();
180235 spawn_detached (*ioContext_, start_server ());
236+ start_io_threads ();
181237 }
182238
183239 void LowLevelServer::start_accept ()
0 commit comments