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读取到数据或出错就返回,不一定读完了整个包。 

posted @ 2017-03-08 10:55  korman  阅读(3376)  评论(0)    收藏  举报