Closed qwertzui11 closed 3 years ago
Hi! Thanks for reporting this use-case.
We've never used RESTinio in such scenarios. I'll investigate the behavior of RESTinio's acceptor and reply to you back later.
At this time I don't see an easy way to pass the actual local_endpoint of the acceptor to the outside of http_server_t
instance. One of the reasons is the fact that that local_endpoint will be known only after completion of http_server_t::open_sync
method, but this moment is hard to detect from the outside of http_server_t
instance.
One of the current ideas is to add another callback to server_settings_t
. Something like:
asio::ip::tcp::endpoint server_endpoint;
...
server_t srv1{
restinio::external_io_context(*context),
settings_t{}.port(0).address("localhost")
.post_acceptor_bind_hook([&server_endpoint](asio::ip::tcp::acceptor & acceptor) {
server_endpoint = acceptor.local_endpoint();
})
.request_handler([](auto) {
return restinio::request_accepted();
})};
...
But I'm not sure that's a good idea yet. Will think further.
I don't know this library well enough, nor its design.
hoooowever some ideas :laughing:
asio::ip::tcp::acceptor
, and more? like for resolver
and more.open_sync
could return a result that contains a port and maybe some other information thats available after the open. like the resolved bind endpoint?Hi @qwertzui11 !
A new post-bind callback is added to RESTinio. You can see an example of its usage here: https://github.com/Stiffstream/restinio/blob/f3bdbfc8d16efdc4ff42b92def01b1a5339ced9d/dev/test/handle_requests/acceptor_post_bind_hook/main.cpp#L23-L66
The new functionality is in 0.6-dev-0.6.11 branch now. I plan to add yet more functionality into v.0.6.11 before the public release of that version. Hope I can complete it in a week, but it hard to predict. So if you can't wait please let us know.
excellent. I'll wait and try it out as soon as it's available on conan. Thx for the great work! :heart_eyes:
It seems that the scope of v.0.6.11 is completed. We have to update to docs and then the release will be published.
works! awesome, thx!
hi. Thx for your great on this awesome framework.
I'd like to host the server on a random port. Aka using port
0
and then call some method likeget_port()
.asio::*::acceptor
assigns on port 0 a random port. This is useful when it comes to unittests, that may run in parallel. I could not find any information on that topic. Is there a possibility to set the port to 0 and then retreive it?so far I got:
thx for ur time!