From owner-freebsd-net Mon May 7 2:10:10 2001 Delivered-To: freebsd-net@freebsd.org Received: from molly.straylight.com (molly.straylight.com [204.69.232.69]) by hub.freebsd.org (Postfix) with ESMTP id 9015537B422 for ; Mon, 7 May 2001 02:10:07 -0700 (PDT) (envelope-from jonathan@graehl.org) Received: from case (root@localhost [127.0.0.1]) by molly.straylight.com (8.11.0/8.10.0) with ESMTP id f4799hL11812 for ; Mon, 7 May 2001 02:09:43 -0700 From: "Jonathan Graehl" To: Subject: Do I need to close after shutdown if I don't want to leak descriptors? (making sure TCP retransmits all my data) Date: Mon, 7 May 2001 02:10:14 -0700 Message-ID: <000001c0d6d5$87607e80$6dfeac40@straylight.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2605 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Scenario: I accept a (TCP) connection, write some data, close the connection. Problem: close() does not perform an orderly shutdown, does not resend unacknowledged data - responds with RST to data/acks sent to me Non-solution: SO_LINGER, makes close into a blocking call in order to get orderly shutdown 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? If so, how can I be notified when the other end acknowledges up to FIN (or timeout) in order to do so? (selecting for readable is not a solution; if they have sent me data I am uninterested in reading, I will select readable) 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? Is there a ps-like tool with which I can easily inspect descriptor usage? This seems to be a very difficult question; I have found contradictory (and many obviously wrong) opinions so far, and Stevens' UNP doesn't address it at all (he seems unaware of the possibility, or else silently reliant on process termination freeing all descriptors). -- Jonathan Graehl http://jonathan.graehl.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message