Boost logo

Boost :

From: BRIDGES Dick (Dick.Bridges_at_[hidden])
Date: 2005-10-03 11:19:25

I submitted this question to boost-users Friday but it occurred to
me that it should have been posted here. Apologies if I've erred.

I created a server something like this:

handle_accept(){ do_the_right_thing(); }

Class Foo {
  socket_acceptor acceptor_;

  Foo(demuxer& d)
    : acceptor_( d, ipv4::tcp::endpoint(2525)){}

  Example(demuxer& d) {
    stream_socket* p = new stream_socket(d);
    acceptor_.async_accept(p, handle_accept);

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, 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?


Dick Bridges

Boost list run by bdawes at, gregod at, cpdaniel at, john at