delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/03/25/09:25:03

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
Date: Fri, 25 Mar 2005 09:24:45 -0500 (EST)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
Subject: Re: recv and errno during a connection reset/closed by peer
In-Reply-To: <4243C14B.AC1A0432@dessent.net>
Message-ID: <Pine.GSO.4.61.0503250916250.27688@slinky.cs.nyu.edu>
References: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAAUKQItienSEKG+9226yKd5cKAAAAQAAAAABEV8lCYiUqikvlg/nhWLAEAAAAA AT sbcglobal DOT net> <4243C14B DOT AC1A0432 AT dessent DOT net>
MIME-Version: 1.0

On Thu, 24 Mar 2005, Brian Dessent wrote:

> Peter Stephens wrote:
>
> > 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.
> > ...
> >          rcv_length = recv(threadarg->new_fd,NULL,NULL,MSG_PEEK);
>
> Try passing a buffer and length to recv().  The Cygwin code does not
> attempt to do anything with the socket if buf = NULL and len = 0.  (You
> can look at it yourself, file winsup/cygwin/net.cc, functions
> cygwin_recv() and cygwin_recvfrom().)  How would you ever expect recv()
> to return >0 when you don't give it a buffer to put the data into?

AIUI, recv with MSG_PEEK is supposed to return the length of the waiting
data without putting anything in the buffer.

> The POSIX standard doesn't say anything about the behavior of recv()
> when buf=NULL so what you're trying to do must be some nonstandard quirk
> of other systems' libc.

The SUSv6 page on recv also doesn't mention the possibility of the buffer
being NULL.  I'd suggest to the OP to pass in a dummy 1-character buffer
to recv() with MSG_PEEK, e.g.,

	char c;
	...
        rcv_length = recv(threadarg->new_fd,&c,1,MSG_PEEK);

HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

--
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