我有以下代碼來測量從客戶端到服務器的套接字寫入所花費的總時間。 (假設回調方法調用是在成功將數據寫入目標套接字(接收到TCP-ACK)時完成的)。這是否確保 - 這次是數據傳輸的實際「網絡時間」?Boost:套接字讀取/寫入所需的時間爲
void on_successful_read_from_client(const boost::system::error_code& error,
const size_t& bytes_transferred)
{
if (!error)
{
m_telnet_server_write_time = posix_time::microsec_clock::universal_time();
async_write(telnet_server,
boost::asio::buffer(data_from_device_,bytes_transferred),
boost::bind(&bridge::on_successful_send_to_server,
shared_from_this(),
boost::asio::placeholders::error));
}
else
close();
}
void on_successful_send_to_server(const boost::system::error_code& error)
{
if (!error)
{
posix_time::ptime now = posix_time::microsec_clock::universal_time();
if ((now - m_telnet_server_write_time).total_milliseconds() > 0)
{
std::ostringstream log;
log << "Time Taken for server write: " << (now - m_telnet_server_write_time).total_milliseconds() << " ms";
write_log(log.str());
}