Linux declarations for epoll polling, timerfd timers, and advisory file locking with flock.
Functions that report failure with -1 set errno.
Constants
epoll control operations
| Name | Value | Meaning |
|---|---|---|
EPOLL_CTL_ADD | 1 | Adds a descriptor to the interest list. |
EPOLL_CTL_DEL | 2 | Removes a descriptor from the interest list. |
EPOLL_CTL_MOD | 3 | Modifies a descriptor in the interest list. |
epoll event flags
| Name | Value | Meaning |
|---|---|---|
EPOLLERR | 0x008n32 | Error condition. |
EPOLLHUP | 0x010n32 | Hang-up condition. |
EPOLLIN | 0x001n32 | Readable condition. |
EPOLLONESHOT | 0x40000000n32 | Disables the event after one delivery. |
EPOLLOUT | 0x004n32 | Writable condition. |
timerfd flags
| Name | Value | Meaning |
|---|---|---|
TFD_NONBLOCK | 2048 | Nonblocking timerfd flag. |
flock operations
| Name | Value | Meaning |
|---|---|---|
LOCK_EX | 0x2 | Requests an exclusive lock. |
LOCK_NB | 0x4 | Requests a nonblocking operation. |
LOCK_SH | 0x1 | Requests a shared lock. |
LOCK_UN | 0x8 | Releases a lock. |
Constant example
"control" use
"linux/linux" use
{} () {} [
EPOLL_CTL_ADD printStack _:;
EPOLLIN printStack _:;
TFD_NONBLOCK printStack _:;
] "main" exportFunction
Expected Output During Compilation
1
1n32
2048
Schemas
epoll_event
(-- epoll_event) Defines the imported epoll-event schema.EpollEvent alias
| Field | Schema | Role |
|---|---|---|
events | Nat32 | readiness mask |
ptr | Natx Ref | event data as an address |
fd | Int32 Ref | event data as a descriptor |
u32 | Nat32 Ref | event data as a 32-bit value |
u64 | Nat64 Ref | event data as a 64-bit value |
- The views share storage and preserve the record's constness.
linux/architecturemust point tox86_64,arm64, ori386for the target CPU; it selects bothEpollEventandUcontext.tiny pull(2.2.0or later) creates this link onx86_64andarm64;i386requires manual setup.
From the directory containing linux/, run the command for the target CPU:
# x86_64
ln -sfnT x86_64 linux/architecture
# arm64 / aarch64
ln -sfnT arm64 linux/architecture
# i386 / i686
ln -sfnT i386 linux/architecture
Imported functions
Stack effects list a C function's parameters with the first parameter on top; see importFunction.
epoll_create1
(flags -- result) Creates an epoll file descriptor.Inputs
flags:Int32descriptor creation flags.
Outputs
result:Int32new descriptor, or-1on failure.
epoll_ctl
(event fd op epfd -- result) Adds, removes, or modifies a descriptor in an epoll interest list.Inputs
event:epoll_eventRefcaller-owned event record for the operation.fd:Int32descriptor to control.op:Int32epoll control operation.epfd:Int32epoll descriptor.
Outputs
result:Int320on success, or-1on failure.
epoll_wait
(timeout maxevents events epfd -- result) Waits for ready epoll events.Inputs
timeout:Int32wait timeout in milliseconds;-1waits indefinitely,0returns immediately.maxevents:Int32capacity of events inepoll_eventrecords.events:Natxaddress of contiguous writableepoll_eventrecords; the call fills them with ready events.epfd:Int32epoll descriptor.
Outputs
result:Int32number of ready events,0on timeout, or-1on failure.
flock
(op fd -- result) Applies a file-lock operation.Inputs
Outputs
result:Int320on success, or-1on failure.
timerfd_create
(flags clockid -- result) Creates a timer file descriptor.Inputs
Outputs
result:Int32new descriptor, or-1on failure.
timerfd_settime
(old_value new_value flags fd -- result) Sets a timerfd expiration and interval.Inputs
old_value:itimerspecRefcaller-owned writable storage that receives the previous timer setting, or a typedNILitimerspec Refwhen the previous setting is not needed.new_value:itimerspecCrefborrowed timer setting to apply.flags:Int32timer-setting flags.fd:Int32timerfd descriptor.
Outputs
result:Int320on success, or-1on failure.
Examples
Signature examples
Printing imported names during compilation shows exact imported signatures for representative declarations.
"control" use
"linux/linux" use
{} Int32 {} [
@epoll_wait printStack _:;
@timerfd_settime printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
{epfd: Int32; events: Natx; maxevents: Int32; timeout: Int32;} Int32 {convention: "";} codeRef
{fd: Int32; flags: Int32; new_value: {it_interval: {tv_sec: Intx; tv_nsec: Intx;}; it_value: {tv_sec: Intx; tv_nsec: Intx;};} Cref; old_value: {it_interval: {tv_sec: Intx; tv_nsec: Intx;}; it_value: {tv_sec: Intx; tv_nsec: Intx;};} Ref;} Int32 {convention: "";} codeRef
epoll descriptor creation
"String" use
"control" use
"linux/linux" use
"linux/posix" use
{} Int32 {} [
epfd: 0 epoll_create1;
epClose: epfd close;
("created=" epfd 0 < ~ LF
"close=" epClose 0 = LF) printList
0
] "main" exportFunction
Expected Output
created=TRUE
close=TRUE
Timer descriptor creation
"String" use
"control" use
"linux/linux" use
"linux/posix" use
{} Int32 {} [
fd: TFD_NONBLOCK CLOCK_MONOTONIC timerfd_create;
closeResult: fd close;
("created=" fd 0 < ~ LF
"close=" closeResult 0 = LF) printList
0
] "main" exportFunction
Expected Output
created=TRUE
close=TRUE
See also
- linux/errno · macos/errno · windows/errno: Accessor for platform error-number storage.
- linux/posix · macos/posix: POSIX process, timing, descriptor, and context declarations.
- linux/runningTime · macos/runningTime · windows/runningTime: Elapsed-time helper built on platform timing APIs.
- 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.