2013-04-22 47 views
0

正如我在Boost :: asio中看到的那樣,異步讀取函數不會返回傳輸的字節量,而是正常的讀取函數。當我使用async_read_some時,如何獲得傳輸的字節數量? (PARAMS:緩衝,處理器)如何獲得異步閱讀提升傳輸字節量asio C++

+1

你看一看的文檔?這是一個非常基本的信息,它出現在任何與套接字相關的示例或函數參考中。http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/ReadHandler.html – 2013-04-22 19:14:41

回答

4

All forms of async_read期望形式

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. 
); 

回調的第二個參數的「ReadHandler」回調將被讀取的字節數。

2

讀取完成後,異步讀取函數調用「處理函數」函數(或函數對象)。傳輸的字節數傳遞給該函數;該函數的簽名必須是:

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

讀處理程序的要求都記錄here