macOS declarations for kqueue event registration, one-shot readiness and timer filters, and the kevent wait operation.
Functions that report failure with -1 set errno.
Constants
Event filters
| Name | Value | Meaning |
|---|---|---|
EVFILT_READ | -1i16 | Read-event filter. |
EVFILT_TIMER | -7i16 | Timer-event filter. |
EVFILT_WRITE | -2i16 | Write-event filter. |
Change-list actions
| Name | Value | Meaning |
|---|---|---|
EV_ADD | 0x0001n16 | Adds an event registration. |
EV_DELETE | 0x0002n16 | Deletes an event registration. |
Event flags
| Name | Value | Meaning |
|---|---|---|
EV_ONESHOT | 0x0010n16 | Removes an event after one delivery. |
Timer units
| Name | Value | Meaning |
|---|---|---|
NOTE_NSECONDS | 0x00000004n32 | Uses nanoseconds for a timer interval. |
NOTE_USECONDS | 0x00000002n32 | Uses microseconds for a timer interval. |
Schemas
struct_kevent
(-- struct_kevent) Defines one kernel event record.Dict schema
| Field | Schema | Role |
|---|---|---|
ident | Natx | event identifier |
filter | Int16 | filter selector |
flags | Nat16 | event flags |
fflags | Nat32 | filter-specific flags |
data | Intx | filter-specific data |
udata | Natx | caller-selected user data |
- For relative
EVFILT_TIMERchanges,datais the timer interval in milliseconds by default;NOTE_NSECONDSorNOTE_USECONDSinfflagsselects nanoseconds or microseconds. - Returned timer events report the number of expirations since the last arming or delivery in
data.
Helpers
EV_SET
(kev ident filter flags fflags data udata --) Fills one event record from its identifier, filter, flags, filter flags, data, and user data.Inputs
kev:struct_keventRefwritable record that the call fills.ident: event identifier; the call casts it toNatx.filter:Int16filter, such asEVFILT_READ.flags:Nat16action and flag values, such asEV_ADD EV_ONESHOT or.fflags:Nat32filter-specific flags;0n32for none.data: filter-specific data; the call casts it toIntx.udata: caller-selected user data; the call casts it toNatx.
Outputs
- None.
Imported functions
Stack effects list a C function's parameters with the first parameter on top; see the stack-order rule.
kevent
(timeout nevents eventlist nchanges changelist kq -- result) Applies event changes and waits for ready events.Inputs
timeout:timespecCrefborrowed wait timeout in seconds and nanoseconds, or a typedNILtimespec Crefto wait until an event arrives; a zerotimespecreturns immediately.nevents:Int32event-list capacity; with0, the call applies the changes and returns without waiting.eventlist:struct_keventRefcaller-owned writable event storage, or a typedNILstruct_kevent Refwhenneventsis0; the call writes ready events or per-change error records; an error record hasEV_ERROR(0x4000n16) set inflagsand its error number indata.nchanges:Int32number of changes inchangelist.changelist:struct_keventCrefborrowed event changes to apply, or a typedNILstruct_kevent Crefwhennchangesis0.kq:Int32kqueuedescriptor.
Outputs
result:Int32number of records returned, including per-change errors,0on timeout, or-1on failure, including a failed change that finds no room for its error record ineventlist.
Examples
Example: macOS declaration inspection
Printing the imported kevent and kqueue shows their signatures, struct_kevent has 6 fields, and EVFILT_READ is -1i16.
"control" use
"macos/macos" use
{} Int32 {} [
@kevent printStack _:;
@kqueue printStack _:;
struct_kevent fieldCount printStack _:;
EVFILT_READ printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
{kq: Int32; changelist: {ident: Natx; filter: Int16; flags: Nat16; fflags: Nat32; data: Intx; udata: Natx;} Cref; nchanges: Int32; eventlist: {ident: Natx; filter: Int16; flags: Nat16; fflags: Nat32; data: Intx; udata: Natx;} Ref; nevents: Int32; timeout: {tv_sec: Intx; tv_nsec: Intx;} Cref;} Int32 {convention: "";} codeRef
{} Int32 {convention: "";} codeRef
6
-1i16
Example: macOS kqueue
kqueue returns a nonnegative descriptor, and close releases it with result 0.
"String" use
"control" use
"macos/macos" use
"macos/posix" use
{} Int32 {} [
kq: kqueue;
("created=" kq 0 < ~ LF
"close=" kq close 0 = LF) printList
0
] "main" exportFunction
Expected Output
created=TRUE
close=TRUE
See also
- linux/posix · macos/posix: POSIX process, timing, descriptor, and context declarations.
- sync/sync: Cross-platform scheduling, sleep, time, IPv4 formatting, and TCP helpers.
- linux/socket · macos/socket: Linux and macOS socket declarations, constants, address schemas, and imported functions.