Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 May 2001 22:08:29 +0700
From:      "Rashid N. Achilov" <>
To:        Garrett Wollman <>, "Jonathan Graehl" <>
Cc:        <freebsd-net@FreeBSD.ORG>
Subject:   Re: Do I need to close after shutdown if I don't want to leak descriptors? (making sure TCP retransmits all my data)
Message-ID:  <>
In-Reply-To: <>
References:  <000001c0d6d5$87607e80$> <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Wednesday 09 May 2001 02:23, Garrett Wollman wrote:
> <<On Mon, 7 May 2001 02:10:14 -0700, "Jonathan Graehl" 
<> said:
> > Problem: close() does not perform an orderly shutdown, does not resend
> > unacknowledged data - responds with RST to data/acks sent to me
> I suggest that this is a bug.

WinDoze do so. When connection finished, it sends RST instead FIN :-) But it 
isn't good. shutdown() should be called before close().

> > Incomplete solution: shutdown(SHUT_RDWR), but then what?  Will the OS
> > close the fd for me once the other end acknowledges, or better yet,
> > closes its end as well, or do I need to close the fd?
> No, you still have to close.

Yes, you still should close. shutdown() marks socket as "unusable for 
read/write/all" but don't free socket handle.

> > (selecting for readable is not a solution; if they have
> > sent me data I am uninterested in reading, I will select readable)
> selecting for an exception *should* do what you want, but doesn't
> (this is also a bug).
> > Obviously, if shutdown fails (it shouldn't, I die on failure), you would
> > need to close to avoid descriptor leakage.  But do I need to babysit the
> > descriptor after I have no more interest in it?
> Yes.  shutdown != close.

I have set flag 'close-on-exec' when open socket, because when I accept new 
connetcion, daemon forked. And have called shutdown() BEFORE close().
   With Best Regards.
   Rashid N. Achilov (RNA1-RIPE), Web:
   Granch Ltd. system administrator, e-mail:
   PGP: 83 CD E2 A7 37 4A D5 81 D6 D6 52 BF C9 2F 85 AF 97 BE CB 0A

To Unsubscribe: send mail to
with "unsubscribe freebsd-net" in the body of the message

Want to link to this message? Use this URL: <>