Fix a crash following use of the stop_listening function.

This commit is contained in:
Peter Thorson
2014-01-26 20:53:17 -06:00
parent 373f180638
commit bb431ee0d2
3 changed files with 42 additions and 6 deletions

View File

@@ -22,10 +22,12 @@ HEAD
reference counted pointers. #310 Thank you otaras for reporting.
- Bug: Fix issue with const endpoint accessors (such as `get_user_agent`) not
compiling due to non-const mutex use. #292 Thank you logofive for reporting.
- Bug: Fix handler allocation crash with multithreaded io_service.
- Bug: Fix handler allocation crash with multithreaded `io_service`.
- Bug: Fixes incorrect whitespace handling in header parsing. #301 Thank you
Wolfram Schroers for reporting
- Bug: Fix a crash when parsing empty HTTP headers. Thank you Thingol for reporting.
- Bug: Fix a crash following use of the `stop_listening` function. Thank you Thingol for
reporting.
0.3.0-alpha4 - 2013-10-11
- HTTP requests ending normally are no longer logged as errors. Thank you Banaan

View File

@@ -504,6 +504,24 @@ BOOST_AUTO_TEST_CASE( client_failed_connection ) {
run_time_limited_client(c,"http://localhost:9005", 5, false);
}
BOOST_AUTO_TEST_CASE( stop_listening ) {
server s;
client c;
// the first connection stops the server from listening
s.set_open_handler(bind(&cancel_on_open,&s,::_1));
// client immediately closes after opening a connection
c.set_open_handler(bind(&close<client>,&c,::_1));
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,true));
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,2));
tthread.detach();
run_client(c, "http://localhost:9005",false);
sthread.join();
}
BOOST_AUTO_TEST_CASE( pause_reading ) {
iostream_server s;

View File

@@ -84,7 +84,9 @@ public:
// Starts the server's async connection acceptance loop.
void start_accept() {
connection_ptr con = get_connection();
lib::error_code ec;
transport_type::async_accept(
lib::static_pointer_cast<transport_con_type>(con),
lib::bind(
@@ -92,16 +94,30 @@ public:
this,
con,
lib::placeholders::_1
)
),
ec
);
if (ec == error::async_accept_not_listening) {
endpoint_type::m_elog.write(log::elevel::info,
"Stopping acceptance of new connections because the underlying transport is no longer listening.");
} else if (ec) {
endpoint_type::m_elog.write(log::elevel::rerror,
"handle_accept error: "+ec.message());
}
}
void handle_accept(connection_ptr con, const lib::error_code& ec) {
void handle_accept(connection_ptr con, lib::error_code const & ec) {
if (ec) {
con->terminate(ec);
endpoint_type::m_elog.write(log::elevel::rerror,
"handle_accept error: "+ec.message());
if (ec == error::operation_canceled) {
endpoint_type::m_elog.write(log::elevel::info,
"handle_accept error: "+ec.message());
} else {
endpoint_type::m_elog.write(log::elevel::rerror,
"handle_accept error: "+ec.message());
}
} else {
con->start();
}