boost::asio::read function hanging

前端 未结 2 2038
-上瘾入骨i
-上瘾入骨i 2021-01-26 23:27

If someone could please help me out, I cannot understand how the boost::asio::read function works in boost asio. In boost\'s example they have it declare the buffer size before

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 00:09

    Usually, you know how much bytes you want to read from the definition of protocol.

    In the opposite case you have to read bytes one by one and observe the error code to stop at the end of connection, file, etc.

    Synchronous methods (for example read) in Boost.Asio are nice for short examples, but in practical use cases you should prefer the asynchronous version async_read, which allows you to cancel or just wait for a next chunk of data without blocking your program.

提交回复
热议问题