boost::asio::buffer: Getting the buffer size and preventing buffer overflow?

前端 未结 3 1360
独厮守ぢ
独厮守ぢ 2020-12-29 14:17

I have the two following functions for sending and receiving packets.

void send(std::string protocol)
{
    char *request=new char[protocol.size()+1];
    re         


        
3条回答
  •  别那么骄傲
    2020-12-29 14:50

    I think your question is confusing, but this might help:

    void receive() {
      enum { max_length = 1024 };
      char reply[max_length];
      size_t reply_length;
      std::cout << "Reply is: ";
      while ( (reply_length = ba::read(s, basio::buffer(reply, max_length))) > 0) {
        std::cout.write(reply, reply_length);
      }
      std::cout << "\n";
    }
    

提交回复
热议问题