add option reuse addr in local endpoint configuration of asio client#1212
Closed
akonskarm wants to merge 1 commit intonghttp2:masterfrom
akonskarm:reuse_addr
Closed
add option reuse addr in local endpoint configuration of asio client#1212akonskarm wants to merge 1 commit intonghttp2:masterfrom akonskarm:reuse_addr
akonskarm wants to merge 1 commit intonghttp2:masterfrom
akonskarm:reuse_addr
Conversation
tatsuhiro-t
reviewed
Aug 20, 2018
| const boost::posix_time::time_duration &connect_timeout) | ||
| : session_impl(io_service, connect_timeout), | ||
| socket_(io_service, local_endpoint) {} | ||
| socket_(io_service, tcp::v4()) { |
Author
There was a problem hiding this comment.
Hi Tatsuhiro
Unfortunately if we just call socket(io_service) the socket will be created in the closed state.
The socket needs to be in the open state to be able to set the option.
So it's a chicken and egg problem. We want to open on local_endpoint, but need to specify reuse address be fore being able to do so.
Maybe there is an alternative to opening the socket that I'm unaware of.
Best
Alexandros
tatsuhiro-t
reviewed
Aug 23, 2018
| socket_(io_service, tcp::v4()) { | ||
| boost::asio::socket_base::reuse_address option(true); | ||
| socket_.set_option(option); | ||
| socket_.bind(local_ep); |
Member
There was a problem hiding this comment.
I think this should be local_endpoint
| const boost::posix_time::time_duration &connect_timeout) | ||
| : session_impl(io_service, connect_timeout), | ||
| socket_(io_service, local_endpoint) {} | ||
| socket_(io_service, tcp::v4()) { |
Member
|
Cherry picked as 866ac6a with some amends. Thank you for PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Tatsuhiro
Adding reuse addr to get rid of annoying message when re-running same program shortly after closing it.
Best
Alexandros