Add clamp-timeout to base package.
[iolib/alendvai.git] / io.multiplex / utils.lisp
blob3f3885c0f47a07d28f3afcba481285ef839d78c1
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Miscellaneous utilities.
4 ;;;
6 (in-package :io.multiplex)
8 (defun timeout->timeval (timeout tv)
9 (with-foreign-slots ((sec usec) tv timeval)
10 (multiple-value-bind (%sec %usec) (decode-timeout timeout)
11 (setf sec %sec
12 usec %usec))))
14 (defun timeout->timespec (timeout ts)
15 (with-foreign-slots ((sec nsec) ts timespec)
16 (multiple-value-bind (%sec %usec) (decode-timeout timeout)
17 (setf sec %sec
18 nsec (* 1000 %usec)))))
20 (defun timeout->milisec (timeout)
21 (if timeout
22 (multiple-value-bind (sec usec) (decode-timeout timeout)
23 (+ (* sec 1000)
24 (truncate usec 1000)))
25 -1))
27 (defmacro ignore-and-print-errors (&body body)
28 `(handler-case (locally ,@body)
29 (error (error)
30 (warn "Caught a ~A: ~A, ignoring it."
31 (type-of error) error))))