Lisp HUG Maillist Archive

[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.


RE: TCP timeout

> > 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)

I've searched some time ago, too, for a way to set the timeout on connect,
using C++ and Windows, but looks like it is not possible with synchronous
sockets:

http://groups.google.de/groups?selm=3emmlh%24n2k%40noao.edu

But I don't know, perhaps LispWorks uses asynchronous sockets internally.

Regards,

Frank


Re: TCP timeout

Unable to parse email body. Email id is 2933

Re: [Fwd: Re: TCP timeout]

Klaus Harbo <klaus@harbo.net> writes:

> Another possible solution (in addition to the :timeout keyword) could using a general timeout construct.  

That can be quite neat, but in general it is a 'dirty' solution since you
may kill the process while it's doing some cleanup operation, so imho
it's better to use less general timeout mechanisms whenever you can.

-- 
  (espen)


Updated at: 2020-12-10 08:54 UTC