From 743785b563f2371d9eb6fac971b130872459e777 Mon Sep 17 00:00:00 2001 From: David Olszowka Date: Mon, 7 Nov 2016 17:32:21 +0100 Subject: [PATCH] Fixed crash if server instance gets deleted after the call to io_service->stop() but before the acceptor gets notified of the stop. --- server_http.hpp | 5 +++-- server_https.hpp | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index 76f1be8..c274767 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -422,8 +422,9 @@ namespace SimpleWeb { std::shared_ptr socket(new HTTP(*io_service)); acceptor->async_accept(*socket, [this, socket](const boost::system::error_code& ec){ - //Immediately start accepting a new connection - accept(); + //Immediately start accepting a new connection (if io_service hasn't been stopped) + if (ec != boost::asio::error::operation_aborted) + accept(); if(!ec) { boost::asio::ip::tcp::no_delay option(true); diff --git a/server_https.hpp b/server_https.hpp index 3478dec..67e7718 100644 --- a/server_https.hpp +++ b/server_https.hpp @@ -31,8 +31,10 @@ namespace SimpleWeb { std::shared_ptr socket(new HTTPS(*io_service, context)); acceptor->async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code& ec) { - //Immediately start accepting a new connection - accept(); + //Immediately start accepting a new connection (if io_service hasn't been stopped) + if (ec != boost::asio::error::operation_aborted) + accept(); + if(!ec) { boost::asio::ip::tcp::no_delay option(true);