1 ;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ; Copyright (C) 2006,2007 by Stelian Ionescu ;
6 ; This program is free software; you can redistribute it and/or modify ;
7 ; it under the terms of the GNU General Public License as published by ;
8 ; the Free Software Foundation; either version 2 of the License, or ;
9 ; (at your option) any later version. ;
11 ; This program is distributed in the hope that it will be useful, ;
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
14 ; GNU General Public License for more details. ;
16 ; You should have received a copy of the GNU General Public License ;
17 ; along with this program; if not, write to the ;
18 ; Free Software Foundation, Inc., ;
19 ; 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ;
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 (in-package :io.multiplex
)
24 (defun timeout->timeval
(timeout tv
)
25 (with-foreign-slots ((et:tv-sec et
:tv-usec
) tv et
:timeval
)
26 (multiple-value-bind (sec usec
) (decode-timeout timeout
)
31 (defun timeout->timespec
(timeout ts
)
32 (with-foreign-slots ((et:ts-sec et
:ts-nsec
) ts et
:timespec
)
33 (multiple-value-bind (sec usec
) (decode-timeout timeout
)
35 et
:ts-nsec
(* 1000 usec
)))))
38 (defmacro flags-case
(mask &body clauses
)
39 (let ((newm (gensym "MASK")))
41 (cond ,@(loop :for clause
:in clauses
42 :collect
`((logtest ,(let ((flags (first clause
)))
47 ,(second clause
)))))))
50 (defmacro ignore-and-print-errors
(&body body
)
51 `(handler-case (progn ,@body
)
53 (warn "Caught a ~A: ~A, ignoring it."
54 (type-of error
) error
))))
57 ;; (defmacro with-restart-on-eintr (&body body)
59 ;; :while (not exit-p) :do
62 ;; (et:unix-error-intr (err)
63 ;; (declare (ignore err))
64 ;; (setf exit-p t)))))