@@ -35,13 +35,17 @@ struct async_server_base : server_storage_base, socket_options_base {
3535// / Defines the type for the connection pointer.
3636typedef std::shared_ptr<connection> connection_ptr;
3737
38+ // / Defines the type for the options.
39+ typedef server_options<Tag, Handler> options;
40+
3841// / Constructs and initializes the asynchronous server core.
39- explicit async_server_base (server_options<Tag, Handler> const &options)
42+ explicit async_server_base (options const &options)
4043 : server_storage_base(options),
4144 socket_options_base(options),
4245 handler(options.handler()),
4346 address_(options.address()),
4447 port_(options.port()),
48+ protocol_family(options.protocol_family()),
4549 thread_pool(options.thread_pool()
4650 ? options.thread_pool()
4751 : std::make_shared<utils::thread_pool>()),
@@ -108,11 +112,19 @@ struct async_server_base : server_storage_base, socket_options_base {
108112 }
109113 }
110114
115+ // / Returns the server socket address, either IPv4 or IPv6 depending on
116+ // / options.protocol_family()
117+ const string_type&address ()const {return address_; }
118+
119+ // / Returns the server socket port
120+ const string_type&port ()const {return port_; }
121+
111122private:
112123typedef std::unique_lock<std::mutex> scoped_mutex_lock;
113124
114125 Handler &handler;
115126 string_type address_, port_;
127+ typename options::protocol_family_t protocol_family;
116128 std::shared_ptr<utils::thread_pool> thread_pool;
117129 boost::asio::ip::tcp::acceptor acceptor;
118130bool stopping;
@@ -165,7 +177,15 @@ struct async_server_base : server_storage_base, socket_options_base {
165177// this allows repeated cycles of run -> stop -> run
166178 service_.reset ();
167179 tcp::resolverresolver (service_);
168- tcp::resolver::queryquery (address_, port_);
180+ tcp::resolver::queryquery ( [&]{
181+ switch (protocol_family) {
182+ case options::ipv4:
183+ return tcp::resolver::query (tcp::v4 (), address_, port_);
184+ case options::ipv6:
185+ return tcp::resolver::query (tcp::v6 (), address_, port_);
186+ default :
187+ return tcp::resolver::query (address_, port_);
188+ }}());
169189 tcp::resolver::iterator endpoint_iterator = resolver.resolve (query, error);
170190if (error) {
171191BOOST_NETWORK_MESSAGE (" Error resolving '" << address_ <<' :' << port_);
@@ -185,6 +205,8 @@ struct async_server_base : server_storage_base, socket_options_base {
185205 << port_);
186206return ;
187207 }
208+ address_ = acceptor.local_endpoint ().address ().to_string ();
209+ port_ =std::to_string (acceptor.local_endpoint ().port ());
188210 acceptor.listen (boost::asio::socket_base::max_connections, error);
189211if (error) {
190212BOOST_NETWORK_MESSAGE (" Error listening on socket: '"