11

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?

darkk
  • 824
  • 7
  • 13

2 Answers2

10

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.

Nathaniel J. Smith
  • 11,613
  • 4
  • 41
  • 49
  • Has anybody got GetPerTcpConnectionEStats() reading TcpConnectionEstatsSendBuff to work on Windows? I have tried it, but I do not get reasonable values. I guess, this information must be explicitly enabled, but when I try to enable it using SetPerTcpConnectionEStats(), I get an access denied error. :-( – Mario Klebsch Jun 01 '23 at 07:18
0

Since TCP/IP is implemented as a stream device, it might be possible to take a kernel dive and get the queue->q_count (number of bytes on the queue).

  • Of course it's possible to patch kernel and get required information. I was wondering about some existing API. – darkk Jun 03 '09 at 18:32