Re[2]: [hunchentoot-devel] port to sbcl win32: timouts are notimplemented
Anton Vodonosov
vodonosov at mail.ru
Tue Jul 3 01:13:32 UTC 2007
Edi Weitz:
> I wonder why this hasn't been an issue for the
> other SBCL/Win32 users so far, though.
I'm using sbcl 1.0.6 win32 binary downloaded from sbcl site.
The error UNDEFINED-FUNCTION: SB-UNIX:UNIX-SETITIMER
is signaled only when you start hunchentoot first time (i.e. when
you invoke sb-ext:with-timeout first time). You may just press 'q'
in the slime debugger and start hunchentoot again. But the function
is definitely not works for win32, I even checkd sbcl sources.
BTW, in the patch suggested here
http://common-lisp.net/pipermail/tbnl-devel/2006-November/000815.html
Luís Oliveira also removes sb-ext:with-timeout (he redefines
force-output* - the only place where with-timout is used)
> Anyway, I'd rather see a more unobtrusive patch which automagically
> starts to work once timeouts are implemented. Something along the
> lines of
>
> http://www.cl-user.net/asp/web-sites/features
Thank you for the link. What do you think about the following mega-solution:
;; determine whether SB-EXT:WITH-TIMEOUT function is supported;
;; we can't just check (FBOUNDP 'SB-EXT:WITH-TIMEOUT)
;; because, for example in sbcl 1.0.6 for win32, the function
;; is present, but doesn't work (it signals UNDEFINED-FUNCTION:
;; SB-UNIX:UNIX-SETITIMER)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun ensured-sleep-millis (milliseconds)
"Sleeps (in fact loops) not less then MILLISECONDS number of milliseconds;
the minimal sleep time is one internal time unit. Don't use this function
for large time values, because it may take up much processor power."
(do ((start-time (get-internal-real-time)))
((< (+ start-time (ceiling (* internal-time-units-per-second
(/ milliseconds 1000))))
(get-internal-real-time)))))
(handler-case
(sb-ext:with-timeout 0.0000001 (ensured-sleep-millis 5))
(sb-ext:timeout () (pushnew :hunchentoot-sbcl-with-timeout *features*))
(t ())))
(defmacro with-timeout ((seconds &body timeout-forms) &body body)
"Executes the code BODY and returns the results of the last
form but stops execution after SECONDS seconds and then instead
executes the code in TIMEOUT-FORMS."
#-:hunchentoot-sbcl-with-timeout `(progn , at body)
#+:hunchentoot-sbcl-with-timeout
`(cl:handler-case
(sb-ext:with-timeout ,seconds , at body)
(sb-ext:timeout () , at timeout-forms)))
In the paper it is suggested to insert symbols from library's package but not keywoards into *features*, but I follow the way already used in port-sbcl (see :hunchentoot-sbcl-debug-print-variable-alist).
I've tried this code on sbcl win32 and on linux. It works as expected.
Best regards,
-Anton
More information about the Tbnl-devel
mailing list