1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
6 (in-package :iolib.base
)
11 ;;; Break a real timeout into seconds and microseconds.
12 (defun decode-timeout (timeout)
13 (assert (or (not timeout
)
14 (and (typep timeout
'real
)
15 (not (minusp timeout
))))
17 "The timeout must be a non-negative real or NIL: ~S" timeout
)
20 (integer (values timeout
0))
22 (multiple-value-bind (q r
) (truncate (coerce timeout
'timeout
))
23 (declare (type unsigned-byte q
)
25 (values q
(the (values unsigned-byte t
) (truncate (* r
1d6
))))))))
27 (defun normalize-timeout (timeout)
28 (assert (and (typep timeout
'real
)
29 (not (minusp timeout
)))
31 "The timeout must be non-negative: ~A" timeout
)
32 (coerce timeout
'timeout
))
34 (defun clamp-timeout (timeout &optional
(min 0) (max most-positive-fixnum
))
35 (clamp (or timeout most-positive-fixnum
)
36 (if min
(max min
0) 0) (or max most-positive-fixnum
)))