我正在尝试使用 Ubuntu 中的 C++ 程序从套接字统计信息中获取往返时间 (RTT)。网上资源不多。我怎样才能获取 RTT,或者也许有更好的套接字统计替代方法?非常感谢。
更新:
我按照 jxh 的指导进行了操作。我创建了一个套接字并测试了代码。效果很好。但是,由于我最初使用wget,所以我没有套接字的文件描述符。我希望从系统创建的套接字获取 RTT。非常感谢。
最佳答案
由于Ubuntu是Linux系统,您可以使用系统特定的 TCP_INFO
socket option :
TCP_INFO
(since Linux 2.4)block 引用>Used to collect information about this socket. The kernel returns a
struct tcp_info
as defined in the file/usr/include/linux/tcp.h
. This option should not be used in code intended to be portable.引用的结构有一个名为
tcpi_rtt
的成员,这似乎就是您想要的。struct tcp_info info; socklen_t info_len = sizeof(info); int r = getsockopt(sock, IPPROTO_TCP, TCP_INFO, &info, &info_len); // examine info.tcpi_rtt ...
关于c++ - 如何在 C++ 编程中从 wget 创建的套接字中检索 RTT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34388687/