Add keyword args WAIT and TIMEOUT to ACCEPT-CONNECTION.
[iolib.git] / io.multiplex / utils.lisp
blob47b18897837e4bf4dfd5d6ff341f0ffac58f4188
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 flags-case (mask &body clauses)
28 (once-only (mask)
29 `(progn ,@(loop :for clause :in clauses
30 :collect `(when (logtest ,(let ((flags (first clause)))
31 (if (listp flags)
32 `(logior ,@flags)
33 flags))
34 ,mask)
35 ,(second clause))))))
37 (defmacro ignore-and-print-errors (&body body)
38 `(handler-case (locally ,@body)
39 (error (error)
40 (warn "Caught a ~A: ~A, ignoring it."
41 (type-of error) error))))