Poller structv0.1.0
pub struct Poller {
// private fields
}
Not copied.
Associated functions
New
pub func New(allocator: Allocator) -> Poller ! IoError
A poller with no sockets registered.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where Windows' registrations and the room for events come from |
Returns: the poller, or why the system would not make one
Methods
Register
pub func Register(
self: &var Poller,
source: PollSource,
token: uint64,
interest: Interest
) -> ! IoError
Watches source for interest, reporting it with token.
| Name | Type | Description |
|---|---|---|
source | PollSource | the socket |
token | uint64 | the word reported with the socket's events |
interest | Interest | the readiness wanted |
Returns: success, or AlreadyExists when the socket is registered already
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.
| Name | Type | Description |
|---|---|---|
source | PollSource | the socket |
token | uint64 | the word reported with the socket's events |
interest | Interest | the readiness wanted |
Returns: success, or NotFound when the socket is not registered
Deregister
pub func Deregister(
self: &var Poller,
source: PollSource
) -> ! IoError
Stops watching a socket.
| Name | Type | Description |
|---|---|---|
source | PollSource | the socket |
Returns: success, or NotFound when the socket is not registered
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.
| Name | Type | Description |
|---|---|---|
events | var PollEvent[..] | room for the events; a wait reports at most this many, and the rest are reported by the next |
timeout | Duration? | 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
Destructor
func ~Poller(self: &var Poller)
Related
Interest
pub struct Interest {
pub readable: bool;
pub writable: bool;
}
The readiness a registration waits for. Copy.
Fields
| Name | Type | Description |
|---|---|---|
readable | bool | Something to read, or a connection to accept. |
writable | bool | Room to write. |
Associated functions
Readable
pub func Readable() -> Interest
Waiting for something to read, or a connection to accept.
Returns: the interest
Writable
pub func Writable() -> Interest
Waiting for room to write.
Returns: the interest
Both
pub func Both() -> Interest
Waiting for either.
Returns: the interest
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.
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.
Fields
| Name | Type | Description |
|---|---|---|
token | uint64 | The token the socket was registered with. |
readable | bool | A read would not wait, or a listener has a connection to accept. |
writable | bool | A write would not wait. |
closed | bool | The 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