2

In UNIX domain socket (AF_UNIX Type & DGRAM) , when a reader is slow , the no. of packets queued is 'max_dgram_qlen' . Is there any way to identify bytes occupied queued (or) no. of more bytes free in the queue either on the sender or receiver side. Or atleast , the writer is blocked when the queue is full. Is there any way identify the writer block event ? Thanks in advance.

3
  • 1
    fyi... AF_INET+SOCK_DGRAM is a not a Unix domain socket, it's a TCP/IP socket using UDP. Commented Oct 18, 2016 at 8:00
  • Possible duplicate of: stackoverflow.com/questions/16427842/… . But I think you asking for how many bytes are queued on the sender side. Commented Oct 18, 2016 at 8:01
  • I have edited the question.And thanks for your suggestion. Commented Oct 18, 2016 at 9:23

2 Answers 2

2

You should set your file descriptor as nonblocking and use select to determine if it can be written to at the current time.

Sign up to request clarification or add additional context in comments.

Comments

1
  1. 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*/
  1. Based on the error message returned by the send() function , we can identify the buffer full event.By checking the error==ENOBUFS you can identify the buffer full.

1 Comment

2 is wrong. It refers to the device buffer, not the socket buffer. "ENOBUFS: The output queue for a network interface was full. This generally indicates that the interface has stopped sending, but may be caused by transient congestion. (Normally, this does not occur in Linux. Packets are just silently dropped when a device queue overflows.)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.