Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
# http://www.boost.org/LICENSE_1_0.txt)

cmake_minimum_required(VERSION 2.8)
project(CPP-NETLIB)
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." OFF )
option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON)
option( CPP-NETLIB_BUILD_EXPERIMENTS "Build the cpp-netlib project experiments." ON)
option( CPP-NETLIB_BUILD_EXAMPLES "Build the cpp-netlib project examples." ON)
if(MSVC)
option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF)
else()
option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." ON)
endif()
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)
Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -87,7 +92,7 @@ if (Boost_FOUND)
if (WIN32)
add_definitions(-D_WIN32_WINNT=0x0501)
endif(WIN32)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
enable_testing()
add_subdirectory(libs/network/src)
if (CPP-NETLIB_BUILD_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion boost/network/protocol/http/server/socket_options_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct socket_options_base {
receive_low_watermark(options.receive_low_watermark()),
send_low_watermark(options.send_low_watermark()),
non_blocking_io(options.non_blocking_io()),
linger(options.linger(), options.linger_timeout()) {}
linger(options.linger(), int(options.linger_timeout())) {}

void acceptor_options(boost::asio::ip::tcp::acceptor &acceptor) {
acceptor.set_option(acceptor_reuse_address);
Expand Down
7 changes: 6 additions & 1 deletion boost/network/protocol/http/server/sync_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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(address_, port_);
tcp::resolver::query query(tcp::v4(), address_, port_);
Copy link
Member

Choose a reason for hiding this comment

The 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_ << ':'
Expand All @@ -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: "
Expand Down