Skip to content

Commit 76f76fe

Browse files
author
v-shmelev
committed
Исправлено некорректное поведение под Windows XP
1 parent 0b5e253 commit 76f76fe

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <boost/network/utils/thread_pool.hpp>
1212

1313
namespace boost { namespace network { namespace http {
14-
14+
1515
template <class Tag, class Handler>
1616
struct async_server_base {
1717
typedef basic_request<Tag> request;
@@ -30,6 +30,8 @@ namespace boost { namespace network { namespace http {
3030
, io_service()
3131
, acceptor(io_service)
3232
, stopping(false)
33+
, socket_exception(false)
34+
3335
{
3436
using boost::asio::ip::tcp;
3537
tcp::resolver resolver(io_service);
@@ -49,14 +51,30 @@ namespace boost { namespace network { namespace http {
4951
}
5052

5153
void run() {
54+
if (socket_exception)
55+
{
56+
boost::system::error_code ec;
57+
acceptor.open(boost::asio::ip::tcp::v4(), ec);
58+
}
5259
io_service.run();
5360
};
5461

5562
void stop() {
5663
// stop accepting new requests and let all the existing
5764
// handlers finish.
5865
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);
6078
}
6179

6280
private:
@@ -66,6 +84,7 @@ namespace boost { namespace network { namespace http {
6684
asio::ip::tcp::acceptor acceptor;
6785
bool stopping;
6886
connection_ptr new_connection;
87+
bool socket_exception;
6988

7089
void handle_accept(boost::system::error_code const & ec) {
7190
if (!ec) {

0 commit comments

Comments
 (0)