non-blocking socket, recv returnes 0

non-blocking socket, recv returnes 0

Post by Andrew Ar » Tue, 07 May 2002 03:15:03



so, non-blocking socket

select says the socket is ready for read, but recv returnes 0 - this
means connection closed or this is some error?

before calling recv one success 'send' is done

if it is connection failed - shoud the socjet be SET in exceptions
set?

Andrew

 
 
 

non-blocking socket, recv returnes 0

Post by Joe Halpi » Tue, 07 May 2002 03:44:43



> so, non-blocking socket

> select says the socket is ready for read, but recv returnes 0 - this
> means connection closed or this is some error?

It means connection closed.

Some servers accept and then immediately close connections depending
on some given condition. For example, a server may refuse to accept a
connection from a particular IP address, or from anything not on the
local subnet. You'd have to check to see if the server you're
connecting to is doing something like that.

Quote:> before calling recv one success 'send' is done

Sending one buffer will not tell you anything like that really. A good
return only means that the buffer was successfully copied to the TCP
send queue. It doesn't mean that the data were sent or received.

A second or subsequent send (hard to predict how many you'd have to
do) would return -1 with ECONNRESET.

Quote:> if it is connection failed - shoud the socjet be SET in exceptions
> set?

The exception set is not to indicate errors, even though man pages and
even SUS says it does. It indicates that an urgent message is pending.

I believe the socket programming FAQ gives a better explanation of
stuff like this:

http://www.developerweb.net/sock-faq/

Joe

 
 
 

non-blocking socket, recv returnes 0

Post by Andrew Ar » Wed, 08 May 2002 06:57:17




> Joe

Joe, thanx you for you time and patience - this info was really usefull for me!

Thanx you  again

Andrew Arro

 
 
 

non-blocking socket, recv returnes 0

Post by Joe Halpi » Wed, 08 May 2002 08:45:28



> Joe, thanx you for you time and patience - this info was really
> usefull for me!

You're welcome, but keep in mind that I didn't cover all the bases. If
you're serious about network programming, invest in Stevens "Unix
Network Programming" Volume 1, second edition. Also read the FAQS for
comp.unix.programmer, the RFCs, et al.

Bookmark http://www.rfc-editor.org/rfcsearch.html. That's where The
Truth is.

Joe

 
 
 

non-blocking socket, recv returnes 0

Post by Andrew Ar » Thu, 09 May 2002 00:44:34




> > Joe, thanx you for you time and patience - this info was really
> > usefull for me!

> You're welcome, but keep in mind that I didn't cover all the bases. If
> you're serious about network programming, invest in Stevens "Unix
> Network Programming" Volume 1, second edition. Also read the FAQS for
> comp.unix.programmer, the RFCs, et al.

> Bookmark http://www.rfc-editor.org/rfcsearch.html. That's where The
> Truth is.

> Joe

my dream for last 3 days is Stevens "Unix Network Programming", but it
is still not published in Russian - and on Amazon is cost about $70 +
delivery - this will be $100... Too much for a book for me :(( Have
you ever seen this online?
 
 
 

non-blocking socket, recv returnes 0

Post by Joe Halpi » Thu, 09 May 2002 02:21:56





> my dream for last 3 days is Stevens "Unix Network Programming", but it
> is still not published in Russian - and on Amazon is cost about $70 +
> delivery - this will be $100... Too much for a book for me :(( Have
> you ever seen this online?

I don't think it's online, but you can get the source code from the
book, as well as a number of other publications at
http://www.kohala.com/start/

vsevo khoroshevo

Joe

 
 
 

non-blocking socket, recv returnes 0

Post by Andrew Ar » Thu, 09 May 2002 16:14:31






Privet from Russia
> vsevo khoroshevo

> Joe

when i do select for reading and recv returnes 0, should the strerror
be

"Operation now in progress"? this makes me think i have an error
somewhere - or this is a valid reply in case of connection "closed by
server"?

 
 
 

non-blocking socket, recv returnes 0

Post by Andrew Giert » Thu, 09 May 2002 19:47:39


 Andrew> when i do select for reading and recv returnes 0, should the
 Andrew> strerror be

if recv returns 0, then the value of errno is irrelevent - errno is set
only if recv returns -1

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>