Gonzalo Garramuno
2014-02-26 19:28:07 UTC
I am using asio asynchronically. I have:
void tcp_session::start_read()
{
// Set a deadline for the read operation.
// input_deadline_.expires_from_now(boost::posix_time::seconds(30));
// input_deadline_.expires_at(boost::posix_time::pos_infin);
// Start an asynchronous operation to read a newline-delimited message.
boost::asio::async_read_until(socket(), input_buffer_, '\n',
boost::bind(&tcp_session::handle_read,
shared_from_this(),
boost::asio::placeholders::error));
}
void tcp_session::handle_read(const boost::system::error_code& ec)
{
if (stopped())
return;
if (!ec)
{
// Extract the newline-delimited message from the buffer.
std::string msg;
std::istream is(&input_buffer_);
is.exceptions( std::ifstream::eofbit );
try {
while ( std::getline(is, msg) )
{
// parse msg
}
}
catch ( std::ios_base::failure& e )
{
}
}
My problem is that when the data sent is too long ( > 256 chars ) I end
up reading only 256 chars or so and my parsing fails. I am obviously
doing something wrong but I do not know how to fix it.
void tcp_session::start_read()
{
// Set a deadline for the read operation.
// input_deadline_.expires_from_now(boost::posix_time::seconds(30));
// input_deadline_.expires_at(boost::posix_time::pos_infin);
// Start an asynchronous operation to read a newline-delimited message.
boost::asio::async_read_until(socket(), input_buffer_, '\n',
boost::bind(&tcp_session::handle_read,
shared_from_this(),
boost::asio::placeholders::error));
}
void tcp_session::handle_read(const boost::system::error_code& ec)
{
if (stopped())
return;
if (!ec)
{
// Extract the newline-delimited message from the buffer.
std::string msg;
std::istream is(&input_buffer_);
is.exceptions( std::ifstream::eofbit );
try {
while ( std::getline(is, msg) )
{
// parse msg
}
}
catch ( std::ios_base::failure& e )
{
}
}
My problem is that when the data sent is too long ( > 256 chars ) I end
up reading only 256 chars or so and my parsing fails. I am obviously
doing something wrong but I do not know how to fix it.