TCP send queue depth

network-programmingtcp

How do I discover how many bytes have been sent to a TCP socket but have not yet been put on the wire?

Looking at the diagram here:
http://www.tcpipguide.com/free/diagrams/tcpswpointers.png

I would like to know the total of Categories 2, 3, and 4 or the total of 3 and 4. This is in C(++) and on both Windows and Linux. Ideally there is a ioctl that I could use, but there doesn't seem to be any.

Best Solution

Under Linux, see the man page for tcp(7).

It appears that you can get the number of untransmitted bytes by ioctl(sock,SIOCINQ ...

Other stats might be available from members of the structure given back by the TCP_INFO getsockopt() call.