Boost asio reuse address
Hi, 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. Best Regards, Nishant Sharma
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.
participants (2)
-
Gavin Lambert
-
Sharma, Nishant