From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E3D54BB81 for ; Wed, 9 Nov 2005 14:29:45 +0100 (CET) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jA9DTh2h023510 for ; Wed, 9 Nov 2005 14:29:45 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by smtp3.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jA9DTdsR074182; Wed, 9 Nov 2005 23:59:39 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] Error binding socket From: skaller To: Maurizio Colucci Cc: caml-list In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Date: Thu, 10 Nov 2005 00:29:38 +1100 Message-Id: <1131542978.8562.43.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 4371F9C7.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 setsockopt:01 ocaml:01 reuse:01 sockets:01 struct:01 freeing:98 queued:98 wrote:01 sourceforge:01 unix:01 unix:01 behaviour:01 int:01 int:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Wed, 2005-11-09 at 13:33 +0100, Maurizio Colucci wrote: > Hi there. For my free tennis game (http://freetennis.sf.net), I get an > error binding the socket to a port. (Unix_error 50, "bind"). The error > description is "address already in use". > > This error only happens the *second* time I start the program. It is > as if the port had not been freed and were still in use. The system is > GNU/Linux Ubuntu Breezy. > > However, if I wait about 1minute, or I start the program specifying a > different port, the problem does not happen. It is as if Linux were > freeing the port with a delay. This is standard Unix behaviour. use the setsockopt() function, these options may help (from man 7 socket), I forget the Ocaml for this, but I know it can be done because I had exactly the same problem myself once. SO_REUSEADDR Indicates that the rules used in validating addresses supplied in a bind(2) call should allow reuse of local addresses. For PF_INET sockets this means that a socket may bind, except when there is an active listening socket bound to the address. When the listening socket is bound to INADDR_ANY with a specific port then it is not possible to bind to this port for any local address. SO_LINGER Sets or gets the SO_LINGER option. The argument is a linger structure. struct linger { int l_onoff; /* linger active */ int l_linger; /* how many seconds to linger for */ }; When enabled, a close(2) or shutdown(2) will not return until all queued mes‐ sages for the socket have been successfully sent or the linger timeout has been reached. Otherwise, the call returns immediately and the closing is done in the background. When the socket is closed as part of exit(2), it always lingers in the background. -- John Skaller Felix, successor to C++: http://felix.sf.net