- Notifications
You must be signed in to change notification settings - Fork425
Expose OS-chosen address and port; force IPv4#707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,12 +4,13 @@ | ||
# http://www.boost.org/LICENSE_1_0.txt) | ||
cmake_minimum_required(VERSION 2.8) | ||
cmake_policy(SET CMP0048 NEW) # The project() command manages VERSION variables. | ||
project(CPP-NETLIB VERSION 0.11.1) | ||
option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries."ON ) | ||
option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests."OFF) | ||
option( CPP-NETLIB_BUILD_EXPERIMENTS "Build the cpp-netlib project experiments."OFF) | ||
option( CPP-NETLIB_BUILD_EXAMPLES "Build the cpp-netlib project examples."OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not comfortable with changing these defaults. Is there a reason why you don't set these from your project? | ||
option( CPP-NETLIB_ENABLE_HTTPS "Build cpp-netlib with support for https if OpenSSL is found." ON) | ||
include(GNUInstallDirs) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -62,6 +62,9 @@ struct sync_server_base : server_storage_base, socket_options_base { | ||
if (!listening_) start_listening(); | ||
} | ||
const string_type& address() const { return address_; } | ||
const string_type& port() const { return port_; } | ||
private: | ||
Handler& handler_; | ||
string_type address_, port_; | ||
@@ -86,7 +89,7 @@ struct sync_server_base : server_storage_base, socket_options_base { | ||
using boost::asio::ip::tcp; | ||
system::error_code error; | ||
tcp::resolver resolver(service_); | ||
tcp::resolver::query query(tcp::v4(),address_, port_); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. There seems to be no reason for this -- can you not make this explicit in your code instead? As part of the options? | ||
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error); | ||
if (error) { | ||
BOOST_NETWORK_MESSAGE("Error resolving address: " << address_ << ':' | ||
@@ -109,6 +112,8 @@ struct sync_server_base : server_storage_base, socket_options_base { | ||
<< error << '\''); | ||
boost::throw_exception(std::runtime_error("Error binding to socket.")); | ||
} | ||
address_ = acceptor_.local_endpoint().address().to_v4().to_string(); | ||
port_ = std::to_string(acceptor_.local_endpoint().port()); | ||
acceptor_.listen(tcp::socket::max_connections, error); | ||
if (error) { | ||
BOOST_NETWORK_MESSAGE("Error listening on socket: " | ||