Merge pull request #184 from jaspervandeven/master
Made svr_sock_ and is_running_ variables atomic
This commit is contained in:
commit
cb43980a70
@ -70,6 +70,7 @@ typedef int socket_t;
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
@ -285,8 +286,8 @@ private:
|
|||||||
|
|
||||||
virtual bool read_and_close_socket(socket_t sock);
|
virtual bool read_and_close_socket(socket_t sock);
|
||||||
|
|
||||||
bool is_running_;
|
std::atomic<bool> is_running_;
|
||||||
socket_t svr_sock_;
|
std::atomic<socket_t> svr_sock_;
|
||||||
std::string base_dir_;
|
std::string base_dir_;
|
||||||
Handlers get_handlers_;
|
Handlers get_handlers_;
|
||||||
Handlers post_handlers_;
|
Handlers post_handlers_;
|
||||||
@ -1587,8 +1588,7 @@ inline bool Server::is_running() const { return is_running_; }
|
|||||||
inline void Server::stop() {
|
inline void Server::stop() {
|
||||||
if (is_running_) {
|
if (is_running_) {
|
||||||
assert(svr_sock_ != INVALID_SOCKET);
|
assert(svr_sock_ != INVALID_SOCKET);
|
||||||
auto sock = svr_sock_;
|
std::atomic<socket_t> sock (svr_sock_.exchange(INVALID_SOCKET));
|
||||||
svr_sock_ = INVALID_SOCKET;
|
|
||||||
detail::shutdown_socket(sock);
|
detail::shutdown_socket(sock);
|
||||||
detail::close_socket(sock);
|
detail::close_socket(sock);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user