Keynan
Keynan

Reputation: 1346

How do you get the current RTT estimation for a tcp socket?

Specifically in C, for *nix systems.

Upvotes: 1

Views: 2676

Answers (1)

Ctx
Ctx

Reputation: 18420

You can use the linux-specific socket option TCP_INFO for that (defined in linux/tcp.h)

struct tcp_info ti;
socklen_t tisize = sizeof(ti);
getsockopt(fd, IPPROTO_TCP, TCP_INFO, &ti, &tisize);

Now the rtt-estimation is in ti.tcpi_rtt (unit is milliseconds). There are several more interesting values, just look into the structure tcp_info.

Upvotes: 10

Related Questions