Fixed crash if server instance gets deleted after the call to io_service->stop() but before the acceptor gets notified of the stop.

This commit is contained in:
David Olszowka 2016-11-07 17:32:21 +01:00 • committed by eidheim
commit 743785b563
2 changed files with 7 additions and 4 deletions

View file

@ -422,7 +422,8 @@ namespace SimpleWeb {
std::shared_ptr<HTTP> socket(new HTTP(*io_service)); std::shared_ptr<HTTP> socket(new HTTP(*io_service));
acceptor->async_accept(*socket, [this, socket](const boost::system::error_code& ec){ acceptor->async_accept(*socket, [this, socket](const boost::system::error_code& ec){
//Immediately start accepting a new connection //Immediately start accepting a new connection (if io_service hasn't been stopped)
if (ec != boost::asio::error::operation_aborted)
accept(); accept();
if(!ec) { if(!ec) {

View file

@ -31,9 +31,11 @@ namespace SimpleWeb {
std::shared_ptr<HTTPS> socket(new HTTPS(*io_service, context)); std::shared_ptr<HTTPS> socket(new HTTPS(*io_service, context));
acceptor->async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code& ec) { acceptor->async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code& ec) {
//Immediately start accepting a new connection //Immediately start accepting a new connection (if io_service hasn't been stopped)
if (ec != boost::asio::error::operation_aborted)
accept(); accept();
if(!ec) { if(!ec) {
boost::asio::ip::tcp::no_delay option(true); boost::asio::ip::tcp::no_delay option(true);
socket->lowest_layer().set_option(option); socket->lowest_layer().set_option(option);