Splitted the start function into a two in order to access the bound port
This is relevant if binding on a random free port (0) and since start never returns... we need a split function to safely get it
This commit is contained in:
parent
bd9c1192bb
commit
3ba786f585
1 changed files with 10 additions and 1 deletions
|
|
@ -332,7 +332,7 @@ namespace SimpleWeb {
|
||||||
/// If you have your own asio::io_service, store its pointer here before running start().
|
/// If you have your own asio::io_service, store its pointer here before running start().
|
||||||
std::shared_ptr<asio::io_service> io_service;
|
std::shared_ptr<asio::io_service> io_service;
|
||||||
|
|
||||||
virtual void start() {
|
virtual unsigned short bindAndPrepare() {
|
||||||
if(!io_service) {
|
if(!io_service) {
|
||||||
io_service = std::make_shared<asio::io_service>();
|
io_service = std::make_shared<asio::io_service>();
|
||||||
internal_io_service = true;
|
internal_io_service = true;
|
||||||
|
|
@ -356,6 +356,10 @@ namespace SimpleWeb {
|
||||||
|
|
||||||
accept();
|
accept();
|
||||||
|
|
||||||
|
return acceptor->local_endpoint().port();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void runServer() {
|
||||||
if(internal_io_service) {
|
if(internal_io_service) {
|
||||||
// If thread_pool_size>1, start m_io_service.run() in (thread_pool_size-1) threads for thread-pooling
|
// If thread_pool_size>1, start m_io_service.run() in (thread_pool_size-1) threads for thread-pooling
|
||||||
threads.clear();
|
threads.clear();
|
||||||
|
|
@ -375,6 +379,11 @@ namespace SimpleWeb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void start() {
|
||||||
|
bindAndPrepare();
|
||||||
|
runServer();
|
||||||
|
}
|
||||||
|
|
||||||
/// Stop accepting new requests, and close current connections.
|
/// Stop accepting new requests, and close current connections.
|
||||||
void stop() noexcept {
|
void stop() noexcept {
|
||||||
if(acceptor) {
|
if(acceptor) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue