Subject: Re: [SWIPL] tcp_socket and REUSEADDR

From: Jan Wielemaker <[email-masked]>
Date: Thu, 27 Sep 2001 13:45:05 +0200

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