mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-20 19:58:35 +00:00
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:
parent
0e239a0014
commit
0515c6aad6
2 changed files with 82 additions and 40 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue