Skip to content

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#1212
akonskarm wants to merge 1 commit intonghttp2:masterfrom
akonskarm:reuse_addr

Conversation

@akonskarm
Copy link
Copy Markdown

Hi Tatsuhiro

Adding reuse addr to get rid of annoying message when re-running same program shortly after closing it.

Best
Alexandros

const boost::posix_time::time_duration &connect_timeout)
: session_impl(io_service, connect_timeout),
socket_(io_service, local_endpoint) {}
socket_(io_service, tcp::v4()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tcp::v4() required?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you.

socket_(io_service, tcp::v4()) {
boost::asio::socket_base::reuse_address option(true);
socket_.set_option(option);
socket_.bind(local_ep);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you.

@tatsuhiro-t
Copy link
Copy Markdown
Member

Cherry picked as 866ac6a with some amends. Thank you for PR.

@tatsuhiro-t tatsuhiro-t added this to the v1.33.0 milestone Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants