Skip site navigation (1)Skip section navigation (2)
Date:      10 Nov 2000 11:45:18 -0800
From:      Eric Rescorla <ekr@rtfm.com>
To:        j mckitrick <jcm@FreeBSD-uk.eu.org>
Cc:        Alfred Perlstein <bright@wintelcom.net>, freebsd-questions@FreeBSD.ORG
Subject:   Re: programming a file transfer
Message-ID:  <kjofznligh.fsf@romeo.rtfm.com>
In-Reply-To: j mckitrick's message of "Fri, 10 Nov 2000 19:18:44 %2B0000"
References:  <20001110152915.A18715@dogma.freebsd-uk.eu.org> <20001110075020.D11449@fw.wintelcom.net> <20001110191844.A20862@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
j mckitrick <jcm@FreeBSD-uk.eu.org> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?kjofznligh.fsf>