Poller structv0.1.0

Source
Waits on many sockets at once.
pub struct Poller {
    // private fields
}

Not copied.

Associated functions

New

pub func New(allocator: Allocator) -> Poller ! IoError

A poller with no sockets registered.

NameTypeDescription
allocatorAllocatorwhere Windows' registrations and the room for events come from

Returns: the poller, or why the system would not make one

Source

Methods

Register

pub func Register(
    self: &var Poller,
    source: PollSource,
    token: uint64,
    interest: Interest
) -> ! IoError

Watches source for interest, reporting it with token.

NameTypeDescription
sourcePollSourcethe socket
tokenuint64the word reported with the socket's events
interestInterestthe readiness wanted

Returns: success, or AlreadyExists when the socket is registered already

Source

Modify

pub func Modify(
    self: &var Poller,
    source: PollSource,
    token: uint64,
    interest: Interest
) -> ! IoError

Changes what a registered socket is watched for, and the token it is reported with.

NameTypeDescription
sourcePollSourcethe socket
tokenuint64the word reported with the socket's events
interestInterestthe readiness wanted

Returns: success, or NotFound when the socket is not registered

Source

Deregister

pub func Deregister(
    self: &var Poller,
    source: PollSource
) -> ! IoError

Stops watching a socket.

NameTypeDescription
sourcePollSourcethe socket

Returns: success, or NotFound when the socket is not registered

Source

Wait

pub func Wait(
    self: &var Poller,
    events: var PollEvent[..],
    timeout: Duration?
) -> uint ! IoError

Waits until a registered socket is ready or timeout passes, and reports the ready sockets into events.

NameTypeDescription
eventsvar PollEvent[..]room for the events; a wait reports at most this many, and the rest are reported by the next
timeoutDuration?how long to wait, zero to only look, or none to wait without end

Returns: how many events were filled; zero after the timeout or when a signal ended the wait early

Source

Destructor

func ~Poller(self: &var Poller)

Source

Interest

pub struct Interest {
    pub readable: bool;
    pub writable: bool;
}

The readiness a registration waits for. Copy.

Source

Fields

NameTypeDescription
readableboolSomething to read, or a connection to accept.
writableboolRoom to write.

Associated functions

Readable

pub func Readable() -> Interest

Waiting for something to read, or a connection to accept.

Returns: the interest

Source

Writable

pub func Writable() -> Interest

Waiting for room to write.

Returns: the interest

Source

Both

pub func Both() -> Interest

Waiting for either.

Returns: the interest

Source

PollSource

pub struct PollSource {
    // private fields
}

A socket as a Poller watches it, from the socket's PollSource. It does not keep the socket open, so it is deregistered before the socket is dropped. Copy.

Source

PollEvent

pub struct PollEvent {
    pub token: uint64;
    pub readable: bool;
    pub writable: bool;
    pub closed: bool;
}

One socket a wait found ready. Copy. A socket ready both to read and to write may be reported once with both, or once for each.

Source

Fields

NameTypeDescription
tokenuint64The token the socket was registered with.
readableboolA read would not wait, or a listener has a connection to accept.
writableboolA write would not wait.
closedboolThe peer has closed the connection or an error is pending; the next read or write says which.

Constructors

PollEvent

pub func PollEvent() -> PollEvent

An event for nothing, to fill the room a wait reports into.

Returns: the event

Source