Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Added a block boolean param to the server.run function
Browse files Browse the repository at this point in the history
  • Loading branch information
luismartingil committed Nov 2, 2018
1 parent 430d712 commit a12f529
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/served/net/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ server::server( const std::string & address
}

void
server::run(int n_threads /* = 1 */)
server::run(int n_threads /* = 1 */, bool block /* = true */)
{
/*
* The io_service::run() call will block until all asynchronous operations
Expand All @@ -88,9 +88,16 @@ server::run(int n_threads /* = 1 */)
}
for ( auto & thread : v_threads )
{
if ( thread.joinable() )
if ( block )
{
thread.join();
if ( thread.joinable() )
{
thread.join();
}
}
else
{
thread.detach();
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/served/net/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ class server
/*
* A call that prompts the server into listening for HTTP requests.
*
* This call blocks until the server is closed, it accepts a value for how large the thread
* pool should be for distributing requests.
* This call accepts a value for how large the thread pool should be for distributing requests
* and another param which defines the blocking nature.
*
* @param n_threads the number of threads to pool for request handling
* @param block if n_threads > 0, defines whether this operation is blocking or not
*/
void run(int n_threads = 1);
void run(int n_threads = 1, bool block = true);

/*
* Stops the server from accepting requests.
Expand Down

0 comments on commit a12f529

Please sign in to comment.