]>
git.saurik.com Git - apple/security.git/blob - libsecurity_utilities/lib/kq++.h
2 * Copyright (c) 2009 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // kq++ - kqueue/kevent interface
31 #include <security_utilities/unix++.h>
32 #include <sys/event.h>
35 namespace UnixPlusPlus
{
46 unsigned operator () (const KEvent
*updates
, unsigned updateCount
, KEvent
*events
, unsigned eventCount
,
47 const timespec
*timeout
= NULL
);
48 unsigned operator () (KEvent
*events
, unsigned eventCount
, const timespec
*timeout
= NULL
)
49 { return operator () (NULL
, NULL
, events
, eventCount
, timeout
); }
51 void update(const KEvent
&event
, unsigned flags
= EV_ADD
);
52 bool receive(KEvent
&event
, const timespec
*timeout
= NULL
);
59 class KEvent
: public PodWrapper
<KEvent
, kevent64_s
> {
61 KEvent() { clearPod(); }
62 KEvent(int16_t filt
) { clearPod(); this->filter
= filt
; }
63 KEvent(int16_t filt
, uint64_t id
, uint32_t ffl
= 0)
64 // { clearPod(); this->ident = id; this->filter = filt; this->fflags = ffl; }
65 { EV_SET64(this, id
, filt
, 0, ffl
, 0, 0, 0, 0); }
67 void addTo(KQueue
&kq
, unsigned flags
= 0)
68 { this->flags
= EV_ADD
| flags
; kq
.update(*this); }
69 void removeFrom(KQueue
&kq
, unsigned flags
= 0)
70 { this->flags
= EV_DELETE
| flags
; kq
.update(*this); }
71 void enable(KQueue
&kq
, unsigned flags
= 0)
72 { this->flags
= EV_ENABLE
| flags
; kq
.update(*this); }
73 void disable(KQueue
&kq
, unsigned flags
= 0)
74 { this->flags
= EV_DISABLE
| flags
; kq
.update(*this); }
81 class Vnode
: public KEvent
{
83 Vnode() : KEvent(EVFILT_VNODE
) { }
84 Vnode(int fd
, uint32_t flags
) : KEvent(EVFILT_VNODE
, fd
, flags
) { }
86 int fd() const { return (int)this->ident
; }
92 } // end namespace UnixPlusPlus
93 } // end namespace Security