joyent/libuv — pull request #1063 by rtarnell (2013-12-29 02:15:54+00:00)
Title: unix: optimise UDP buffer allocation

Instead of always allocating a 64KB buffer, use FIONREAD to check the size of the next incoming packet.

I intended to use FIONREAD here to check if any packet is pending, and avoid allocating a buffer (simply returning instead) if no packet is pending. However, this isn't possible with FIONREAD: if a zero-byte packet is pending, we would spin forever as the socket will appear readable but we'll never read the packet.

Still, this is a minor worthwhile optimisation.