delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/03/25/01:18:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Peter Stephens" <ptfoof AT sbcglobal DOT net>
To: <cygwin AT cygwin DOT com>
Subject: recv and errno during a connection reset/closed by peer
Date: Fri, 25 Mar 2005 01:23:00 -0500
Message-ID: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAAUKQItienSEKG+9226yKd5cKAAAAQAAAAABEV8lCYiUqikvlg/nhWLAEAAAAA@sbcglobal.net>
MIME-Version: 1.0

I am writing a program to handle messages on a TCP/CONNECTION based setup.
I have verified that I can receive the messages I want, both blocking and
non-blocking.  I want to be in non-blocking mode.

When in blocking mode I can detect a loss of the connection simply by
waiting for a return of '0' from recv.  Easy enough.

When in non-blocking mode I thought I would be able to get a return from
recv of '-1' and then check errno, but it never seems to be anything but
'11', or EAGAIN.  This seems to be true whether I MSG_PEEK or not.

I have included my code below.  The intention is that for recv returns
greater than zero, there is a message and I should process it and get ready
for the next one.  For recv returns of '0' I should do nothing and for recv
returns of '-1' I should handle per errno.

Seems easy enough, but no matter what I have tried I can only get a recv
return of EAGAIN.

Any help would be appreciated..

Pete Stephens
ptfoof AT sbcglobal DOT net

         rcv_length = recv(threadarg->new_fd,NULL,NULL,MSG_PEEK);
         if(rcv_length > 0)
         {
		  // actually get the message
		  rcv_length = pmsg->get_message();

           // add message to list to be processed
           station_message_list.insertAtFront(pmsg);
           badge_station_state = STATION_THREAD_MSG_INIT;
         }
         else if(-1 == rcv_length)
           {
             switch(errno)
               {
               case EAGAIN :// no messages
                 break;
               case EBADF :
                 cerr << "Bad file descriptor" << endl;
                 break;
               case ECONNRESET :
                 cerr << "Connection reset" << endl;
                 break;
               case EINTR :
                 cerr << "Signal interrupt" << endl;
                 break;
               case ENOTCONN :
                 cerr << "Not connected" << endl;
                 break;
               case ENOTSOCK :
                 cerr << "Not a socket" << endl;
                 break;
               case EOPNOTSUPP :
                 cerr << "Not supported" << endl;
                 break;
               case ETIMEDOUT :
                 cerr << "Timed out" << endl;
                 break;
               default :
                 cerr<<"Unknown" <<endl;
                 break;
			}
		}

Peter A. Stephens
ptfoof AT sbcglobal DOT net


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019