Server can be started on a random free port

If the server is started with a port value of 0, it binds to a random
free port. The bound port can be obtained with a `getPort()` method.
This commit is contained in:
Veloman Yunkan
2020-04-18 15:45:51 +04:00
parent 9bf6d0621f
commit b0f65a02f2
3 changed files with 11 additions and 2 deletions

View File

@ -50,6 +50,8 @@ ZimFileServer::ZimFileServer(int serverPort, std::string zimpath)
if ( !server->start() )
throw std::runtime_error("ZimFileServer failed to start");
if ( serverPort == 0 )
serverPort = server->getPort();
client.reset(new httplib::Client(address, serverPort));
}
@ -64,7 +66,7 @@ class ServerTest : public ::testing::Test
protected:
std::unique_ptr<ZimFileServer> zfs1_;
const int PORT = 8001;
const int PORT = 0;
const std::string ZIMFILE = "./test/zimfile.zim";
protected: