如何查明通过 Boost ASIO TCP 套接字连接发送了多少数据?
我有一些指向 boost::asio::io_service
、boost::asio::ip::tcp::endpoint
、boost::asio: 的共享指针:ip::tcp::acceptor
和 boost::asio::ip::tcp::socket
。我接受用户连接并将套接字的shared_ptr传递给我的某个类。它发挥作用。
现在我想要的很简单——统计我的流量。我想获取有关该连接期间发送和接收的数据量的信息。如何从接受的 Boost ASIO TCP 套接字获取此类信息?
I have some shared pointers to boost::asio::io_service
, boost::asio::ip::tcp::endpoint
, boost::asio::ip::tcp::acceptor
and boost::asio::ip::tcp::socket
. I accept users connection and pass shared_ptr of the socket to some class of mine. It does its work.
Now what I want is simple - count my traffic. I want to get information of how much data was sent and received during that connection. How to get such information from accepted Boost ASIO TCP socket?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用异步方法,为
async_read
提供的完成处理程序将指示接收到的字节数。类似地,提供给async_write
的完成处理程序将指示写入的字节数。将正在运行的计数器维护为类的成员是很简单的,在该类中将方法绑定为前面描述的完成处理程序。Assuming you use asynchronous methods, the completion handler given to
async_read
will indicate the number of bytes received. Similarly, the completion handler given toasync_write
will indicate the number of bytes written. It would be trivial to maintain a running counter as a member of a class where you bind methods as the previously described completion handlers.