Fixes #280 : added start_stop_mutex that is used in Server::bind() and Server::stop()
This commit is contained in:
parent
44b787e27a
commit
253b18f02b
1 changed files with 6 additions and 0 deletions
|
|
@ -386,6 +386,8 @@ namespace SimpleWeb {
|
|||
/// Returns assigned port. If io_service is not set, an internal io_service is created instead.
|
||||
/// Call before accept_and_run().
|
||||
unsigned short bind() {
|
||||
std::lock_guard<std::mutex> lock(start_stop_mutex);
|
||||
|
||||
asio::ip::tcp::endpoint endpoint;
|
||||
if(config.address.size() > 0)
|
||||
endpoint = asio::ip::tcp::endpoint(make_address(config.address), config.port);
|
||||
|
|
@ -452,6 +454,8 @@ namespace SimpleWeb {
|
|||
|
||||
/// Stop accepting new requests, and close current connections.
|
||||
void stop() noexcept {
|
||||
std::lock_guard<std::mutex> lock(start_stop_mutex);
|
||||
|
||||
if(acceptor) {
|
||||
error_code ec;
|
||||
acceptor->close(ec);
|
||||
|
|
@ -474,6 +478,8 @@ namespace SimpleWeb {
|
|||
}
|
||||
|
||||
protected:
|
||||
std::mutex start_stop_mutex;
|
||||
|
||||
bool internal_io_service = false;
|
||||
|
||||
std::unique_ptr<asio::ip::tcp::acceptor> acceptor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue