Boost logo

Boost Users :

From: george (george13p_at_[hidden])
Date: 2006-10-21 12:15:49


hello,

I start using asio in my project and I don't know how to reuse a socket...
some code:

void server(asio::io_service& io_service, short port)
{
  tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
  for (;;)
  {
    tcp::socket *sock=new tcp::socket(io_service);
    a.accept(sock);
    session(sock);
  }
}

void session(tcp::socket *sock)
{
  sock->read(...);
    ....
  sock->send("reply");
}

when I send the first request everything is ok but when I try for a second one I
never get a reply or an error from the server...

The easy way would be to have a thread/connection model so I could block each
thread waiting to a socket but I want to use a thread-pool for my server so I
want to know if there is any callback parameter I could pass to my socket and
when there is data availiable in the socket the asio would fire the callback
function .

thanks in advance,
george


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