File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ typedef int socket_t;
7070#include < string>
7171#include < sys/stat.h>
7272#include < thread>
73+ #include < atomic>
7374
7475#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
7576#include < openssl/err.h>
@@ -285,8 +286,8 @@ class Server {
285286
286287 virtual bool read_and_close_socket (socket_t sock);
287288
288- bool is_running_;
289- socket_t svr_sock_;
289+ std::atomic< bool > is_running_;
290+ std::atomic< socket_t > svr_sock_;
290291 std::string base_dir_;
291292 Handlers get_handlers_;
292293 Handlers post_handlers_;
@@ -1587,8 +1588,7 @@ inline bool Server::is_running() const { return is_running_; }
15871588inline void Server::stop () {
15881589 if (is_running_) {
15891590 assert (svr_sock_ != INVALID_SOCKET);
1590- auto sock = svr_sock_;
1591- svr_sock_ = INVALID_SOCKET;
1591+ std::atomic<socket_t > sock (svr_sock_.exchange (INVALID_SOCKET));
15921592 detail::shutdown_socket (sock);
15931593 detail::close_socket (sock);
15941594 }
You can’t perform that action at this time.
0 commit comments