Fix inverse host lookups.
[iolib.git] / io-multiplex / fd-entry.lisp
blob51140dbe7be29fc99f14a8f5d8fad31cc7fff2c7
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
2 ;;;
3 ;;; fd-entry.lisp --- FD event structure.
4 ;;;
5 ;;; Copyright (C) 2003 Zach Beane <xach@xach.com>
6 ;;;
7 ;;; Permission is hereby granted, free of charge, to any person obtaining
8 ;;; a copy of this software and associated documentation files (the
9 ;;; "Software"), to deal in the Software without restriction, including
10 ;;; without limitation the rights to use, copy, modify, merge,publish,
11 ;;; distribute, sublicense, and/or sell copies of the Software, and to
12 ;;; permit persons to whom the Software is furnished to do so, subject to
13 ;;; the following conditions:
14 ;;;
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
17 ;;;
18 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 ;;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 ;;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 ;;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 (in-package :io.multiplex)
28 (declaim (optimize (debug 3) (safety 3)))
30 ;;;; EVENT
32 (deftype fd-event-type ()
33 '(member :read :write :error))
35 (defstruct (fd-event (:constructor make-event (fd type handler one-shot-p))
36 (:copier nil))
37 (fd nil :type unsigned-byte)
38 (type nil :type fd-event-type)
39 (handler nil :type function)
40 (timer nil :type (or null timer))
41 ;; if an event is not persistent it is removed
42 ;; after it is triggered or if it times out
43 (one-shot-p nil :type boolean))
45 ;;;; FD-ENTRY
47 (defstruct (fd-entry (:constructor make-fd-entry (fd))
48 (:copier nil))
49 (fd 0 :type unsigned-byte)
50 (read-event nil :type (or null fd-event))
51 (write-event nil :type (or null fd-event))
52 (error-event nil :type (or null fd-event)))
54 (defun fd-entry-event (fd-entry event-type)
55 (check-type fd-entry fd-entry)
56 (check-type event-type fd-event-type)
57 (case event-type
58 (:read (fd-entry-read-event fd-entry))
59 (:write (fd-entry-write-event fd-entry))
60 (:error (fd-entry-error-event fd-entry))))
62 (defun (setf fd-entry-event) (event fd-entry event-type)
63 (check-type fd-entry fd-entry)
64 (check-type event-type fd-event-type)
65 (case event-type
66 (:read (setf (fd-entry-read-event fd-entry) event))
67 (:write (setf (fd-entry-write-event fd-entry) event))
68 (:error (setf (fd-entry-error-event fd-entry) event))))
70 (defun fd-entry-empty-p (fd-entry)
71 (not (or (fd-entry-read-event fd-entry)
72 (fd-entry-write-event fd-entry)
73 (fd-entry-error-event fd-entry))))
75 (defun fd-entry-all-events (fd-entry)
76 (remove-if #'null
77 (list (fd-entry-read-event fd-entry)
78 (fd-entry-write-event fd-entry)
79 (fd-entry-error-event fd-entry))))