Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost asio reuse address
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2018-01-07 23:27:28


On 3/01/2018 19:37, Sharma, Nishant wrote:
> Just wanted to know if setting the following option on acceptor should
> be ever done or not.. When should this be used..
>
>
> acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
>
> The reason I am asking this is because I have a server application which
> crashed but the socket did not close. So, the next time, I was bringing
> up the server, I get the error :
>
> Error occured! Error code = system:98. Message: bind: Address already in use
>
> But, even giving the option above, it is not working fine.
>
> I referred to the URL :
> https://stackoverflow.com/questions/34596638/boost-asio-so-reuseport to
> figure out the steps in which acceptor should be created from this link.

The option merely sets the corresponding flag on the underlying native
socket. So the behaviour is the same as whatever that does.

By default, after TCP ports are closed they are still "reserved" for a
brief time to allow stray TCP packets addressed to the previous holder
of that port to be properly discarded; without this there can be
problematic cross-talk from the tail end of a prior conversation,
especially if the connection is interrupted rather than gracefully closed.

It should not be enabled for clients, unless in the rare case where a
client needs to bind to a specific port for firewall or dumb-protocol
reasons. It might be necessary to enable it for servers if a new server
instance is spawned immediately after killing the old instance.

In no case will it allow you to open a port that is still actually in
use by a still-running previous instance. The previous instance must be
killed first.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net