From jan@swi.psy.uva.nl Thu Sep 27 13:48:26 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8RBmQv18124;
	Thu, 27 Sep 2001 13:48:26 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f8RBmQm28155;
	Thu, 27 Sep 2001 13:48:26 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "Leonid V. Khramov" <leo@solvo.ru>,
   Prolog mailing list <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] tcp_socket and REUSEADDR
Date: Thu, 27 Sep 2001 13:45:05 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <Pine.LNX.4.21.0109271237140.21646-100000@condor.solvo.ru>
In-Reply-To: <Pine.LNX.4.21.0109271237140.21646-100000@condor.solvo.ru>
MIME-Version: 1.0
Message-Id: <0109271348260D.25592@gollem>
Content-Transfer-Encoding: 8bit

On Thu, 27 Sep 2001, Leonid V. Khramov wrote:
>Hi!
>
>First of all thanks for fixing bug in wait_for_it, it works fine now.
>
>And i have another problem in tcp library.
>When i open socket for server use , tcp library didn't set SO_REUSEADDR
>option on soket. So if server crashes and restarts it can't allocate socket
>again because address still in use (OS wait some timeout).
>
>For fix this problem in C, you need to call:
>if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,&val,sizeof(val))==-1)
>{
>  return(tcp_error_term(errno, NULL));
>}
>
>after creating a socket.
>
>I hope this helps to fix the problem.

There is a lot of nasty things on this option.  To avoid setting it
by default and to provide for more options in the future, I added
tcp_setopt/2, so you can now do:

	tcp_socket(Socket),
	tcp_setopt(Socket, reuseaddr),
	...

Please pick packages/clib/socket.c and packages/clib/socket.pl from
the CVS server to get the modified sources.

Considering another E-mail on this library, the new version also
protects the global data in this library for multi-threading.

	Regards --- Jan

