One of my projects on Linux uses blocking sockets. Things happen very serially so non-blocking would just make things more complicated. Anyway, I am finding that often a
I don't suggest this as a first-attempt fix, but if you're all out of options, you can always select()
on the socket with a reasonably long timeout to force it to wait for data.
Is it possible that you're using MSG_DONTWAIT
is being specified as part of your flags? The man
page says EAGAIN
will occur if no data is available and this flag is specified.
If you really want to force a block until the recv()
is somewhat successful, you may wish to use the MSG_WAITALL
flag.
It's possible that you have a nonzero receive timeout set on the socket (via setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,...)
) as that would also cause recv to return EAGAIN
EAGAIN
is generated by the OS almost like an "Oops! I'm sorry for disturbing you.". In case of this error, you may try reading again, This is not a serious or fatal error. I have seen these interrupts occur in Linux and LynxOS anywhere from one a day to 100 times a day.