Home > Archive > Unix Programming > April 2005 > passive close
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]
|
|
| Anant Padmanath Mudambi 2005-04-22, 8:57 pm |
| 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.
| |
| Barry Margolin 2005-04-23, 3:57 am |
| In 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 ***
|
|
|
|
|