chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Is there a way to get tcp-accept to time-out?


From: felix winkelmann
Subject: Re: [Chicken-users] Is there a way to get tcp-accept to time-out?
Date: Sat, 26 Feb 2005 17:03:31 +0100

On Fri, 25 Feb 2005 04:01:05 +0000, Julian Morrison
<address@hidden> wrote:
> Ed Watkeys wrote:
> 
> > Hi all,
> >
> > Anyone know of a way to get tcp-accept to time-out? Or, barring that,
> > is there a way I can get a file descriptor from a listener so I can
> > call file-select with it?
> >
> Will this help:
> 
> (declare (uses posix))
> (define (call-with-timeout duration-in-seconds thunk)
>    (call-with-current-continuation
>     (lambda (timeout)
>        (let ((before (lambda ()
>                         (set-signal-handler! signal/alrm
>                                              (lambda (signal-number)
>                                                 (timeout #f)))
>                         (set-alarm! duration-in-seconds)))
> 
>              (after  (lambda ()
>                         (set-signal-handler! signal/alrm #f)
>                         (set-alarm! 0))))
>           (dynamic-wind before thunk after)))))
> 

Cool, but not necessarily safe: the signal handler will be called in whatever
thread happens to run (I'm working on improving this situation, together with
Mark Wutka). But this is fine for single-threaded applications.


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]