Skip to content

Commit 1f21307

Browse files
committed
Fixing issue with stoppage and cancellation when the server starts listening.
1 parent 6a8ce11 commit 1f21307

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

boost/network/protocol/http/server/async_server.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ namespace boost { namespace network { namespace http {
5555
// stop accepting new requests and let all the existing
5656
// handlers finish.
5757
stopping = true;
58-
acceptor.cancel();
58+
system::error_code ignored;
59+
acceptor.cancel(ignored);
5960
}
6061

6162
void listen() {
@@ -101,10 +102,15 @@ namespace boost { namespace network { namespace http {
101102
tcp::resolver resolver(service_);
102103
tcp::resolver::query query(address_, port_);
103104
tcp::endpoint endpoint = *resolver.resolve(query);
104-
acceptor.open(endpoint.protocol());
105-
acceptor.bind(endpoint);
105+
106+
system::error_code error;
107+
acceptor.open(endpoint.protocol(), error);
108+
if (error) return;
109+
acceptor.bind(endpoint, error);
110+
if (error) return;
106111
socket_options_base::acceptor_options(acceptor);
107-
acceptor.listen();
112+
acceptor.listen(asio::socket_base::max_connections, error);
113+
if (error) return;
108114
new_connection.reset(new connection(service_, handler, thread_pool));
109115
acceptor.async_accept(new_connection->socket(),
110116
boost::bind(

boost/network/protocol/http/server/sync_server.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ namespace boost { namespace network { namespace http {
5757

5858
void stop() {
5959
// stop accepting new connections and let all the existing handlers finish.
60-
acceptor_.cancel();
60+
system::error_code ignored;
61+
acceptor_.cancel(ignored);
62+
service_.stop();
6163
}
6264

6365
void listen() {

0 commit comments

Comments
 (0)