In Linux, development often encounters many errors (setting errno), where Eagain is one of the more common errors (for example, in non-blocking operations).
Using Write\send to send datagrams Eagain:resource temporarily unavailable error under Linux
First of all, I set the socket to asynchronous, and then when I use write to send data, the way is to loop a large amount of data, because it is asynchronous, Write\send will send the data submitted to the send buffer is immediately returned, do not need to confirm the data received. In this case, it is quite possible that the send buffer is filled up, causing the write\send to no longer commit the data to be sent to the buffer. So there is the resource temporarily unavailable error, Eagain meaning is also obvious, is to you try again.
Literally, it is a hint to try again. This error often occurs when the application is doing some non-blocking (non-blocking) operations (for files or sockets). For example, open the file/socket/fifo with the O_nonblock flag, if you do a sequential read operation and no data is readable. At this point the program does not block up and waits for the data to be ready to return, and the Read function returns an error eagain, prompting your application to now have no data to read please try again later.
For example, when a system call (such as fork) fails because there is not enough resources (such as virtual memory), the return eagain prompts it to be called again (perhaps next time it succeeds).
Linux-non-blocking socket programming handles Eagain errors
What does it mean when a non-blocking socket on Linux receives data that often appears resource temporarily Unavailable,errno code (eagain)?
This indicates that you have a blocking operation in non-blocking mode, which returns the error if the operation is not completed, which does not break the synchronization of the socket, regardless of the next loop and then recv. For non-blocking sockets, Eagain is not an error. On VxWorks and Windows, Eagain is named Ewouldblock.
Additionally, if EINTR is present as errno 4, the error description interrupted system call, the operation should also continue.
Finally, if the return value of recv is 0, it indicates that the connection has been disconnected and our receive operation should end.
Ireadsizeonce=read (iopencom,rxbuf+ireadsize,1024);
if (ireadsizeonce! = ZERO)
{
if (ireadsizeonce! = Eagain)
{
Continue
}
Else
{
Stccomapilog.logerror ("Read serial operation error");
return (FUN_ERROR);
}
}
Meanings and processing of eagain and EINTR macros under Linux programming