Subject: sendto() and ENOBUFS question..
To: None <tech-net@netbsd.org>
From: sudog <sudog@sudog.com>
List: tech-net
Date: 05/14/2002 14:16:34
I am writing a high-performance UDP-based networking system and while I've 
written a kludgy solution, I have the nagging feeling I'm not doing something 
'properly'.

During output I'll select on a socket to wait for writeable status. When it 
returns, I try writing a single packet. Often, though, the sendto() call 
returns the error ENOBUFS, which indicates that the network output queue is 
full and I need to back off some.

My question is: Is there a simple way to detect just *how* ready the socket 
is for writing? My concept of what's going is that the socket may be ready 
for writing, but it may only be ready for 1 byte (or less than my packet size 
at any rate). Thus when I try writing, there isn't enough room (though there 
is *some* room) and the thing fails.

Currently what I'm doing is just waiting for progressively longer periods of 
time until a sendto() *IS* successful and backing off, then stepping it up to 
test faster stability.

I realize that an exponential back-off is "the right way to do it" but..  is 
there another way?

Thanks for any comments, suggestions, criticisms, etc. :)

Sincerely,
Marc Tooley