How to fix EAGAIN error on recv when socket reconnects?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cgillopez
    New Member
    • Jan 2011
    • 2

    How to fix EAGAIN error on recv when socket reconnects?

    Hello,

    I implented a socket client to communicate to an ip camera with RTSP over HTTP to get teh video from the camera.

    To stablished the communication with the camera, first i have to set an HTTP-GET tunnel, then send the RTSP commands. When the camera loses the connection, the program has to close the tunnel handler, finish the thread and when the process return to the main function, it begins the communication (start the treads, and so on).

    On the reconnection: the http-get tunnel is set ok, i mean, the socket connects and receives a "HTTP OK", so the program sends a RTSP "DESCRIBE" but the recv always return an EAGAIN error. I check with wireshar that the DESCRIBE OK response is sent from the camera, but the recv never gets it.

    Here is the code:
    Code:
          		  //LISTENING...
    		  int theLen=1500; //3000;
    		  int ret=0;
    		  unsigned char receivedData[3000];
    
    
    		  while (c->bFin==false){
    
    			//  ret = read(c->fd_get, receivedData, theLen);
    
    			  //ret= recvfrom(c->fd_get, receivedData, theLen, 0,  (struct sockaddr *) 0, (socklen_t*)0);
    			  ret=recv(c->fd_get, receivedData, theLen, 0);
    			  if (ret == 0)
    			  {
    				  cout << "Server closed connection: 0" << endl;
    
    				}
    				  else
    				  if (ret == -1){
    					fprintf (stderr, "\n[%d]: %s %d\n", __LINE__, strerror (errno), errno);
    
    	cout << "errno" << endl;
    
    							if (errno==EINTR )
    								cout << "EINTR" << endl;
    							if (errno==EAGAIN  )
    								cout << "EAGAIN " << endl;
    Could it be a timeout problem? or a stack problem? How can i solve it?

    Thanks in advance for your help. Best regards.

    cristina
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    EAGAIN basically just means that there was nothing to read at that time but the socket is non-blocking so the function must return. The connection is still good you should just try the read again.

    Comment

    • cgillopez
      New Member
      • Jan 2011
      • 2

      #3
      Thanks banfa for your quick reply, i alredy try waiting a few seconds and reading again, but the recv() still returning -1 (EAGAIN)...

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        That would suggest that no data is being sent.

        Using a monitoring tool, like WireShark, is useful when trying to diagnose communication errors so you can independently see exactly what data is being sent.

        Comment

        Working...