HELP: reading from a closed TCP connection

HELP: reading from a closed TCP connection

Post by Zeta Gund » Wed, 15 May 1996 04:00:00



Hi,

        what is the consequence of reading from a TCP socket but the other
end has been closed? Will the data received be retained until I read it?

        Thanks.

-David

 
 
 

HELP: reading from a closed TCP connection

Post by Andrew Gier » Wed, 15 May 1996 04:00:00



Quote:>Hi,

>       what is the consequence of reading from a TCP socket but the other
>end has been closed? Will the data received be retained until I read it?

>       Thanks.
>-David

If the other end of the socket was closed normally, then any data that
you have not read is buffered until you *do* read it, and then all
subsequent read() or recv() calls return 0.

If the other end was aborted, then buffered data may be discarded
and read() or recv() calls will return -1 with a suitable value
in errno.

You might want to take a look at the unix-socket-faq, regularly
posted here and in news.answers, comp.answers and comp.unix.answers,
and also available at:

  http://www.auroraonline.com/sock-faq
  http://kipper.york.ac.uk/~vic/sock-faq
  ftp://rtfm.mit.edu/pub/usenet/news.answers/unix-faq/socket


"How is this place run - is it an anarchy?"
"No, I wouldn't say so; it is not that well organised..."