1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
3 ;;; fd-entry.lisp --- FD event structure.
5 ;;; Copyright (C) 2003 Zach Beane <xach@xach.com>
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:
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
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)))
32 (deftype fd-event-type
()
33 '(member :read
:write
:error
))
35 (defstruct (fd-event (:constructor make-event
(fd type handler one-shot-p
))
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
))
47 (defstruct (fd-entry (:constructor make-fd-entry
(fd))
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
)
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
)
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)
77 (list (fd-entry-read-event fd-entry
)
78 (fd-entry-write-event fd-entry
)
79 (fd-entry-error-event fd-entry
))))