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