|
Boost : |
From: Pedro Lamarão (pedro.lamarao_at_[hidden])
Date: 2006-11-16 07:07:05
berserker_r escreveu:
> void Session::handle_read(const asio::error_code& err, size_t length)
> {
> --op_count_;
>
> if (!err)
> {
> read_data_length_ = length;
> ++unsent_count_;
> if (unsent_count_ == 1)
> {
> very_very_long_operation(); // Process the client request
>
> op_count_ += 2;
> std::swap(read_data_, write_data_);
> async_write(socket_, buffer(write_data_, read_data_length_),
> strand_.wrap(
> boost::bind(&session::handle_write, this,
> placeholders::error)));
> socket_.async_read_some(buffer(read_data_, block_size_),
> strand_.wrap(
> boost::bind(&session::handle_read, this,
> placeholders::error,
> placeholders::bytes_transferred)));
> }
> }
>
> if (op_count_ == 0)
> io_service_.post(boost::bind(&session::destroy, this));
> }
>
> Session::very_very_long_operation() takes a lot of time :) I need in the
> meanwhile to be able in the server to accept new connections, how can I do
> that?
You can rework your read handler to do all I/O necessary, and to submit
the obtained data to a work queue somewhere else.
Another thread would then dispatch work items from this work queue to
worker threads.
After the work is finished, the item would be moved to an exit queue,
with a response for the peer, or something.
Also, shouldn't this thread live in the boost-users list?
-- Pedro Lamarão
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk