Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errno 35 (EAGAIN) returned on recv call

Tags:

c

macos

sockets

I have a socket which waits for recv and then after receiving data, sends data forward for processing. However, then it again goes for recv, and this time it receives nothing returns -1 and when printed the errno it prints 35 (which is EAGAIN).

This happens only on MAC OS Lion operating system, for other OS this runs perfectly fine

do{
 rc = recv(i, buffer, sizeof(buffer), 0);
 if (rc < 0){
      printf("err code %d", errno); 
 }
 if(rc == 0){ 
      //Code for processing the data in buffer 
      break; 
 } 
      ....
}while(1);

EDIT: Corrected indentation and errno

like image 499
VijayKumar Avatar asked Jan 30 '13 01:01

VijayKumar


1 Answers

You either set the socket to non-blocking mode or enabled the receive timeout. Here's from recv(2) on a mac:

The calls fail if:

[EAGAIN] The socket is marked non-blocking, and the receive operation would block, or a receive timeout had been set, and the timeout expired before data were received.

Edit 0:

Hmm, apologies for quoting again. This time from intro(2):

11 EDEADLK Resource deadlock avoided. An attempt was made to lock a system resource that would have resulted in a deadlock situation.

...

35 EAGAIN Resource temporarily unavailable. This is a temporary condition and later calls to the same routine may complete normally.

Just use strerror(3) to figure out the actual issue.

like image 67
Nikolai Fetissov Avatar answered Nov 06 '22 20:11

Nikolai Fetissov