i'm using boost asio library to read the content from the tcp socket. My code looks like this
std::string completeBuffer="";
std::string TcpConnection::readMessage()
{
LOG4CPLUS_DEBUG(logger, "Start Listener for Reading Message from Connection");
boost::system::error_code error;
boost::asio::async_read(socket, boost::asio::buffer(buffer),
boost::bind(&TcpConnection::handleRead, this, buffer, boost::asio::placeholders::error));
return buffer.data();
}
void TcpConnection::handleRead(boost::array<char, TcpConnection::BUFFER_SIZE> buf, const boost::system::error_code& error)
{
if(!error)
{
LOG4CPLUS_INFO(logger, "READ Message " << buf.data());
compl开发者_C百科eteBuffer.append(buf.data());
buf.assign(0);
readMessage();
}
}
Now i'm making the call from some other class to readMessage()
. whenever the BUFFER_SIZE
is reached the handleRead
gets called and the content gets appended.
now the question is say the BUFFER_SIZE
is 50, and the whole message size is 75, handleRead
is called only once and the buffer waits to be filled for the handleRead
to be called for the second time.
Is there a way to set the EOM character or string for asio to return whenever its reached.
Found the answer async_read_until
精彩评论