簡體   English   中英

如何在異步讀取Boost Asio C ++上獲取已傳輸的字節數

[英]How can I get the amount of transferred bytes on asynchronous reading boost asio c++

正如我在Boost :: asio中看到的那樣,異步讀取函數不會返回傳輸的字節數,但普通讀取函數會返回。 使用async_read_some時如何獲取傳輸的字節數? (參數:緩沖區,處理程序)

所有形式的async_read期望該形式的ReadHandler ”回調

void handler(
  const boost::system::error_code& error, // Result of operation.

  std::size_t bytes_transferred           // Number of bytes copied into the
                                          // buffers. If an error occurred,
                                          // this will be the  number of
                                          // bytes successfully transferred
                                          // prior to the error.
); 

回調的第二個參數是讀取的字節數。

讀取完成后,異步讀取函數將調用“處理程序”函數(或函數對象)。 傳輸的字節數傳遞給該函數; 函數的簽名必須是:

void handler(
    const boost::system::error_code& error, // Result of operation.
    std::size_t bytes_transferred           // Number of bytes read.
);

讀取處理程序的要求在此處記錄

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM