[Fwd: Re: TCP timeout]
[I accidentally sent this just to Chris, but for the benefit of the list: ]
Chris R. Sims wrote:
> Hi,
>
> I'm having some trouble with getting a TCP connection to timeout on
> connect. My understanding is that the following function should return
> Nil after 3 seconds:
>
> (comm:open-tcp-stream "1.0.0.3" 3999 direction :io :read-timeout 3)
>
> However, the :read-timeout keyword seems to have no effect on how long
> it attempts to connect. For me it takes somewhere around 1 minute before
> it times out. I'm using LWM.
>
> Is this an error, or am I missing something about the specs for this
> function?
>
> Thanks,
>
> -Chris
>
Another possible solution (in addition to the :timeout keyword) could using a general timeout
construct. I found
(defmacro with-timeout ((timeout &optional result) &body body)
(let ((proc (gensym "PROC"))
(blockname (gensym "BLOCKNAME")))
`(block ,blockname
(let ((,proc (mp:process-run-function
(format nil "Timeout Function for ~A"
(mp:process-name mp:*current-process*))
(list :priority (mp:process-priority
mp:*current-process*))
(lambda (,proc)
(sleep ,timeout)
(mp:process-interrupt ,proc
(lambda ()
(return-from ,blockname
,result))))
mp:*current-process*)))
(unwind-protect
(progn
,@body)
(mp:process-kill ,proc))))))
some time ago; I forget if it was on comp.lang.lisp or on this list. Note that the code is
LW-specific (and quite neat, I might add).
best,
-Klaus.