Unix Programming - recv returns 0; errno = EAGAIN

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2004 > recv returns 0; errno = EAGAIN





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author recv returns 0; errno = EAGAIN
Raja

2004-02-17, 8:33 pm

I have a recv call to a socket and the return value from recv is 0 and
the errno is EAGAIN. There are lots of discussions around this but i
couldnt get a clear picture anywhere.
What are the chances of recv returning 0 and EAGAIN? The manual says
only if recv is -1, you should check for EAGAIN. Should i ignore the
value of errno if recv returns a 0?

Thanks
Raja
Ian Fitchet

2004-02-17, 8:33 pm

raja0576@yahoo.com (Raja) writes:

> couldnt get a clear picture anywhere.


The clear picture is, for all system calls, errno has no useful value
unless the system call has failed.

recv() didn't fail, it told you there were no bytes received. Why
recv() reported no bytes returned is a different problem which you
may wish to ask again regarding.


Man pages are notoriously terse but on the whole they tell you the
facts.

Cheers,

Ian
Andrei Voropaev

2004-02-17, 11:33 pm

On 2004-02-18, Raja <raja0576@yahoo.com> wrote:
> I have a recv call to a socket and the return value from recv is 0 and
> the errno is EAGAIN. There are lots of discussions around this but i
> couldnt get a clear picture anywhere.
> What are the chances of recv returning 0 and EAGAIN? The manual says
> only if recv is -1, you should check for EAGAIN. Should i ignore the
> value of errno if recv returns a 0?


Check if errno was set before call to recv?
Generally, check errno only if return value is -1. No -1 - no error.

Andrei
Nils O. newsgroup user

2004-02-18, 1:34 am

In article <1a26ae5d.0402180127.3e89a257@posting.google.com>, Raja wrote:
> I have a recv call to a socket and the return value from recv is 0 and
> the errno is EAGAIN. There are lots of discussions around this but i
> couldnt get a clear picture anywhere.
> What are the chances of recv returning 0 and EAGAIN? The manual says
> only if recv is -1, you should check for EAGAIN. Should i ignore the
> value of errno if recv returns a 0?

If a call didn't fail, which in this case it did not since
it didn't return -1 ,you shouldn't check errno nor trust its value.

--
Vennlig hilsen/Best Regards
Nils Olav Selåsdal
System Engineer
w w w . u t e l s y s t e m s . c o m
Fletcher Glenn

2004-02-18, 4:34 am



Raja wrote:
> I have a recv call to a socket and the return value from recv is 0 and
> the errno is EAGAIN. There are lots of discussions around this but i
> couldnt get a clear picture anywhere.
> What are the chances of recv returning 0 and EAGAIN? The manual says
> only if recv is -1, you should check for EAGAIN. Should i ignore the
> value of errno if recv returns a 0?
>
> Thanks
> Raja


EAGAIN is not the issue here. When recv return zero, it means EOF for
the socket connection.

--

Fletcher Glenn

Barry Margolin

2004-02-18, 9:34 am

In article <40339D34.4040702@removethisfoglight.com>,
Fletcher Glenn <fletcher@removethisfoglight.com> wrote:

> Raja wrote:
>
> EAGAIN is not the issue here. When recv return zero, it means EOF for
> the socket connection.


Assuming it's a stream socket. If it's a datagram socket, it means you
received an empty messsage.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Fletcher Glenn

2004-02-18, 11:34 am



Barry Margolin wrote:
> In article <40339D34.4040702@removethisfoglight.com>,
> Fletcher Glenn <fletcher@removethisfoglight.com> wrote:
>
>
>
>
> Assuming it's a stream socket. If it's a datagram socket, it means you
> received an empty messsage.
>


This is a direct quote from the man page for recv():

recv() may be used only on a con-
nected socket (see connect(3SOCKET))

--

Fletcher Glenn

David Schwartz

2004-02-18, 12:34 pm


"Fletcher Glenn" <fletcher@removethisfoglight.com> wrote in message
news:403408C2.703@removethisfoglight.com...



[color=blue]
> This is a direct quote from the man page for recv():
>
> recv() may be used only on a con-
> nected socket (see connect(3SOCKET))



What's your point? UDP *sockets* can be connected.

DS



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com