mardi 26 novembre 2019

Boost TCP Server not reading all incoming data

I am making a Boost TCP Server and following this example.

https://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/example/cpp11/echo/async_tcp_echo_server.cpp

I realised that not all the messages sent by client are received by the server and after further reading i realised the problem lies with this function.

void do_read()
  {
    auto self(shared_from_this());
    socket_.async_read_some(boost::asio::buffer(data_, max_length),
        [this, self](boost::system::error_code ec, std::size_t length)
        {
          if (!ec)
          {
            do_write(length);
          }
        });
  }

Since we are using socket_.async_read_some this function can exit before reading all the messages.

Can this function be modified or how should i make a server which will read all the incoming messages.

Aucun commentaire:

Enregistrer un commentaire