tags:

views:

708

answers:

1

I have an implementation which uses ioctl(FIONREAD) to determine the number of pending octets in the Raw Socket receive buffer in Linux and then call a recv on that.

I read somewhere that the ioctl interface for raw sockets in Linux does not actually return the actual pending octets. Is this correct?

I am asking because I am loosing some messages every now and then on high loads and so far havent been able to figure out where. Is their a better way to figure out the number of pending octets in the Raw Socket.

+1  A: 

There is always the possibility that the kernel will drop packets if your application is not able to keep up with the packet rate (as the kernel buffer is not unbounded).

BTW, why do you need to know the number of octets anyway? As these are packet sockets, the length of a packet will always be limited by the maximum frame size of the network interface, so just pass a large enough buffer to recv.

Having said that, if performance is critical, you should look into PACKET_MMAP support on Linux.

cmeerw
the implementation I work with uses ioctl system call to determine the number of unread packets. I have changed that to hardcode it to 2048 and I am seeing no more packet loss. Thanks.
Aditya Sehgal