I am creating a TCP connection from my linux program with boost.asio. I wonder how do I get the value of its congestion window (cwnd) from the program? The only way I know of is to parse /proc/net/tcp
, but this does not feel right. I'd rather use a dedicated syscall to get this info.
A solution to a similar question (How to monitor cwnd and ssthresh values for a TCP connection?) suggests using TCP Probe, but it feels even less appealing.
So what is the best way to get the value of cwnd?
It turned out getsockopt()
is able to return the same tcp_info
when called with TCP_INFO
option:
tcp_info tcpi = {};
socklen_t len = sizeof(tcp_info);
getsockopt(tcp_socket, SOL_TCP, TCP_INFO, &tcpi, &len);
tcpi.tcpi_snd_cwnd; // <-- CWND