async_read 和 async_read_some 的區別


Start an asynchronous operation to read a certain amount of data from a stream.

template< typename AsyncReadStream, typename MutableBufferSequence, typename ReadHandler> void async_read( AsyncReadStream & s, const MutableBufferSequence & buffers, ReadHandler handler); 

This function is used to asynchronously read a certain number of bytes of data from a stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

  • The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes.
  • An error occurred.

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

 

 

 

Start an asynchronous read.

template< typename MutableBufferSequence, typename ReadHandler> void async_read_some( const MutableBufferSequence & buffers, ReadHandler handler); 

This function is used to asynchronously read data from the stream socket. The function call always returns immediately.

 

總結一下:
      asio::async_read 通常用戶讀取指定長度的數據,讀完或出錯才返回。
      而socket的async_read_some讀取到數據或出錯就返回,不一定讀完了整個包。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM