Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get amount of non-ACK-ed TCP data for the socket?

Linux has ioctl SIOCOUTQ described in man-page tcp(7) that returns amount of unsent data in socket buffers. If I understand kernel code right, all the non-ACKed data is counted as "unsent". The ioctl is available at least since 2.4.x.

Is there anything alike for {Free,Net,Open,*}BSD, Solaris, Windows?

like image 682
darkk Avatar asked Feb 27 '09 16:02

darkk


1 Answers

There are (at least) two different pieces of information you might want: the amount of data that hasn't been sent yet, and the amount of data that's been sent-but-not-ACK-ed.

On Linux: SIOCOUTQ is documented to give the amount of unsent data, but actually gives the sum of (unsent data + sent-but-not-ACK-ed data). A recent patch (Feb 2016) made it possible to get the actual unsent data from the tcpi_notsent_bytes field in the TCP_INFO struct.

On macOS and iOS: getsockopt(fd, SOL_SOCKET, SO_NWRITE, ...) is just like SIOCOUTQ: it's documented to give the amount of unsent data, but actually gives the sum of (unsent data + sent-but-not-ACK-ed data). I don't know any way to get more fine-grained information.

On Windows: GetPerTcpConnectionEStats with the TcpConnectionEstatsSendBuff option gives you both unsent data and sent-but-not-ACK-ed data as two separate numbers.

I don't know how to get this information on other operating systems.

like image 117
Nathaniel J. Smith Avatar answered Sep 28 '22 00:09

Nathaniel J. Smith