Add INLINE declamations for foreign wrappers.
[iolib/alendvai.git] / io.multiplex / fd-entry.lisp
blob9e33e9e2adcd965cb649805683fe8d18fb4adeac
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 ;;;; EVENT
30 (deftype fd-event-type ()
31 '(member :read :write :error))
33 (defstruct (fd-event (:constructor make-event (fd type handler one-shot-p))
34 (:copier nil))
35 (fd nil :type unsigned-byte)
36 (type nil :type fd-event-type)
37 (handler nil :type function)
38 (timer nil :type (or null timer))
39 ;; if an event is not persistent it is removed
40 ;; after it is triggered or if it times out
41 (one-shot-p nil :type boolean))
43 ;;;; FD-ENTRY
45 (defstruct (fd-entry (:constructor make-fd-entry (fd))
46 (:copier nil))
47 (fd 0 :type unsigned-byte)
48 (read-event nil :type (or null fd-event))
49 (write-event nil :type (or null fd-event))
50 (error-event nil :type (or null fd-event)))
52 (defun fd-entry-event (fd-entry event-type)
53 (check-type fd-entry fd-entry)
54 (check-type event-type fd-event-type)
55 (case event-type
56 (:read (fd-entry-read-event fd-entry))
57 (:write (fd-entry-write-event fd-entry))
58 (:error (fd-entry-error-event fd-entry))))
60 (defun (setf fd-entry-event) (event fd-entry event-type)
61 (check-type fd-entry fd-entry)
62 (check-type event-type fd-event-type)
63 (case event-type
64 (:read (setf (fd-entry-read-event fd-entry) event))
65 (:write (setf (fd-entry-write-event fd-entry) event))
66 (:error (setf (fd-entry-error-event fd-entry) event))))
68 (defun fd-entry-empty-p (fd-entry)
69 (not (or (fd-entry-read-event fd-entry)
70 (fd-entry-write-event fd-entry)
71 (fd-entry-error-event fd-entry))))
73 (defun fd-entry-all-events (fd-entry)
74 (remove-if #'null
75 (list (fd-entry-read-event fd-entry)
76 (fd-entry-write-event fd-entry)
77 (fd-entry-error-event fd-entry))))