Rewrote the I/O multiplexer.
[iolib.git] / io-multiplex / utils.lisp
blobebd29d501d267aac3d4d001d431b193913950d6c
1 ;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ; Copyright (C) 2006,2007 by Stelian Ionescu ;
5 ; ;
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. ;
10 ; ;
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. ;
15 ; ;
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)
27 (setf et:tv-sec sec
28 et:tv-usec usec))))
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)
34 (setf et:ts-sec sec
35 et:ts-nsec (* 1000 usec)))))
38 (defmacro flags-case (mask &body clauses)
39 (let ((newm (gensym "MASK")))
40 `(let ((,newm ,mask))
41 (cond ,@(loop :for clause :in clauses
42 :collect `((logtest ,(let ((flags (first clause)))
43 (if (listp flags)
44 `(logand ,@flags)
45 flags))
46 ,newm)
47 ,(second clause)))))))
50 (defmacro ignore-and-print-errors (&body body)
51 `(handler-case (progn ,@body)
52 (error (error)
53 (warn "Caught a ~A: ~A, ignoring it."
54 (type-of error) error))))
57 ;; (defmacro with-restart-on-eintr (&body body)
58 ;; `(loop :for exit-p
59 ;; :while (not exit-p) :do
60 ;; (handler-case
61 ;; (progn ,@body)
62 ;; (et:unix-error-intr (err)
63 ;; (declare (ignore err))
64 ;; (setf exit-p t)))))