Support system-assigned port via two part listen()

This fixes #46 by allowing the user to separate the port bind from the
blocking listen(). Two new API functions bind_to_any_port() (which
returns the system-assigned port) and listen_after_bind() are equivalent
to the existing listen().
This commit is contained in:
Scott Graham 2018-04-15 00:56:00 -07:00
parent 0e239a0014
commit 0515c6aad6
2 changed files with 82 additions and 40 deletions

View file

@ -240,6 +240,13 @@ TEST(ConnectionErrorTest, Timeout)
ASSERT_TRUE(res == nullptr);
}
TEST(Server, BindAndListenSeparately) {
Server svr(httplib::HttpVersion::v1_1);
int port = svr.bind_to_any_port("localhost");
ASSERT_TRUE(port > 0);
svr.stop();
}
class ServerTest : public ::testing::Test {
protected:
ServerTest()