Boost logo

Boost Users :

Subject: [Boost-users] [asio] accepting all connections in a seperate thread - how?
From: for-gmane (for-gmane_at_[hidden])
Date: 2010-10-10 18:57:57


My server app needs to be "highly responsive".
Ie. it shall handle connection attemps with a higher priority.
Currently it has the following problem:
if a handler function like the one below takes too much time,
then unfortunately no new connections will be handled as long
as the operation below lasts (ie. new connections have to wait).
Which alternatives are there to solve this problem?
(I was thinking of doing the accept in a seperate thread,
but not sure how and whether that would work?)

   void session::handle_read(const boost::system::error_code& error,
     size_t bytes_transferred)
   {
     if (!error)
     {
       // PROBLEM HERE:
       // ... a lengthy job here blocks the whole app (ie. new connections have to wait)
       // ... which coding/design alternatives would solve this problem?

       boost::asio::async_write(socket_,
           boost::asio::buffer(data_, bytes_transferred),
           boost::bind(&session::handle_write, this,
             boost::asio::placeholders::error));
     }
     else
     {
       delete this;
     }
   }


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