File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
boost/network/protocol/http/server Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 11
11
#include < boost/network/utils/thread_pool.hpp>
12
12
13
13
namespace boost { namespace network { namespace http {
14
-
14
+
15
15
template <class Tag , class Handler >
16
16
struct async_server_base {
17
17
typedef basic_request<Tag> request;
@@ -30,6 +30,8 @@ namespace boost { namespace network { namespace http {
30
30
, io_service()
31
31
, acceptor(io_service)
32
32
, stopping(false )
33
+ , socket_exception(false )
34
+
33
35
{
34
36
using boost::asio::ip::tcp;
35
37
tcp::resolver resolver (io_service);
@@ -49,14 +51,30 @@ namespace boost { namespace network { namespace http {
49
51
}
50
52
51
53
void run () {
54
+ if (socket_exception)
55
+ {
56
+ boost::system::error_code ec;
57
+ acceptor.open (boost::asio::ip::tcp::v4 (), ec);
58
+ }
52
59
io_service.run ();
53
60
};
54
61
55
62
void stop () {
56
63
// stop accepting new requests and let all the existing
57
64
// handlers finish.
58
65
stopping = true ;
59
- acceptor.cancel ();
66
+
67
+ if (!socket_exception)
68
+ {
69
+ try
70
+ { acceptor.cancel (); }
71
+ catch (...)
72
+ { socket_exception = true ; }
73
+ }
74
+
75
+ boost::system::error_code ec;
76
+ if (socket_exception)
77
+ acceptor.close (ec);
60
78
}
61
79
62
80
private:
@@ -66,6 +84,7 @@ namespace boost { namespace network { namespace http {
66
84
asio::ip::tcp::acceptor acceptor;
67
85
bool stopping;
68
86
connection_ptr new_connection;
87
+ bool socket_exception;
69
88
70
89
void handle_accept (boost::system::error_code const & ec) {
71
90
if (!ec) {
You can’t perform that action at this time.
0 commit comments