|
Boost : |
From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2005-10-03 17:01:02
Hi Dick,
--- BRIDGES Dick <Dick.Bridges_at_[hidden]> wrote:
> Everything works fine except when I (1) connect a client;
> (2) ^C the server; (3) try to restart the server - which, as
> expected, yields "Address already in use".
>
> Mumbling something about defaulting modern socket libraries
> to SO_REUSEADDR,
Do you think I should change the default to set SO_REUSEADDR to true?
At the moment I leave all options to default to whatever the OS
provides. Is there a good reason why all OSes (that I know of) have it
default to false I wonder? Or is it just historical?
> I started trying to figure out where to call
> set_option(stream_socket::reuse_address(true)) - and can't
> work it out. I've set_option() on sockets and the acceptor
> but can't make the acceptor reuse the address as long as the
> connection that was established is still in TIME_WAIT. Do you
> have an example that shows how this can be done?
asio::ipv4::tcp::endpoint endpoint(port);
acceptor_.open(endpoint.protocol());
acceptor_.set_option(asio::socket_acceptor::reuse_address(true));
acceptor_.bind(endpoint);
acceptor_.listen();
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this,
asio::placeholders::error));
(From the new http example I've written:
http://cvs.sourceforge.net/viewcvs.py/asio/asio/src/examples/http/server/server.cpp?rev=1.1&view=markup).
Cheers,
Chris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk