XU XUv0.13.1
中文

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

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

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

Shared client transport for external drivers. A connection keeps the complete TLS state when secure is true. Callers must pass Conn values around instead of retaining only fd; an fd alone cannot represent a live TLS session.

github.com/xulang-org/packages · 1.0.2 · Install and use

const DEFAULT_TIMEOUT_NS

XuAPI
pub const DEFAULT_TIMEOUT_NS = 30000000000

Purpose

Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.

const MAX_HEADER_BYTES

XuAPI
pub const MAX_HEADER_BYTES = 1048576

Purpose

Constant MAX_HEADER_BYTES, defining protocol or algorithm parameters.

const MAX_MESSAGE_BYTES

XuAPI
pub const MAX_MESSAGE_BYTES = 10485760

Purpose

Constant MAX_MESSAGE_BYTES, defining protocol or algorithm parameters.

struct Endpoint

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

Purpose

Structure encapsulating scheme, host, port, path, secure.

Public fields

scheme string
field (string)
host string
host
port int
port
path string
filesystem path
secure bool
field (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
}

Purpose

Structure encapsulating fd, tls_conn, secure, closed, eof.

Public fields

fd int
file descriptor
tls_conn tls.Conn
field (tls.Conn)
secure bool
field (bool)
closed bool
field (bool)
eof bool
field (bool)
buf string
buffer

parse_endpoint

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

Purpose

parse_endpoint accepts scheme://host[:port][/path] and host[:port]. The path is retained for callers that need a base URL; query handling is intentionally left to the individual protocol driver. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

Endpoint — a value of this type

secure_endpoint

XuAPI
pub fn secure_endpoint(ep Endpoint) bool

Purpose

Secure endpoint.

Parameters

ep Endpoint
ep (Endpoint)

Returns

bool — true or false

dial

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

Purpose

Dial a connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

ep Endpoint
ep (Endpoint)
cfg tls.Config
cfg (tls.Config)
timeout_ns int
timeout in nanoseconds (int)

Returns

Conn — a value of this type

from_fd

XuAPI
pub fn from_fd(fd int) Conn

Purpose

Build from fd. Throws on failure; handle the error or propagate it to the caller.

Parameters

fd int
file descriptor (int)

Returns

Conn — a value of this type

closed_conn

XuAPI
pub fn closed_conn() Conn

Purpose

Closed connection.

Parameters

No arguments are required.

Returns

Conn — a value of this type

($&Conn) read

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

Purpose

Operation on $&Conn: read up to max bytes. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

string — result string

($&Conn) write

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

Purpose

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

Parameters

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

Returns

int — bytes written

($&Conn) write_all

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

Purpose

Operation on $&Conn: write all. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Conn
The Conn instance used by this call (exclusive borrow).
data string
data (string)

Returns

int — a value of this type

($&Conn) close

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

Purpose

Operation on $&Conn: close the resource.

Parameters

c $&Conn
The Conn instance used by this call (exclusive borrow).

Returns

int — a value of this type

request_raw

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

Purpose

request_raw performs one HTTP request on a fresh connection. It is used by drivers while their legacy plaintext fd pools are being migrated to Conn pools; the TLS handshake and certificate verification still happen here. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

http.Response — a value of this type

read_response

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

Purpose

read_response reads one HTTP/1.x response while retaining bytes belonging to the next response in Conn.buf. It works for both TCP and TLS sessions. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Conn
byte or character code (exclusive borrow; may modify the original; type $&Conn)
method string
method (string)

Returns

http.Response — a value of this type