This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: recv and errno during a connection reset/closed by peer


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

Brian

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]