From owner-freebsd-questions Fri Nov 10 11:41:40 2000 Delivered-To: freebsd-questions@freebsd.org Received: from speedy.rtfm.com (unknown [198.144.203.243]) by hub.freebsd.org (Postfix) with ESMTP id A289337B4C5 for ; Fri, 10 Nov 2000 11:41:38 -0800 (PST) Received: from romeo.rtfm.com (romeo.rtfm.com [198.144.203.242]) by speedy.rtfm.com (8.9.1/8.6.4) with ESMTP id LAA05269; Fri, 10 Nov 2000 11:45:08 -0800 (PST) Received: (ekr@localhost) by romeo.rtfm.com (8.9.3/8.6.4) id LAA96847; Fri, 10 Nov 2000 11:45:19 -0800 (PST) To: j mckitrick Cc: Alfred Perlstein , freebsd-questions@FreeBSD.ORG Subject: Re: programming a file transfer References: <20001110152915.A18715@dogma.freebsd-uk.eu.org> <20001110075020.D11449@fw.wintelcom.net> <20001110191844.A20862@dogma.freebsd-uk.eu.org> Reply-To: EKR Mime-Version: 1.0 (generated by tm-edit 7.108) Content-Type: text/plain; charset=US-ASCII From: Eric Rescorla Date: 10 Nov 2000 11:45:18 -0800 In-Reply-To: j mckitrick's message of "Fri, 10 Nov 2000 19:18:44 +0000" Message-ID: Lines: 25 X-Mailer: Gnus v5.6.45/XEmacs 20.4 - "Emerald" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG j mckitrick writes: > If I crash my server after opening and binding a socket, it won't let me > bind it again obviously. How can I close this dangling socket? I need a > descriptor, right? How can I get the descriptor in a new program run? I > tried the man page for socket, but I can't find anything. It depends what you're trying to accomplish here. When your server closes, the file descriptor automatically closes, thus closing the TCP connection as well. What's likely hapenning here is that the socket is in TIME_WAIT (see Stevens TCP/IP Illustrated vol I p. 241-246). The general idea here is that TCP forbids the reuse of a socket while there might be outstanding data associated with that connection. The exact length of the timeout varies from OS to OS. On FreeBSD I believe it's two minutes. After that time you'll be able to bind() again. There's no need to clean this up. It will go away on its own. However, if you want to bind() to the same socket immediately, you can use the SO_REUSEADDR setsockopt() when you bind() (both times). -Ekr [Eric Rescorla ekr@rtfm.com] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message