Add clamp-timeout to base package.
[iolib/alendvai.git] / io.multiplex / grovel.lisp
blobae9fd3c92b147c12aef7224e4f097ef572e7092a
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Grovel definitions for IO.MULTIPLEX
4 ;;;
5 ;;; Copyright (C) 2005-2006, Matthew Backes <lucca@accela.net>
6 ;;; Copyright (C) 2005-2006, Dan Knapp <dankna@accela.net>
7 ;;; Copyright (C) 2007, Stelian Ionescu <sionescu-@common-lisp.net>
8 ;;;
9 ;;; Permission is hereby granted, free of charge, to any person
10 ;;; obtaining a copy of this software and associated documentation
11 ;;; files (the "Software"), to deal in the Software without
12 ;;; restriction, including without limitation the rights to use, copy,
13 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
14 ;;; of the Software, and to permit persons to whom the Software is
15 ;;; furnished to do so, subject to the following conditions:
16 ;;;
17 ;;; The above copyright notice and this permission notice shall be
18 ;;; included in all copies or substantial portions of the Software.
19 ;;;
20 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 ;;; DEALINGS IN THE SOFTWARE.
29 #+linux
30 (define "_GNU_SOURCE")
32 ;;; largefile support on linux
33 ;;; TODO: check if these flags are required on solaris too
34 #+linux
35 (progn
36 (define "_XOPEN_SOURCE" 600)
37 (define "_LARGEFILE_SOURCE")
38 (define "_LARGEFILE64_SOURCE")
39 (define "_FILE_OFFSET_BITS" 64))
41 (include "sys/types.h" "time.h" "sys/select.h" "sys/poll.h")
43 #+linux
44 (include "sys/epoll.h" "sys/ioctl.h")
46 #+bsd
47 (include "sys/event.h" "sys/time.h") ; for kqueue
49 (in-package :io.multiplex)
52 ;;;; from time.h
54 (ctype time_t "time_t")
55 (ctype suseconds "suseconds_t")
57 #-darwin
58 (progn
59 (ctype clockid "clockid_t")
60 (constant (clock-monotonic "CLOCK_MONOTONIC"))
61 (constant (clock-realtime "CLOCK_REALTIME")))
63 (cstruct timespec "struct timespec"
64 "UNIX time specification in seconds and nanoseconds."
65 (sec "tv_sec" :type time_t)
66 (nsec "tv_nsec" :type :long))
68 ;;;; from sys/select.h
70 (constant (fd-setsize "FD_SETSIZE"))
72 (cstruct fd-set "fd_set"
73 (bits "fds_bits" :type :uint8 :count :auto))
75 ;;;; from sys/poll.h
77 (ctype nfds "nfds_t")
79 (cstruct pollfd "struct pollfd"
80 "Poll file descriptor activity specification structure."
81 (fd "fd" :type :int)
82 (events "events" :type :short)
83 (revents "revents" :type :short))
85 (constant (pollin "POLLIN"))
86 (constant (pollrdnorm "POLLRDNORM"))
87 (constant (pollrdband "POLLRDBAND"))
88 (constant (pollpri "POLLPRI"))
89 (constant (pollout "POLLOUT"))
90 (constant (pollwrnorm "POLLWRNORM"))
91 (constant (pollwrband "POLLWRBAND"))
92 (constant (pollerr "POLLERR"))
93 #-darwin (constant (pollrdhup "POLLRDHUP"))
94 (constant (pollhup "POLLHUP"))
95 (constant (pollnval "POLLNVAL"))
97 ;;;; from sys/epoll.h
99 #+linux
100 (progn
101 (cunion epoll-data "epoll_data_t"
102 (ptr "ptr" :type :pointer)
103 (fd "fd" :type :int)
104 (u32 "u32" :type :uint32)
105 (u64 "u64" :type :uint64))
107 (cstruct epoll-event "struct epoll_event"
108 (events "events" :type :uint32)
109 (data "data" :type epoll-data))
111 (constant (epollin "EPOLLIN"))
112 (constant (epollrdnorm "EPOLLRDNORM"))
113 (constant (epollrdband "EPOLLRDBAND"))
114 (constant (epollpri "EPOLLPRI"))
115 (constant (epollout "EPOLLOUT"))
116 (constant (epollwrnorm "EPOLLWRNORM"))
117 (constant (epollwrband "EPOLLWRBAND"))
118 (constant (epollerr "EPOLLERR"))
119 (constant (epollhup "EPOLLHUP"))
120 (constant (epollmsg "EPOLLMSG"))
121 (constant (epolloneshot "EPOLLONESHOT"))
122 (constant (epollet "EPOLLET"))
124 (constant (epoll-ctl-add "EPOLL_CTL_ADD"))
125 (constant (epoll-ctl-del "EPOLL_CTL_DEL"))
126 (constant (epoll-ctl-mod "EPOLL_CTL_MOD")))
128 ;;;; from sys/event.h
130 #+bsd
131 (progn
132 (ctype intptr "intptr_t")
133 (ctype uintptr "uintptr_t")
135 (cstruct kevent "struct kevent"
136 (ident "ident" :type uintptr)
137 (filter "filter" :type :short)
138 (flags "flags" :type :unsigned-short)
139 (fflags "fflags" :type :unsigned-int)
140 (data "data" :type intptr)
141 (udata "udata" :type :pointer))
143 ;; kevent() flags
144 (constant (ev-add "EV_ADD"))
145 (constant (ev-enable "EV_ENABLE"))
146 (constant (ev-disable "EV_DISABLE"))
147 (constant (ev-delete "EV_DELETE"))
148 (constant (ev-oneshot "EV_ONESHOT"))
149 (constant (ev-clear "EV_CLEAR"))
150 (constant (ev-eof "EV_EOF"))
151 (constant (ev-error "EV_ERROR"))
153 ;; kevent() filter flags
154 (constant (evfilt-read "EVFILT_READ"))
155 (constant (evfilt-write "EVFILT_WRITE"))
156 (constant (evfilt-aio "EVFILT_AIO"))
157 (constant (evfilt-vnode "EVFILT_VNODE"))
158 (constant (evfilt-proc "EVFILT_PROC"))
159 (constant (evfilt-signal "EVFILT_SIGNAL"))
160 (constant (evfilt-timer "EVFILT_TIMER"))
161 #-darwin (constant (evfilt-netdev "EVFILT_NETDEV"))
163 ;; EVFILT_VNODE options
164 (constant (note-delete "NOTE_DELETE"))
165 (constant (note-write "NOTE_WRITE"))
166 (constant (note-extend "NOTE_EXTEND"))
167 (constant (note-attrib "NOTE_ATTRIB"))
168 (constant (note-link "NOTE_LINK"))
169 (constant (note-rename "NOTE_RENAME"))
170 (constant (note-revoke "NOTE_REVOKE"))
172 ;; EVFILT_PROC options
173 (constant (note-exit "NOTE_EXIT"))
174 (constant (note-fork "NOTE_FORK"))
175 (constant (note-exec "NOTE_EXEC"))
176 (constant (note-track "NOTE_TRACK"))
177 (constant (note-trackerr "NOTE_TRACKERR"))
179 ;; EVFILT_NETDEV options
180 #-darwin
181 (progn
182 (constant (note-linkup "NOTE_LINKUP"))
183 (constant (note-linkdown "NOTE_LINKDOWN"))
184 (constant (note-linkinv "NOTE_LINKINV"))))