XU XUv0.13.1
EN

#github.com/xulang-org/packages/transport

导入方式: transport #github.com/xulang-org/packages/transport

公开 API: 7 函数, 4 方法, 2 类型, 3 常量, 0 方法集

扩展包 `transport #github.com/xulang-org/packages/transport`,由模块 github.com/xulang-org/packages 提供。

github.com/xulang-org/packages · 1.0.2 · 安装与使用

const DEFAULT_TIMEOUT_NS

XuAPI
pub const DEFAULT_TIMEOUT_NS = 30000000000

用途

常量 DEFAULT_TIMEOUT_NS,定义了相关的协议或算法配置参数。

const MAX_HEADER_BYTES

XuAPI
pub const MAX_HEADER_BYTES = 1048576

用途

常量 MAX_HEADER_BYTES,定义了相关的协议或算法配置参数。

const MAX_MESSAGE_BYTES

XuAPI
pub const MAX_MESSAGE_BYTES = 10485760

用途

常量 MAX_MESSAGE_BYTES,定义了相关的协议或算法配置参数。

struct Endpoint

XuAPI
pub struct Endpoint {
    pub scheme string
    pub host string
    pub port int
    pub path string
    pub secure bool
}

用途

承载 scheme、host、port、path、secure 等属性的结构体。

公开字段

scheme string
字段(string)
host string
主机
port int
端口
path string
文件系统路径
secure bool
字段(bool)

struct Conn

XuAPI
pub struct Conn {
    pub fd int
    pub tls_conn tls.Conn
    pub secure bool
    pub closed bool
    pub eof bool
    pub buf string
}

用途

承载 fd、tls_conn、secure、closed、eof 等属性的结构体。

公开字段

fd int
文件描述符
tls_conn tls.Conn
字段(tls.Conn)
secure bool
字段(bool)
closed bool
字段(bool)
eof bool
字段(bool)
buf string
缓冲

parse_endpoint

XuAPI
pub fn parse_endpoint(raw string, fallback_port int) Endpoint

用途

解析为 endpoint。失败时抛出错误,调用方需处理或继续传播。

参数

raw string
raw(string)
fallback_port int
fallback_port(int)

返回值

Endpoint — 该类型的值

secure_endpoint

XuAPI
pub fn secure_endpoint(ep Endpoint) bool

用途

执行 secure endpoint 操作。

参数

ep Endpoint
ep(Endpoint)

返回值

bool — 是否成立

dial

XuAPI
pub fn dial(ep Endpoint, cfg tls.Config, timeout_ns int) Conn

用途

发起连接。失败时抛出错误,调用方需处理或继续传播。

参数

ep Endpoint
ep(Endpoint)
cfg tls.Config
cfg(tls.Config)
timeout_ns int
超时(纳秒)(int)

返回值

Conn — 该类型的值

from_fd

XuAPI
pub fn from_fd(fd int) Conn

用途

从 fd 构造。失败时抛出错误,调用方需处理或继续传播。

参数

fd int
文件描述符(int)

返回值

Conn — 该类型的值

closed_conn

XuAPI
pub fn closed_conn() Conn

用途

执行 closed conn 操作。

参数

无需传入参数。

返回值

Conn — 该类型的值

($&Conn) read

XuAPI
pub fn (c $&Conn) read(max int) string

用途

$&Conn 上的操作:读出最多 max 字节。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max int
上限(int)

返回值

string — 结果字符串

($&Conn) write

XuAPI
pub fn (c $&Conn) write(data &string) int

用途

$&Conn 上的操作:写入数据,返回写入的字节数。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
data &string
数据(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 写入的字节数

($&Conn) write_all

XuAPI
pub fn (c $&Conn) write_all(data string) int

用途

$&Conn 上的操作:执行 write all 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
data string
数据(string)

返回值

int — 该类型的值

($&Conn) close

XuAPI
pub fn (c $&Conn) close() int

用途

$&Conn 上的操作:关闭资源。

参数

c $&Conn
本次调用使用的 Conn 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

request_raw

XuAPI
pub fn request_raw(ep Endpoint, cfg tls.Config, request string, method string) http.Response

用途

执行 request raw 操作。失败时抛出错误,调用方需处理或继续传播。

参数

ep Endpoint
ep(Endpoint)
cfg tls.Config
cfg(tls.Config)
request string
request(string)
method string
method(string)

返回值

http.Response — 该类型的值

read_response

XuAPI
pub fn read_response(c $&Conn, method string) http.Response

用途

读取响应。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Conn
字节或字符码(独占借用,可修改原值;类型 $&Conn)
method string
method(string)

返回值

http.Response — 该类型的值