Finding used socket receive-buffer size

I have set the receive buffer size of socket to max.

setsockopt(sd,SOL_SOCKET, SO_RCVBUF,&max,optval);

Am reading data from the socket in a loop(say max 100 bytes per recv)
1
2
3
4
5
while(1)
  {
   int rlen=recv(sd,(void *)buf, 100 , 0);
   //err handle and processing
  }

Assume my process is slow and the buffer(unread message size) is getting full.

Is there a way to find the unread bytes in the receive buffer(without reading them all),just to detect bottleneck?
1
2
3
int numBytes = 0;
if( ioctl( sock_fd, SIOCINQ, &numBytes ) < 0 )
    std::cout << "ioctl failed" << std::endl;


This fills out numBytes with the number of bytes available to be read in the next read() of the socket.

For stream-oriented sockets such as TCP sockets, this would return the number of bytes in the
receive buffer.

For datagram-oriented sockets such as UDP sockets, this would return the size of the next
datagram in the receive buffer.
Thanks
Topic archived. No new replies allowed.