Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

winsock send function with WSAENOBUFS and WSAEWOULDBLOCK errors

Status
Not open for further replies.

jasonzhangx

Programmer
Mar 12, 2002
8
US
I am using winsock's send function to send msgs. I set the socket as nonblocking and and buff size (option SO_SNDBUF) as 2048. All msgs's length are the same and less than 2048. My program runs in about 14 hours and got WSAENOBUFS error (no buffer space is available).

If the option SO_SNDBUF is not set, the program would get WSAEWOULDBLOCK error every 30 minutes or so.

Any suggestions will be greatly appreciated.

Jason
 
I have recently experienced similar problems. I believe WSAEWOULDBLOCK error is caused due to it trying to read the socket when no data is available. Since nothing is available, it would have to block in order to get the number of bytes you are trying to read. So, what to do depends on your program. Ideally if you are non-blocking, there's other functions/etc. to do while waiting for data, so exit the read function, do your other stuff, then come back. (More or less, ignore the WOULDBLOCK error, do other stuff, then try again later.) It might take a while for this error to normally appear if the sender and receiver are well synchronized (i.e., sender keeps the pipe "full" for the reader), but its bound to get out of sync once in a while.

The reason why it might be overflowing your buffer with SO_SNDBUF set to 2048 is that you might have a similar synchronization issue between sends and reads, where perhaps 2 messages are in the buffer instead of the expected 1 message, which would be too large for your buffer. So if you insist on setting SO_SNDBUF, try to make it at least 2-3x your message size to deal with synchronization issues, or just leave it turned off.

Enjoy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top