XU XUv0.8.8
中文

API

#net/poller

import: #net/poller

counts: 1 fns, 6 methods, 1 types, 0 consts, 0 ifaces

Connection registry for long-lived peers (gateway / 5k sessions). **Runtime status:** hosted backends have no epoll/kqueue/IOCP ncall (`rt_net` is dial/listen/accept + blocking conn_*). A readiness poller needs runtime support (poll(2) / kqueue / IOCP). v1 is a registry + cooperative helpers * add / remove / count * read_timeout applies a deadline then reads Pair with `timer.Wheel` for heartbeats. Swap for readiness events when the runtime exposes poll.

struct Poller

XuAPI
pub struct Poller {

}

Purpose

Connection registry for long-lived peers (gateway / 5k sessions). **Runtime status:** hosted backends have no epoll/kqueue/IOCP ncall (`rt_net` is dial/listen/accept + blocking conn_*). A readiness poller needs runtime support (poll(2) / kqueue / IOCP). v1 is a registry + cooperative helpers * add / remove / count * read_timeout applies a deadline then reads Pair with `timer.Wheel` for heartbeats. Swap for readiness events when the runtime exposes poll.

Parameters

none

new

XuAPI
pub fn new() Poller

Purpose

new creates an empty registry.

Parameters

none

Returns

Poller — a value of this type

(&mut Poller) add

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

Purpose

add registers a stream. Returns a stable id (>0).

Parameters

p &mut Poller
receiver &mut Poller (exclusive borrow)
s stream.Stream
source string (stream.Stream)

Returns

int — a value of this type

(&mut Poller) remove

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

Purpose

remove drops id. Returns true if it existed.

Parameters

p &mut Poller
receiver &mut Poller (exclusive borrow)
id int
id (int)

Returns

bool — true or false

(Poller) count

XuAPI
pub fn (p Poller) count() int

Purpose

Method on `Poller`: count non-overlapping occurrences.

Parameters

p Poller
receiver Poller (value receiver)

Returns

int — a value of this type

(&mut Poller) read_timeout

XuAPI
pub fn (p &mut 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. Throws on failure.

Parameters

p &mut Poller
receiver &mut Poller (exclusive borrow)
id int
id (int)
max int
maximum (int)
timeout_ns int
timeout in nanoseconds (int)

Returns

string — result string

(&mut Poller) write_all

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

Purpose

write_all writes the buffer in one call. Throws on failure.

Parameters

p &mut Poller
receiver &mut Poller (exclusive borrow)
id int
id (int)
data &string
data (borrowed; caller keeps it; type &string)

Returns

int — a value of this type

(&mut Poller) close_id

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

Purpose

close_id closes and removes. Throws on failure.

Parameters

p &mut Poller
receiver &mut Poller (exclusive borrow)
id int
id (int)

Returns

bool — true or false