|
Boost Users : |
From: Axel (axel.azerty_at_[hidden])
Date: 2008-04-03 06:22:30
Hello
I m a new Boost user, (and a little less but still new C++ developper)
and I d like to find some advices about how to manage network
communications.
I m writing a daemon and I use boost::asio::async_read_until() to fill a
boost::asio::streambuf buffer.
Here's the corresponding handler :
void Session::handleRecv(const boost::system::error_code& error, size_t
size)
{
if(error.value() == 0 && size > 0)
{
size -= separator.size();
istream command_stream(&buffer_);
char * command_chr = new char[size];
command_stream.read(command_chr, size);
string command = command_chr;
cout << "COMMAND " << command << endl;
buffer_.consume(separator.size());
//doSomethingWithTheCommand(command);
this->start();
}
}
I have some questions regarding this code.
If I don't consume the full buffer_ , as soon as the this->start() is
called, the handlerRecv() is called again. Is this a normal behaviour ?
Is there a better way to extract the command from the buffer_ variable ?
Finally how could I use an iterator of buffer_ without using an external
class (like it's done in
http://asio.sourceforge.net/boost_asio_1_0_0/libs/asio/doc/html/boost_asio/example/http/server3/request_parser.hpp
, example I didn't fully understood)
Thanks in advance.
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