XU XUv0.16.0

#net/stream

import: #net/stream

counts: 1 functions, 10 methods, 1 types, 0 constants, 0 method sets

Stream wraps net.Conn with the same method names tls.Conn uses (read / write / set_*_deadline / close) so a service loop can be written once. Xu has no interfaces — tls.Conn already has this method set; branch on a bool at the dial site if you mix both. net/stream does not import crypto/tls (tls already imports net). read may throw (deadline/IO); write/close follow net.Conn.

struct Stream

XuAPI
pub struct Stream {
    pub c net.Conn
}

Purpose

Structure encapsulating c.

Public fields

c net.Conn
byte or character code

from_tcp

XuAPI
pub fn from_tcp(c net.Conn) Stream

Purpose

from_tcp wraps a net.Conn.

Parameters

c net.Conn
byte or character code (net.Conn)

Returns

Stream — a value of this type

(&Stream) fd

XuAPI
pub fn (s &Stream) fd() int

Purpose

Execute fd on &Stream. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Stream
The Stream instance used by this call (borrow).

Returns

int — a value of this type

(Stream) remote_addr

XuAPI
pub fn (s Stream) remote_addr() string

Purpose

Operation on Stream: remote address.

Parameters

s Stream
The Stream instance used by this call (value receiver).

Returns

string — result string

($&Stream) read

XuAPI
pub fn (s $&Stream) read(max int) string

Purpose

read may throw on IO/deadline error. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Stream
The Stream instance used by this call (exclusive borrow).
max int
maximum (int)

Returns

string — result string

($&Stream) write

XuAPI
pub fn (s $&Stream) write(data &string) int

Purpose

Operation on $&Stream: write data and return the byte count. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

int — bytes written

($&Stream) set_read_deadline

XuAPI
pub fn (s $&Stream) set_read_deadline(t_ns int) int

Purpose

Operation on $&Stream: set read deadline.

Parameters

s $&Stream
The Stream instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&Stream) set_write_deadline

XuAPI
pub fn (s $&Stream) set_write_deadline(t_ns int) int

Purpose

Operation on $&Stream: set write deadline.

Parameters

s $&Stream
The Stream instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&Stream) set_deadline

XuAPI
pub fn (s $&Stream) set_deadline(t_ns int) int

Purpose

Operation on $&Stream: set deadline.

Parameters

s $&Stream
The Stream instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&Stream) close

XuAPI
pub fn (s $&Stream) close() int

Purpose

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

Parameters

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

Returns

int — a value of this type

($&Stream) read_result

XuAPI
pub fn (s $&Stream) read_result(n int) io.ReadResult

Purpose

Operation on $&Stream: read result.

Parameters

s $&Stream
The Stream instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

io.ReadResult — a value of this type

($&Stream) write_result

XuAPI
pub fn (s $&Stream) write_result(data string) io.WriteResult

Purpose

Operation on $&Stream: write result.

Parameters

s $&Stream
The Stream instance used by this call (exclusive borrow).
data string
data (string)

Returns

io.WriteResult — a value of this type