Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
I have a server process that needs to reuse a TCP socket. So I would like
it to always do a passive close. To do this I do the following
char c;
int tmp;
tmp = read(TCPsocket, &c, 1, 0);
while(tmp >= 0 || (errno != ENOTCONN))
{
tmp = read(TCPsocket, &c, 1, 0);
}
The TCPsocket is non-blocking so I check whether read() returns -1 for
some other reason like EWOULDBLOCK.
This loop never ends. So my question is whether read() returns 0 or -1
(with ENOTCONN set) when the remote end sends a FIN pkt. What is the usual
method for ensuring that a server only does a passvive close?
Thank you,
Anant.
Post Follow-up to this messageIn article <Pine.GSO.4.58.0504221210280.14072@mamba.cs.Virginia.EDU>,
Anant Padmanath Mudambi <apm9v@mamba.cs.Virginia.EDU> wrote:
> Hi,
> I have a server process that needs to reuse a TCP socket. So I would like
> it to always do a passive close. To do this I do the following
>
> char c;
> int tmp;
> tmp = read(TCPsocket, &c, 1, 0);
> while(tmp >= 0 || (errno != ENOTCONN))
> {
> tmp = read(TCPsocket, &c, 1, 0);
> }
>
> The TCPsocket is non-blocking so I check whether read() returns -1 for
> some other reason like EWOULDBLOCK.
> This loop never ends. So my question is whether read() returns 0 or -1
> (with ENOTCONN set) when the remote end sends a FIN pkt. What is the usual
> method for ensuring that a server only does a passvive close?
If the remote end sends a FIN segment, read() will return 0 when you've
finished reading everything. So change 'tmp >= 0' to 'tmp > 0'.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.