XU XUv0.16.0

#net/poller

import: #net/poller

counts: 3 functions, 20 methods, 4 types, 4 constants, 0 method sets

Connection registry for long-lived peers (gateway / 5k sessions). Linux and Darwin use a persistent EventSet. Windows batches the socket probes. Event tokens identify registrations independently of reused descriptors and slots.

const EVENT_READ

XuAPI
pub const EVENT_READ = 1

Purpose

Constant EVENT_READ, defining protocol or algorithm parameters.

const EVENT_WRITE

XuAPI
pub const EVENT_WRITE = 2

Purpose

Constant EVENT_WRITE, defining protocol or algorithm parameters.

const EVENT_ERROR

XuAPI
pub const EVENT_ERROR = 4

Purpose

Constant EVENT_ERROR, defining protocol or algorithm parameters.

const EVENT_HANGUP

XuAPI
pub const EVENT_HANGUP = 8

Purpose

Constant EVENT_HANGUP, defining protocol or algorithm parameters.

struct Event

XuAPI
pub struct Event {
    pub id int
    pub events int
}

Purpose

Structure encapsulating id, events.

Public fields

id int
field (int)
events int
field (int)

struct Poller

XuAPI
pub struct Poller {

}

Purpose

Poller context or state structure.

Public fields

This type has no public fields.

new

XuAPI
pub fn new() Poller

Purpose

new creates an empty registry.

Parameters

No arguments are required.

Returns

Poller — a value of this type

(&Poller) err

XuAPI
pub fn (p &Poller) err() string

Purpose

Execute err on &Poller.

Parameters

p &Poller
The Poller instance used by this call (borrow).

Returns

string — result string

($&Poller) add

XuAPI
pub fn (p $&Poller) add(s stream.Stream) int

Purpose

add registers a stream with default EVENT_READ interest. Returns a stable id (>0).

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
s stream.Stream
s (stream.Stream)

Returns

int — a value of this type

($&Poller) add_interest_checked

XuAPI
pub fn (p $&Poller) add_interest_checked(s stream.Stream, interest int) int

Purpose

add_interest_checked registers a stream with the specified event interest mask, rolling back slot allocation and throwing on EventSet watch failure. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
s stream.Stream
s (stream.Stream)
interest int
interest (int)

Returns

int — a value of this type

($&Poller) add_interest

XuAPI
pub fn (p $&Poller) add_interest(s stream.Stream, interest int) int

Purpose

add_interest registers a stream with the specified event interest mask. Returns -1 (after rolling back slot allocation) on EventSet watch error.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
s stream.Stream
s (stream.Stream)
interest int
interest (int)

Returns

int — a value of this type

($&Poller) set_interest

XuAPI
pub fn (p $&Poller) set_interest(id int, interest int) bool

Purpose

set_interest modifies event interest for an already registered stream.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
id int
id (int)
interest int
interest (int)

Returns

bool — true or false

($&Poller) remove

XuAPI
pub fn (p $&Poller) remove(id int) bool

Purpose

remove drops the registration and its owned stream. Returns true if the id existed. Use close_id to observe an OS close error.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
id int
id (int)

Returns

bool — true or false

(Poller) count

XuAPI
pub fn (p Poller) count() int

Purpose

Operation on Poller: count non-overlapping occurrences.

Parameters

p Poller
The Poller instance used by this call (value receiver).

Returns

int — a value of this type

($&Poller) wait_checked

XuAPI
pub fn (p $&Poller) wait_checked(timeout_ns int) []Event

Purpose

wait returns the descriptors that became ready. An empty registry returns immediately. With registered streams, zero blocks and a positive timeout is in nanoseconds. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
timeout_ns int
timeout in nanoseconds (int)

Returns

[]Event — slice result

($&Poller) wait

XuAPI
pub fn (p $&Poller) wait(timeout_ns int) []Event

Purpose

Execute wait on $&Poller.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
timeout_ns int
timeout in nanoseconds (int)

Returns

[]Event — slice result

($&Poller) read_timeout

XuAPI
pub fn (p $&Poller) read_timeout(id int, max int, timeout_ns int) string

Purpose

read_timeout reads up to max bytes, applying a deadline of timeout_ns (0 = blocking). Empty string is EOF/timeout/error. The deadline is per operation. Conn applies it to SO_RCVTIMEO, so leaving it installed would make a later read inherit an already-expired timeout. Always clear it after the operation (including the error path). Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
id int
id (int)
max int
maximum (int)
timeout_ns int
timeout in nanoseconds (int)

Returns

string — result string

($&Poller) write_all

XuAPI
pub fn (p $&Poller) write_all(id int, data &string) int

Purpose

write_all writes the full buffer, looping across short writes. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
id int
id (int)
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

($&Poller) close_id

XuAPI
pub fn (p $&Poller) close_id(id int) bool

Purpose

close_id closes and removes. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&Poller
The Poller instance used by this call (exclusive borrow).
id int
id (int)

Returns

bool — true or false

struct EventSet

XuAPI
pub struct EventSet {

}

Purpose

A persistent, non-owning socket event set. Linux uses epoll and Darwin kqueue. Other hosted targets explicitly reject construction; the legacy Poller remains available there. A set is used by one owner at a time.

Public fields

This type has no public fields.

struct EventWake

XuAPI
pub struct EventWake {

}

Purpose

EventWake is a non-owning, copyable notification token for worker tasks. It does not close the EventSet; the owner must keep the set alive until all publishers have stopped.

Public fields

This type has no public fields.

event_set_supported

XuAPI
pub fn event_set_supported() bool

Purpose

Event set supported.

Parameters

No arguments are required.

Returns

bool — true or false

new_event_set

XuAPI
pub fn new_event_set() EventSet

Purpose

Construct event set. Throws on failure; handle the error or propagate it to the caller.

Parameters

No arguments are required.

Returns

EventSet — a value of this type

($&EventSet) watch

XuAPI
pub fn (p $&EventSet) watch(fd int, token int, interest int) int

Purpose

watch borrows fd and associates a caller-owned stable token. Closing the set does not close fd. Tokens must distinguish a reused connection slot an already-returned event may otherwise name a different connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&EventSet
The EventSet instance used by this call (exclusive borrow).
fd int
file descriptor (int)
token int
token (int)
interest int
interest (int)

Returns

int — a value of this type

($&EventSet) modify

XuAPI
pub fn (p $&EventSet) modify(fd int, token int, interest int) int

Purpose

Execute modify on $&EventSet. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&EventSet
The EventSet instance used by this call (exclusive borrow).
fd int
file descriptor (int)
token int
token (int)
interest int
interest (int)

Returns

int — a value of this type

($&EventSet) remove

XuAPI
pub fn (p $&EventSet) remove(fd int) int

Purpose

remove tolerates a registration already removed by the kernel. Call it before closing/reusing fd; other invalid descriptor failures propagate. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&EventSet
The EventSet instance used by this call (exclusive borrow).
fd int
file descriptor (int)

Returns

int — a value of this type

($&EventSet) wait

XuAPI
pub fn (p $&EventSet) wait(timeout_ns int) []Event

Purpose

wait returns at most 64 events. timeout_ns: zero=infinite, negative=probe, positive=relative deadline. Signals may cause an empty early wake; callers with an absolute deadline recompute the remaining time. Darwin can return separate read/write events for one token. Readiness never reserves bytes. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&EventSet
The EventSet instance used by this call (exclusive borrow).
timeout_ns int
timeout in nanoseconds (int)

Returns

[]Event — slice result

(&EventSet) wake_token

XuAPI
pub fn (p &EventSet) wake_token() EventWake

Purpose

Operation on &EventSet: wake token.

Parameters

p &EventSet
The EventSet instance used by this call (borrow).

Returns

EventWake — a value of this type

(&EventSet) wake

XuAPI
pub fn (p &EventSet) wake() int

Purpose

Execute wake on &EventSet. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &EventSet
The EventSet instance used by this call (borrow).

Returns

int — a value of this type

(EventWake) notify

XuAPI
pub fn (w EventWake) notify() int

Purpose

Execute notify on EventWake. Throws on failure; handle the error or propagate it to the caller.

Parameters

w EventWake
The EventWake instance used by this call (value receiver).

Returns

int — a value of this type

($&EventSet) close

XuAPI
pub fn (p $&EventSet) close() int

Purpose

Operation on $&EventSet: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&EventSet
The EventSet instance used by this call (exclusive borrow).

Returns

int — a value of this type