# LINUX socket SIOCOUTQ获取发送队列信息

C: How to tell the status of a socket
by George Michael|Published 30 October 2011
If you are trying to check if a socket is empty but you cannot use select(), because what you need is to check the write buffers instead of the read ones just to be sure that you have successfully managed to send all data to your peers before terminating, or if you want to tell if a socket buffer is full.

You can use the ioctl to find out.

To check a write buffer if it empty (assuming you have already put data there and want to check if they were consumed):

ioctl(fd, SIOCOUTQ, &pending);
Where fd is the socket’s file descriptor and pending the variable were the remaining size of data will be returned.

To check a read buffer if it empty (assuming someone has already put data there and you want to check if they there is any without consuming them):

ioctl(fd, SIOCINQ, &pending);
*note the difference on the second parameter, where we change the flag from SIOCOUTQ to SIOCINQ
Among other includes be sure to add these:

#include <sys/ioctl.h>
#include <linux/sockios.h>

linux提供了ioctl(fd, SIOCOUTQ, &count)方法来查询一个tcp socket的write buffer是否清空。发送方一般可以用这个方法来判断对端是否收到报文。

CLIENT端实际上已经收到了SERVER发送的报文，开始进行下一步动作。 但是SERVER端的out queue始终显示没有发送完毕。