Polling v0.1.0

Source
Descriptor flags and the kqueue filters a poller waits with.

F_GETFL

pub const F_GETFL: int32 = 3;

F_GETFL: the fcntl command that reads a descriptor's status flags.

Source

F_SETFL

pub const F_SETFL: int32 = 4;

F_SETFL: the fcntl command that sets a descriptor's status flags.

Source

O_NONBLOCK

pub const O_NONBLOCK: int32 = 0x4;

O_NONBLOCK: the status flag that makes a call fail with EAGAIN rather than wait.

Source

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.

Source

EVFILT_WRITE

pub const EVFILT_WRITE: int16 = -2;

EVFILT_WRITE: the filter that reports a descriptor a write would not wait on.

Source

EV_ADD

pub const EV_ADD: uint16 = 0x1;

EV_ADD: add the change's filter, or update it.

Source

EV_DELETE

pub const EV_DELETE: uint16 = 0x2;

EV_DELETE: remove the change's filter.

Source

EV_RECEIPT

pub const EV_RECEIPT: uint16 = 0x40;

EV_RECEIPT: report each change as an event, with its outcome in data, rather than waiting.

Source

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.

Source

EV_EOF

pub const EV_EOF: uint16 = 0x8000;

EV_EOF: the peer has closed its side.

Source

Kevent

pub struct Kevent {
    pub ident: uint64;
    pub filter: int16;
    pub flags: uint16;
    pub filterFlags: uint32;
    pub data: int64;
    pub userData: uint64;
}

One struct kevent as 64-bit macOS lays it out: a change to register or an event to report.

Source

Fields

NameTypeDescription
identuint64The descriptor.
filterint16EVFILT_READ or EVFILT_WRITE.
flagsuint16EV_ADD, EV_DELETE and the flags reported back, such as EV_EOF and EV_ERROR.
filterFlagsuint32Filter-specific flags.
dataint64Filter-specific data: bytes ready, or an error number.
userDatauint64The word the caller chose, reported back with every event.

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.

NameTypeDescription
identuint64the descriptor
filterint16the filter
flagsuint16such as EV_ADD
userDatauint64the word to report

Returns: the kevent

Source

FcntlInt

pub func FcntlInt(
    fd: FileDescriptor,
    command: int32,
    argument: int64
) -> int64

Performs command on a descriptor with an integer argument.

See also: https://keith.github.io/xcode-man-pages/fcntl.2.html

Source

Parameters

NameTypeDescription
fdFileDescriptorthe descriptor
commandint32such as F_GETFL or F_SETFL
argumentint64the 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://keith.github.io/xcode-man-pages/kqueue.2.html

Source

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://keith.github.io/xcode-man-pages/kevent.2.html

Source

Parameters

NameTypeDescription
queueFileDescriptorthe kqueue
changes*Keventthe changes to apply, or null
changeCountint32how many changes there are
events*var Keventroom for eventCount events, or null
eventCountint32how many events fit
timeout*Timespechow long to wait, or null to wait without end

Returns: how many events were filled, or a negative error number