XU XUv0.8.8
中文

API

#net/stream

import: #net/stream

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

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

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.

Parameters

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

Call `fd` on `&Stream`. Throws on failure.

Parameters

s &Stream
receiver &Stream (borrow)

Returns

int — a value of this type

(Stream) remote_addr

XuAPI
pub fn (s Stream) remote_addr() string

Purpose

Method on `Stream`: remote address.

Parameters

s Stream
receiver Stream (value receiver)

Returns

string — result string

(&mut Stream) read

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

Purpose

read may throw on IO/deadline error. Throws on failure.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
max int
maximum (int)

Returns

string — result string

(&mut Stream) write

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

Purpose

Method on `&mut Stream`: write data and return the byte count. Throws on failure.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
data &string
data (borrowed; caller keeps it; type &string)

Returns

int — bytes written

(&mut Stream) set_read_deadline

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

Purpose

Method on `&mut Stream`: set read deadline.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
t_ns int
t_ns (int)

Returns

int — a value of this type

(&mut Stream) set_write_deadline

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

Purpose

Method on `&mut Stream`: set write deadline.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
t_ns int
t_ns (int)

Returns

int — a value of this type

(&mut Stream) set_deadline

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

Purpose

Method on `&mut Stream`: set deadline.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
t_ns int
t_ns (int)

Returns

int — a value of this type

(&mut Stream) close

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

Purpose

Method on `&mut Stream`: close the resource. Throws on failure.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)

Returns

int — a value of this type

(&mut Stream) read_result

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

Purpose

Method on `&mut Stream`: read result.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
n int
count, length, or limit (int)

Returns

io.ReadResult — a value of this type

(&mut Stream) write_result

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

Purpose

Method on `&mut Stream`: write result.

Parameters

s &mut Stream
receiver &mut Stream (exclusive borrow)
data string
data (string)

Returns

io.WriteResult — a value of this type