From: Conrad Barski
Subject: keeping pristine CMUCL sockets
Date: 
Message-ID: <a4af10cf.0311222033.6652f90b@posting.google.com>
My socket server keeps hosing my CMUCL sockets, a problem CLISP didn't
cause for me- Any abnormal exit will block the socket permanently, and
I can't figure out why...

If I run:

(let ((sock (extensions:create-inet-listener 1000)))
	(unwind-protect
		(let* ((x (extensions:accept-tcp-connection sock))
		       (f (sys:make-fd-stream x :input t :output t)))
				(unwind-protect
					(break)
					(close f)))
		(extensions:close-socket sock)))

then connect to the socket (for instance, with "telnet localhost
1000") the program reaches the breakpoint. If I then "q" out of the
debugger kill the program, my protection clauses are triggered and the
socket should be returned to a clean state.

However, next time I try to connect to the socket, I get an exception
"Error binding socket to port 1000: Address already in use".

Is there something I'm not clearing out properly to return the
socket/port back to a default state?

-Thanks in advance everybody-

From: Marc Spitzer
Subject: Re: keeping pristine CMUCL sockets
Date: 
Message-ID: <861xrzhddb.fsf@bogomips.optonline.net>
·····················@yahoo.com (Conrad Barski) writes:

> My socket server keeps hosing my CMUCL sockets, a problem CLISP didn't
> cause for me- Any abnormal exit will block the socket permanently, and
> I can't figure out why...

even after you exit the server socket will not be avalable for binding
to, its an IP thing.  The reason for this is that there may be some
late ariving packets to the socket so the stack protects you from that
by denying you the use of that socket for 2 to 4 min(its configurable
on most os's).  give it 5 min and then see what happens, also look at
the system documentation because there should be a way to reuse the
socket quicker by setting socket options.

marc

> 
> If I run:
> 
> (let ((sock (extensions:create-inet-listener 1000)))
> 	(unwind-protect
> 		(let* ((x (extensions:accept-tcp-connection sock))
> 		       (f (sys:make-fd-stream x :input t :output t)))
> 				(unwind-protect
> 					(break)
> 					(close f)))
> 		(extensions:close-socket sock)))
> 
> then connect to the socket (for instance, with "telnet localhost
> 1000") the program reaches the breakpoint. If I then "q" out of the
> debugger kill the program, my protection clauses are triggered and the
> socket should be returned to a clean state.
> 
> However, next time I try to connect to the socket, I get an exception
> "Error binding socket to port 1000: Address already in use".
> 
> Is there something I'm not clearing out properly to return the
> socket/port back to a default state?
> 
> -Thanks in advance everybody-
From: Conrad Barski
Subject: Re: keeping pristine CMUCL sockets
Date: 
Message-ID: <a4af10cf.0311230811.1456b83c@posting.google.com>
Thanks for the incredibly helpful comments. It works great now. Now I
understand a little more about busy ports and the SO_REUSEADDR
parameter.
From: Harald Hanche-Olsen
Subject: Re: keeping pristine CMUCL sockets
Date: 
Message-ID: <pco65hb9whs.fsf@thoth.math.ntnu.no>
+ ·····················@yahoo.com (Conrad Barski):

| (let ((sock (extensions:create-inet-listener 1000)))
| 	(unwind-protect
| 		(let* ((x (extensions:accept-tcp-connection sock))
| 		       (f (sys:make-fd-stream x :input t :output t)))
| 				(unwind-protect
| 					(break)
| 					(close f)))
| 		(extensions:close-socket sock)))
| [...]
| However, next time I try to connect to the socket, I get an exception
| "Error binding socket to port 1000: Address already in use".
| 
| Is there something I'm not clearing out properly to return the
| socket/port back to a default state?

Try: (extensions:create-inet-listener 1000 :stream :reuse-address t)

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow