From 2fdc41c3236014617ac36290bc69c2c4694d89af Mon Sep 17 00:00:00 2001 From: Jasper van de Ven Date: Fri, 5 Jul 2019 11:03:23 +0200 Subject: [PATCH] Made svr_sock_ and is_running_ variables atomic --- httplib.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/httplib.h b/httplib.h index 90a8c19..ec21956 100644 --- a/httplib.h +++ b/httplib.h @@ -70,6 +70,7 @@ typedef int socket_t; #include #include #include +#include #ifdef CPPHTTPLIB_OPENSSL_SUPPORT #include @@ -285,8 +286,8 @@ private: virtual bool read_and_close_socket(socket_t sock); - bool is_running_; - socket_t svr_sock_; + std::atomic is_running_; + std::atomic svr_sock_; std::string base_dir_; Handlers get_handlers_; Handlers post_handlers_; @@ -1587,8 +1588,7 @@ inline bool Server::is_running() const { return is_running_; } inline void Server::stop() { if (is_running_) { assert(svr_sock_ != INVALID_SOCKET); - auto sock = svr_sock_; - svr_sock_ = INVALID_SOCKET; + std::atomic sock (svr_sock_.exchange(INVALID_SOCKET)); detail::shutdown_socket(sock); detail::close_socket(sock); }