Polling v0.1.0
F_GETFL
pub const F_GETFL: int32 = 3;
F_SETFD's companion F_GETFL: the fcntl command that reads a descriptor's status flags.
F_SETFL
pub const F_SETFL: int32 = 4;
F_SETFL: the fcntl command that sets a descriptor's status flags.
O_NONBLOCK
pub const O_NONBLOCK: int32 = 0x4;
O_NONBLOCK: the status flag that makes a call fail with EAGAIN rather than wait.
EVFILT_READ
pub const EVFILT_READ: int16 = -1;
EVFILT_READ: the filter that reports a descriptor with something to read, or a connection to accept.
EVFILT_WRITE
pub const EVFILT_WRITE: int16 = -2;
EVFILT_WRITE: the filter that reports a descriptor a write would not wait on.
EV_ADD
pub const EV_ADD: uint16 = 0x1;
EV_ADD: add the change's filter, or update it.
EV_DELETE
pub const EV_DELETE: uint16 = 0x2;
EV_DELETE: remove the change's filter.
EV_RECEIPT
pub const EV_RECEIPT: uint16 = 0x40;
EV_RECEIPT: report each change as an event, with its outcome in data, rather than waiting.
EV_ERROR
pub const EV_ERROR: uint16 = 0x4000;
EV_ERROR: set on an event that reports a failed change, with the error number in data.
EV_EOF
pub const EV_EOF: uint16 = 0x8000;
EV_EOF: the peer has closed its side.
Kevent
pub struct Kevent {
pub ident: uint64;
pub filter: int16;
pub flags: uint16;
pub filterFlags: uint32;
pub data: int64;
pub userData: uint64;
pub extension: uint64[N];
}
One struct kevent as FreeBSD 12 and later lay it out: a change to register or an event to report.
Fields
| Name | Type | Description |
|---|---|---|
ident | uint64 | The descriptor. |
filter | int16 | EVFILT_READ or EVFILT_WRITE. |
flags | uint16 | EV_ADD, EV_DELETE and the flags reported back, such as EV_EOF and EV_ERROR. |
filterFlags | uint32 | Filter-specific flags. |
data | int64 | Filter-specific data: bytes ready, or an error number. |
userData | uint64 | The word the caller chose, reported back with every event. |
extension | uint64[N] | Extensions the kernel uses and returns; zero in a change. |
Associated functions
Of
pub func Of(
ident: uint64,
filter: int16,
flags: uint16,
userData: uint64
) -> Kevent
A change or an empty event: filter on ident with flags, reporting userData.
| Name | Type | Description |
|---|---|---|
ident | uint64 | the descriptor |
filter | int16 | the filter |
flags | uint16 | such as EV_ADD |
userData | uint64 | the word to report |
Returns: the kevent
FcntlInt
pub func FcntlInt(
fd: FileDescriptor,
command: int32,
argument: int64
) -> int64
Performs command on a descriptor with an integer argument.
See also: https://man.freebsd.org/cgi/man.cgi?query=fcntl&sektion=2
Parameters
| Name | Type | Description |
|---|---|---|
fd | FileDescriptor | the descriptor |
command | int32 | such as F_GETFL or F_SETFL |
argument | int64 | the command's argument, or zero |
Returns: the command's result, or a negative error number
Kqueue
pub func Kqueue() -> int64
Opens a kqueue.
See also: https://man.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
Returns: the kqueue's descriptor, or a negative error number
KeventCall
pub func KeventCall(
queue: FileDescriptor,
changes: *Kevent,
changeCount: int32,
events: *var Kevent,
eventCount: int32,
timeout: *Timespec
) -> int64
Applies changeCount changes, then waits until an event is ready or timeout passes, filling events.
See also: https://man.freebsd.org/cgi/man.cgi?query=kevent&sektion=2
Parameters
| Name | Type | Description |
|---|---|---|
queue | FileDescriptor | the kqueue |
changes | *Kevent | the changes to apply, or null |
changeCount | int32 | how many changes there are |
events | *var Kevent | room for eventCount events, or null |
eventCount | int32 | how many events fit |
timeout | *Timespec | how long to wait, or null to wait without end |
Returns: how many events were filled, or a negative error number