XU XUv0.16.0

#net

import: #net

counts: 93 functions, 68 methods, 19 types, 2 constants, 0 method sets

IP/port parsing, TCP/UDP IPv4/IPv6 across Linux, macOS, and Windows, and Unix-domain sockets on Linux/macOS.

Examples · API declarations

Examples

These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.

15_udp_echo/main.xu

Required SDK: Xu 0.8.13-dev.7 · Complete project · Download source

XuLocal SDK example
@main

#net

// UDP echo(Go net.ListenPacket / ListenUDP)。
//   printf ping | nc -u 127.0.0.1 19001
// TCP 见 14tcp_echo。

fn main() int {
    $c := net.listen_packet("udp", "127.0.0.1:19001") >>> (err) {
        println(err.msg())
        << 1
    }
    println("udp://127.0.0.1:19001  echo")
    $running := true
    while running {
        pkt := c.read_from(4096) >>> (err) {
            ->
        }
        data := pkt.data + ""
        c.write_to(&data, &pkt.addr) >>> (err) {
            ->
        }
    }
    << 0
}
14_tcp_echo/main.xu

Required SDK: Xu 0.8.13-dev.7 · Complete project · Download source

XuLocal SDK example
@main

#net

// TCP echo(Go net.Listen + Accept + goroutine)。
//   printf ping | nc 127.0.0.1 19000
// UDP 见 15udp_echo。

fn handle(c net.Conn) {
    $conn := c
    buf := conn.read(4096) >>> (err) {
        conn.close() >>> (e2) { << }
        <<
    }
    if buf.len == 0 {
        conn.close() >>> (err) { << }
        <<
    }
    conn.write(&buf) >>> (err) { << }
    conn.close() >>> (err) { << }
}

fn main() int {
    ln := net.listen_on("tcp", "127.0.0.1:19000") >>> (err) {
        println(err.msg())
        << 1
    }
    println("tcp://127.0.0.1:19000  echo")
    $running := true
    while running {
        c := ln.accept() >>> (err) {
            ->
        }
        xu handle(c)
    }
    << 0
}
11_http_server/main.xu

Required SDK: Xu 0.8.13-dev.7 · Complete project · Download source

XuLocal SDK example
@main

#net
#net/http

// 自己 listen / accept / 按路径处理(Go HandleFunc 那种)。
//   GET  /        HTML
//   GET  /hello   text
//   GET  /health  ok
//   POST /echo    回显 body
// 静态目录见 12file_server;Handler 上下文见 13http_context。

fn path_only(p string) string {
    $i := 0
    while i < p.len {
        if (p[i] & 255) == 63 {
            << p[0:i]
        }
        i = i + 1
    }
    << p + ""
}

fn write_http(fd int, status int, ctype string, body string) int {
    $reason := "OK"
    if status == 404 {
        reason = "Not Found"
    }
    if status == 400 {
        reason = "Bad Request"
    }
    if status == 405 {
        reason = "Method Not Allowed"
    }
    $out := "HTTP/1.1 " + str(status) + " " + reason + "\r\n"
    out = out + "Content-Type: " + ctype + "\r\n"
    out = out + "Content-Length: " + str(body.len) + "\r\n"
    out = out + "Connection: close\r\n"
    out = out + "\r\n"
    out = out + body
    << net.conn_write(fd, &out) >>> (err) { >> err }
}

fn index_page() string {
    << "<!doctype html><html><head><meta charset=\"utf-8\"><title>Xu HTTP</title>" +
        "<style>body{font-family:ui-sans-serif,system-ui,sans-serif;max-width:40rem;" +
        "margin:3rem auto;padding:0 1.5rem;background:#0f1419;color:#e7ecf1}" +
        "h1{font-weight:650;letter-spacing:-.03em}a{color:#7dd3fc}" +
        "code{background:#1b2430;padding:.15rem .4rem;border-radius:4px}" +
        "ul{line-height:1.8}</style></head><body>" +
        "<h1>Xu HTTP</h1>" +
        "<p>自己 <code>listen</code> / <code>accept</code> / 按 path 分支。</p>" +
        "<ul>" +
        "<li><a href=\"/hello\">/hello</a></li>" +
        "<li><a href=\"/health\">/health</a></li>" +
        "<li>POST <code>/echo</code></li>" +
        "</ul></body></html>"
}

fn handle(fd int) {
    $req := http.new_request()
    req.read(fd) >>> (err) {
        msg := err.msg()
        write_http(fd, 400, "text/plain; charset=utf-8", msg) >>> (e2) { << }
        net.conn_close(fd) >>> (e3) { << }
        <<
    }
    method := req.method()
    raw_path := req.path()
    path := path_only(raw_path)
    if path == "/" || path == "/index.html" {
        page := index_page()
        write_http(fd, 200, "text/html; charset=utf-8", page) >>> (err) { << }
        net.conn_close(fd) >>> (err) { << }
        <<
    }
    if path == "/hello" {
        body := "hello, xu\n"
        write_http(fd, 200, "text/plain; charset=utf-8", body) >>> (err) { << }
        net.conn_close(fd) >>> (err) { << }
        <<
    }
    if path == "/health" {
        body := "ok\n"
        write_http(fd, 200, "text/plain; charset=utf-8", body) >>> (err) { << }
        net.conn_close(fd) >>> (err) { << }
        <<
    }
    if path == "/echo" {
        if method != "POST" && method != "PUT" {
            body := "method not allowed\n"
            write_http(fd, 405, "text/plain; charset=utf-8", body) >>> (err) { << }
            net.conn_close(fd) >>> (err) { << }
            <<
        }
        echo := req.body()
        write_http(fd, 200, "text/plain; charset=utf-8", echo) >>> (err) { << }
        net.conn_close(fd) >>> (err) { << }
        <<
    }
    miss := "not found: " + path + "\n"
    write_http(fd, 404, "text/plain; charset=utf-8", miss) >>> (err) { << }
    net.conn_close(fd) >>> (err) { << }
}

fn main() int {
    $s := http.new_server()
    s.listen("127.0.0.1:18080") >>> (err) {
        println(err.msg())
        << 1
    }
    println("http://127.0.0.1:18080")
    $running := true
    while running {
        fd := s.accept() >>> (err) {
            ->
        }
        // The deployable example uses the portable, deterministic path on all
        // hosts. The stackful `xu` scheduler has dedicated stress fixtures,
        // but it is not yet a production request-execution primitive; keeping
        // request handling sequential also gives local and server builds the
        // same lifecycle contract. Put TLS, limits and concurrency in the
        // reverse proxy until that runtime gate is closed.
        handle(fd)
    }
    << 0
}

API declarations

struct HostPort

XuAPI
pub struct HostPort {
    pub host string
    pub port string
}

Purpose

Host and port network address structure.

Public fields

host string
host
port string
port

new_host_port

XuAPI
pub fn new_host_port() HostPort

Purpose

Construct host port.

Parameters

No arguments are required.

Returns

HostPort — a value of this type

(HostPort) host

XuAPI
pub fn (hp HostPort) host() string

Purpose

Operation on HostPort: host.

Parameters

hp HostPort
The HostPort instance used by this call (value receiver).

Returns

string — result string

(HostPort) port

XuAPI
pub fn (hp HostPort) port() string

Purpose

Operation on HostPort: port.

Parameters

hp HostPort
The HostPort instance used by this call (value receiver).

Returns

string — result string

ipv4

XuAPI
pub fn ipv4(a int, b int, c int, d int) string

Purpose

Build an IPv4 address from four 0..255 octets (a 4-byte string).

Parameters

a int
octet 1, 0..255
b int
octet 2, 0..255
c int
octet 3, 0..255
d int
octet 4, 0..255

Returns

string — result string

parse_ip

XuAPI
pub fn parse_ip(s &string) string

Purpose

Parse IPv4 (dotted decimal) or IPv6 (colon hex) string into raw IP bytes; empty if invalid.

Parameters

s &string
IP address text (borrowed)

Returns

raw IP byte string (4 bytes for IPv4, 16 bytes for IPv6)

ip_string

XuAPI
pub fn ip_string(ip &string) string

Purpose

IP string.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

ip_is_unspecified

XuAPI
pub fn ip_is_unspecified(ip &string) bool

Purpose

Whether ip is unspecified.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

ip_is_loopback

XuAPI
pub fn ip_is_loopback(ip &string) bool

Purpose

Whether ip is loopback.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

ip_is_private

XuAPI
pub fn ip_is_private(ip &string) bool

Purpose

Whether ip is private.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

join_host_port

XuAPI
pub fn join_host_port(host &string, port &string) string

Purpose

Combine host and port into a network address string (host:port or [ipv6]:port).

Parameters

host &string
host name or IP text
port &string
port text

Returns

canonical host:port string

($&HostPort) split

XuAPI
pub fn (hp $&HostPort) split(hostport string) int

Purpose

Operation on $&HostPort: split on the separator. Throws on failure; handle the error or propagate it to the caller.

Parameters

hp $&HostPort
The HostPort instance used by this call (exclusive borrow).
hostport string
hostport (string)

Returns

int — a value of this type

struct Conn

XuAPI
pub struct Conn {
    pub network string
    pub laddr string
    pub raddr string
    pub read_deadline_ns int
    pub write_deadline_ns int
}

Purpose

General bidirectional streaming network connection.

Public fields

network string
field (string)
laddr string
field (string)
raddr string
field (string)
read_deadline_ns int
field (int)
write_deadline_ns int
field (int)

See usage example

struct Listener

XuAPI
pub struct Listener {
    pub network string
    pub addr string
}

Purpose

Network socket server listener for incoming connections.

Public fields

network string
field (string)
addr string
address

dial

XuAPI
pub fn dial(addr string) int

Purpose

Dial a connection.

Parameters

addr string
address (string)

Returns

int — a value of this type

dial_ns

XuAPI
pub fn dial_ns(addr string, ns int) int

Purpose

dial_ns is the fd-level connect with an optional connect timeout. ns <= 0 means no extra timeout (same as dial). Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)
ns int
ns (int)

Returns

int — a value of this type

listen

XuAPI
pub fn listen(addr string) int

Purpose

Listen for connections. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)

Returns

int — a value of this type

accept

XuAPI
pub fn accept(fd int) int

Purpose

Accept one connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

fd int
file descriptor (int)

Returns

int — a value of this type

conn_close

XuAPI
pub fn conn_close(fd int) int

Purpose

Connection close. Throws on failure; handle the error or propagate it to the caller.

Parameters

fd int
file descriptor (int)

Returns

int — a value of this type

See usage example

conn_write

XuAPI
pub fn conn_write(fd int, data &string) int

Purpose

Connection write. Throws on failure; handle the error or propagate it to the caller.

Parameters

fd int
file descriptor (int)
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

See usage example

conn_read

XuAPI
pub fn conn_read(fd int, max int) string

Purpose

Connection read. Throws on failure; handle the error or propagate it to the caller.

Parameters

fd int
file descriptor (int)
max int
maximum (int)

Returns

string — result string

($&Conn) set_deadline

XuAPI
pub fn (c $&Conn) set_deadline(t_ns int) int

Purpose

Conn.SetDeadline / SetReadDeadline / SetWriteDeadline. t_ns is absolute now_ns; 0 clears read and/or write timeouts independently.

Parameters

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

Returns

int — a value of this type

($&Conn) set_read_deadline

XuAPI
pub fn (c $&Conn) set_read_deadline(t_ns int) int

Purpose

Operation on $&Conn: set read deadline.

Parameters

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

Returns

int — a value of this type

($&Conn) set_write_deadline

XuAPI
pub fn (c $&Conn) set_write_deadline(t_ns int) int

Purpose

Operation on $&Conn: set write deadline.

Parameters

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

Returns

int — 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 (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 (borrow).
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

int — bytes written

($&Conn) close

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

Purpose

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

Parameters

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

Returns

int — a value of this type

($&Conn) close_read

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

Purpose

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

Parameters

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

Returns

int — a value of this type

($&Conn) close_write

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

Purpose

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

Parameters

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

Returns

int — a value of this type

($&Conn) shutdown

XuAPI
pub fn (c $&Conn) shutdown(how int) int

Purpose

Execute shutdown on $&Conn. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

int — a value of this type

(&Conn) set_nodelay

XuAPI
pub fn (c &Conn) set_nodelay(nodelay bool) int

Purpose

Operation on &Conn: set nodelay. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
nodelay bool
nodelay (bool)

Returns

int — a value of this type

(&Conn) set_keepalive

XuAPI
pub fn (c &Conn) set_keepalive(enable bool) int

Purpose

Operation on &Conn: set keepalive. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
enable bool
enable (bool)

Returns

int — a value of this type

(&Conn) set_read_buffer

XuAPI
pub fn (c &Conn) set_read_buffer(bytes int) int

Purpose

Operation on &Conn: set read buffer. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
bytes int
bytes (int)

Returns

int — a value of this type

(&Conn) set_write_buffer

XuAPI
pub fn (c &Conn) set_write_buffer(bytes int) int

Purpose

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

Parameters

c &Conn
The Conn instance used by this call (borrow).
bytes int
bytes (int)

Returns

int — a value of this type

(Conn) local_addr

XuAPI
pub fn (c Conn) local_addr() string

Purpose

Operation on Conn: local address.

Parameters

c Conn
The Conn instance used by this call (value receiver).

Returns

string — result string

(Conn) remote_addr

XuAPI
pub fn (c Conn) remote_addr() string

Purpose

Operation on Conn: remote address.

Parameters

c Conn
The Conn instance used by this call (value receiver).

Returns

string — result string

(Listener) accept

XuAPI
pub fn (l Listener) accept() Conn

Purpose

Operation on Listener: accept one connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

l Listener
The Listener instance used by this call (value receiver).

Returns

Conn — a value of this type

($&Listener) close

XuAPI
pub fn (l $&Listener) close() int

Purpose

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

Parameters

l $&Listener
The Listener instance used by this call (exclusive borrow).

Returns

int — a value of this type

(Listener) addr

XuAPI
pub fn (l Listener) addr() string

Purpose

Operation on Listener: address.

Parameters

l Listener
The Listener instance used by this call (value receiver).

Returns

string — result string

file_conn

XuAPI
pub fn file_conn(fd int) Conn

Purpose

File connection. 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

file_listener

XuAPI
pub fn file_listener(fd int) Listener

Purpose

File listener. Throws on failure; handle the error or propagate it to the caller.

Parameters

fd int
file descriptor (int)

Returns

Listener — 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) is_closed

XuAPI
pub fn (c &Conn) is_closed() bool

Purpose

Operation on &Conn: whether it is closed.

Parameters

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

Returns

bool — true or false

(&Conn) descriptor

XuAPI
pub fn (c &Conn) descriptor() int

Purpose

Borrowed raw descriptor; platform adapters must not create a second owner. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

int — a value of this type

struct TCPAddr

XuAPI
pub struct TCPAddr {
    pub ip string
    pub port int
    pub zone string
}

Purpose

TCP network endpoint address structure.

Public fields

ip string
field (string)
port int
port
zone string
field (string)

struct UDPAddr

XuAPI
pub struct UDPAddr {
    pub ip string
    pub port int
    pub zone string
}

Purpose

UDP network endpoint address structure.

Public fields

ip string
field (string)
port int
port
zone string
field (string)

struct IPAddr

XuAPI
pub struct IPAddr {
    pub ip string
    pub zone string
}

Purpose

IP network endpoint address structure.

Public fields

ip string
field (string)
zone string
field (string)

struct UnixAddr

XuAPI
pub struct UnixAddr {
    pub name string
    pub network string
}

Purpose

Unix network endpoint address structure.

Public fields

name string
name
network string
field (string)

new_tcp_addr

XuAPI
pub fn new_tcp_addr() TCPAddr

Purpose

Construct tcp addr.

Parameters

No arguments are required.

Returns

TCPAddr — a value of this type

new_udp_addr

XuAPI
pub fn new_udp_addr() UDPAddr

Purpose

Construct udp addr.

Parameters

No arguments are required.

Returns

UDPAddr — a value of this type

new_ip_addr

XuAPI
pub fn new_ip_addr() IPAddr

Purpose

Construct ip addr.

Parameters

No arguments are required.

Returns

IPAddr — a value of this type

new_unix_addr

XuAPI
pub fn new_unix_addr() UnixAddr

Purpose

Construct unix addr.

Parameters

No arguments are required.

Returns

UnixAddr — a value of this type

(TCPAddr) network

XuAPI
pub fn (a TCPAddr) network() string

Purpose

Return the network protocol family name (e.g. "tcp", "udp").

Parameters

a TCPAddr
The TCPAddr instance used by this call (value receiver).

Returns

string — result string

(UDPAddr) network

XuAPI
pub fn (a UDPAddr) network() string

Purpose

Return the network protocol family name (e.g. "tcp", "udp").

Parameters

a UDPAddr
The UDPAddr instance used by this call (value receiver).

Returns

string — result string

(IPAddr) network

XuAPI
pub fn (a IPAddr) network() string

Purpose

Return the network protocol family name (e.g. "tcp", "udp").

Parameters

a IPAddr
The IPAddr instance used by this call (value receiver).

Returns

string — result string

(UnixAddr) network

XuAPI
pub fn (a UnixAddr) network() string

Purpose

Return the network protocol family name (e.g. "tcp", "udp").

Parameters

a UnixAddr
The UnixAddr instance used by this call (value receiver).

Returns

string — result string

(TCPAddr) to_string

XuAPI
pub fn (a TCPAddr) to_string() string

Purpose

Operation on TCPAddr: convert to string.

Parameters

a TCPAddr
The TCPAddr instance used by this call (value receiver).

Returns

string — result string

(&UDPAddr) clone

XuAPI
pub fn (a &UDPAddr) clone() UDPAddr

Purpose

Operation on &UDPAddr: copy into a new independent string.

Parameters

a &UDPAddr
The UDPAddr instance used by this call (borrow).

Returns

UDPAddr — a value of this type

(UDPAddr) to_string

XuAPI
pub fn (a UDPAddr) to_string() string

Purpose

Operation on UDPAddr: convert to string.

Parameters

a UDPAddr
The UDPAddr instance used by this call (value receiver).

Returns

string — result string

(IPAddr) to_string

XuAPI
pub fn (a IPAddr) to_string() string

Purpose

Operation on IPAddr: convert to string.

Parameters

a IPAddr
The IPAddr instance used by this call (value receiver).

Returns

string — result string

(UnixAddr) to_string

XuAPI
pub fn (a UnixAddr) to_string() string

Purpose

Operation on UnixAddr: convert to string.

Parameters

a UnixAddr
The UnixAddr instance used by this call (value receiver).

Returns

string — result string

unpack_sockaddr

XuAPI
pub fn unpack_sockaddr(raw string) string

Purpose

Unpack sockaddr.

Parameters

raw string
raw (string)

Returns

string — result string

socket_local_addr

XuAPI
pub fn socket_local_addr(fd int) string

Purpose

Socket local address.

Parameters

fd int
file descriptor (int)

Returns

string — result string

socket_remote_addr

XuAPI
pub fn socket_remote_addr(fd int) string

Purpose

Socket remote address.

Parameters

fd int
file descriptor (int)

Returns

string — result string

split_host_port

XuAPI
pub fn split_host_port(hostport string) HostPort

Purpose

Split host:port or [ipv6]:port network address into host and port parts.

Parameters

hostport string
host and port string

Returns

HostPort structure containing host and port

resolve_tcp_addr

XuAPI
pub fn resolve_tcp_addr(network string, address string) TCPAddr

Purpose

Resolve TCP address. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
address string
address (string)

Returns

TCPAddr — a value of this type

resolve_udp_addr

XuAPI
pub fn resolve_udp_addr(network string, address string) UDPAddr

Purpose

Resolve UDP address. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
address string
address (string)

Returns

UDPAddr — a value of this type

resolve_ip_addr

XuAPI
pub fn resolve_ip_addr(network string, address string) IPAddr

Purpose

Resolve IP address. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
address string
address (string)

Returns

IPAddr — a value of this type

resolve_unix_addr

XuAPI
pub fn resolve_unix_addr(network string, address string) UnixAddr

Purpose

Resolve unix address. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
address string
address (string)

Returns

UnixAddr — a value of this type

struct Dialer

XuAPI
pub struct Dialer {
    pub timeout_ns int
    pub dual_stack bool
    pub local_ip string
    pub local_port int
}

Purpose

Network connection dialer with custom options.

Public fields

timeout_ns int
timeout_ns is a relative connect bound (SO_SNDTIMEO). 0 means no extra bound; context.deadline_ns still applies. dual_stack local_ip / local_port are stored for API shape and ignored by the stream dialer; UDP callers pass explicit local addresses.
dual_stack bool
field (bool)
local_ip string
field (string)
local_port int
field (int)

struct ListenConfig

XuAPI
pub struct ListenConfig {
    pub reuse bool
}

Purpose

Network listener configuration with custom options.

Public fields

reuse bool
field (bool)

new_dialer

XuAPI
pub fn new_dialer() Dialer

Purpose

Construct dialer.

Parameters

No arguments are required.

Returns

Dialer — a value of this type

new_listen_config

XuAPI
pub fn new_listen_config() ListenConfig

Purpose

Construct listen config.

Parameters

No arguments are required.

Returns

ListenConfig — a value of this type

dial_tcp

XuAPI
pub fn dial_tcp(network string, laddr TCPAddr, raddr TCPAddr) Conn

Purpose

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

Parameters

network string
network (string)
laddr TCPAddr
laddr (TCPAddr)
raddr TCPAddr
raddr (TCPAddr)

Returns

Conn — a value of this type

listen_tcp_config

XuAPI
pub fn listen_tcp_config(network string, laddr TCPAddr, reuse bool) Listener

Purpose

Listen TCP config. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
laddr TCPAddr
laddr (TCPAddr)
reuse bool
reuse (bool)

Returns

Listener — a value of this type

listen_tcp

XuAPI
pub fn listen_tcp(network string, laddr TCPAddr) Listener

Purpose

Listen TCP.

Parameters

network string
network (string)
laddr TCPAddr
laddr (TCPAddr)

Returns

Listener — a value of this type

dial_to

XuAPI
pub fn dial_to(network string, address string) Conn

Purpose

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

Parameters

network string
network (string)
address string
address (string)

Returns

Conn — a value of this type

listen_on

XuAPI
pub fn listen_on(network string, address string) Listener

Purpose

Listen on. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
address string
address (string)

Returns

Listener — a value of this type

See usage example

dial_context

XuAPI
pub fn dial_context(ctx &context.Context, network string, address string) Conn

Purpose

dial_context is net.DialContext.

Parameters

ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
network string
network (string)
address string
address (string)

Returns

Conn — a value of this type

(Dialer) dial

XuAPI
pub fn (d Dialer) dial(network string, address string) Conn

Purpose

Operation on Dialer: dial a connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

d Dialer
The Dialer instance used by this call (value receiver).
network string
network (string)
address string
address (string)

Returns

Conn — a value of this type

(Dialer) dial_context

XuAPI
pub fn (d Dialer) dial_context(ctx &context.Context, network string, address string) Conn

Purpose

Operation on Dialer: dial context. Throws on failure; handle the error or propagate it to the caller.

Parameters

d Dialer
The Dialer instance used by this call (value receiver).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
network string
network (string)
address string
address (string)

Returns

Conn — a value of this type

dial_timeout

XuAPI
pub fn dial_timeout(network string, address string, timeout_ns int) Conn

Purpose

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

Parameters

network string
network (string)
address string
address (string)
timeout_ns int
timeout in nanoseconds (int)

Returns

Conn — a value of this type

(ListenConfig) listen

XuAPI
pub fn (c ListenConfig) listen(ctx &context.Context, network string, address string) Listener

Purpose

listen is ListenConfig.Listen(ctx, network, address). Throws on failure; handle the error or propagate it to the caller.

Parameters

c ListenConfig
The ListenConfig instance used by this call (value receiver).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
network string
network (string)
address string
address (string)

Returns

Listener — a value of this type

(ListenConfig) listen_packet

XuAPI
pub fn (c ListenConfig) listen_packet(ctx &context.Context, network string, address string) PacketConn

Purpose

Operation on ListenConfig: listen packet. Throws on failure; handle the error or propagate it to the caller.

Parameters

c ListenConfig
The ListenConfig instance used by this call (value receiver).
ctx &context.Context
ctx (read-only borrow; caller keeps the original; type &context.Context)
network string
network (string)
address string
address (string)

Returns

PacketConn — a value of this type

listen_packet

XuAPI
pub fn listen_packet(network string, address string) PacketConn

Purpose

Listen packet. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
address string
address (string)

Returns

PacketConn — a value of this type

See usage example

struct Interface

XuAPI
pub struct Interface {
    pub index int
    pub mtu int
    pub name string
    pub hardware_addr string
    pub flags int
}

Purpose

System network interface information structure.

Public fields

index int
field (int)
mtu int
field (int)
name string
name
hardware_addr string
field (string)
flags int
field (int)

new_interface

XuAPI
pub fn new_interface() Interface

Purpose

Construct interface.

Parameters

No arguments are required.

Returns

Interface — a value of this type

flags_string

XuAPI
pub fn flags_string(f int) string

Purpose

Flags string.

Parameters

f int
callback or format string (int)

Returns

string — result string

(Interface) addrs

XuAPI
pub fn (ifi Interface) addrs() []string

Purpose

List all network addresses assigned to this interface. Throws on failure; handle the error or propagate it to the caller.

Parameters

ifi Interface
The Interface instance used by this call (value receiver).

Returns

[]string — slice result

interfaces

XuAPI
pub fn interfaces() []Interface

Purpose

Interfaces. Throws on failure; handle the error or propagate it to the caller.

Parameters

No arguments are required.

Returns

[]Interface — slice result

interface_addrs

XuAPI
pub fn interface_addrs() []string

Purpose

Interface addrs. Throws on failure; handle the error or propagate it to the caller.

Parameters

No arguments are required.

Returns

[]string — slice result

interface_by_name

XuAPI
pub fn interface_by_name(name string) Interface

Purpose

Interface by name. Throws on failure; handle the error or propagate it to the caller.

Parameters

name string
name (string)

Returns

Interface — a value of this type

interface_by_index

XuAPI
pub fn interface_by_index(index int) Interface

Purpose

Interface by index. Throws on failure; handle the error or propagate it to the caller.

Parameters

index int
index (int)

Returns

Interface — a value of this type

struct IPNet

XuAPI
pub struct IPNet {
    pub ip string
    pub mask string
}

Purpose

IP network segment structure with prefix mask.

Public fields

ip string
field (string)
mask string
field (string)

struct CIDR

XuAPI
pub struct CIDR {
    pub ip string
    pub ipnet IPNet
}

Purpose

Structure encapsulating ip, ipnet.

Public fields

ip string
field (string)
ipnet IPNet
field (IPNet)

ipv4_zero

XuAPI
pub fn ipv4_zero() string

Purpose

IPv4 zero.

Parameters

No arguments are required.

Returns

string — result string

ipv4_bcast

XuAPI
pub fn ipv4_bcast() string

Purpose

IPv4 limited broadcast address (255.255.255.255).

Parameters

No arguments are required.

Returns

string — result string

ipv4_allsys

XuAPI
pub fn ipv4_allsys() string

Purpose

IPv4 all-systems multicast address (224.0.0.1).

Parameters

No arguments are required.

Returns

string — result string

ipv4_allrouter

XuAPI
pub fn ipv4_allrouter() string

Purpose

IPv4 all-routers multicast address (224.0.0.2).

Parameters

No arguments are required.

Returns

string — result string

ipv6_zero

XuAPI
pub fn ipv6_zero() string

Purpose

IPv6 zero.

Parameters

No arguments are required.

Returns

string — result string

ipv6_unspecified

XuAPI
pub fn ipv6_unspecified() string

Purpose

IPv6 unspecified.

Parameters

No arguments are required.

Returns

string — result string

ipv6_loopback

XuAPI
pub fn ipv6_loopback() string

Purpose

IPv6 loopback.

Parameters

No arguments are required.

Returns

string — result string

ipv6_interface_local_all_nodes

XuAPI
pub fn ipv6_interface_local_all_nodes() string

Purpose

IPv6 interface local all nodes.

Parameters

No arguments are required.

Returns

string — result string

ipv4_mask

XuAPI
pub fn ipv4_mask(a int, b int, c int, d int) string

Purpose

Construct 4-byte IPv4 subnet mask.

Parameters

a int
value (int)
b int
b (int)
c int
byte or character code (int)
d int
d (int)

Returns

string — result string

cidr_mask

XuAPI
pub fn cidr_mask(ones int, bits int) string

Purpose

Construct CIDR IP subnet mask from prefix bit count.

Parameters

ones int
ones (int)
bits int
bit count (int)

Returns

string — result string

ip_to4

XuAPI
pub fn ip_to4(ip &string) string

Purpose

Return 4-byte representation if IPv4, or empty string.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

ip_to16

XuAPI
pub fn ip_to16(ip &string) string

Purpose

Return standard 16-byte representation of the IP address.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

ip_equal

XuAPI
pub fn ip_equal(a &string, b &string) bool

Purpose

IP equal.

Parameters

a &string
value (read-only borrow; caller keeps the original; type &string)
b &string
b (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

ip_mask

XuAPI
pub fn ip_mask(ip &string, mask &string) string

Purpose

Perform bitwise AND of the IP with subnet mask.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)
mask &string
mask (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

ip_default_mask

XuAPI
pub fn ip_default_mask(ip &string) string

Purpose

Return default subnet mask for IPv4 address class.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

ip_mask_size

XuAPI
pub fn ip_mask_size(mask &string) int

Purpose

IP mask size.

Parameters

mask &string
mask (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

ip_mask_bits

XuAPI
pub fn ip_mask_bits(mask &string) int

Purpose

Return leading ones and total bits of the mask.

Parameters

mask &string
mask (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

ip_mask_string

XuAPI
pub fn ip_mask_string(mask &string) string

Purpose

IP mask string.

Parameters

mask &string
mask (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

(IPNet) network

XuAPI
pub fn (n IPNet) network() string

Purpose

Return the network protocol family name (e.g. "tcp", "udp").

Parameters

n IPNet
The IPNet instance used by this call (value receiver).

Returns

string — result string

(IPNet) contains

XuAPI
pub fn (n IPNet) contains(ip &string) bool

Purpose

Operation on IPNet: report whether the input contains the given piece.

Parameters

n IPNet
The IPNet instance used by this call (value receiver).
ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

(IPNet) to_string

XuAPI
pub fn (n IPNet) to_string() string

Purpose

Operation on IPNet: convert to string.

Parameters

n IPNet
The IPNet instance used by this call (value receiver).

Returns

string — result string

parse_cidr

XuAPI
pub fn parse_cidr(s &string) CIDR

Purpose

Parse as cidr. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

CIDR — a value of this type

ip_is_multicast

XuAPI
pub fn ip_is_multicast(ip &string) bool

Purpose

Whether ip is multicast.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

ip_is_interface_local_multicast

XuAPI
pub fn ip_is_interface_local_multicast(ip &string) bool

Purpose

Whether ip is interface_local_multicast.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

ip_is_global_unicast

XuAPI
pub fn ip_is_global_unicast(ip &string) bool

Purpose

Whether ip is global_unicast.

Parameters

ip &string
ip (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

dial_ip

XuAPI
pub fn dial_ip(network string, laddr IPAddr, raddr IPAddr) Conn

Purpose

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

Parameters

network string
network (string)
laddr IPAddr
laddr (IPAddr)
raddr IPAddr
raddr (IPAddr)

Returns

Conn — a value of this type

listen_ip

XuAPI
pub fn listen_ip(network string, laddr IPAddr) PacketConn

Purpose

Listen IP. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
laddr IPAddr
laddr (IPAddr)

Returns

PacketConn — a value of this type

struct MX

XuAPI
pub struct MX {
    pub host string
    pub pref int
}

Purpose

Structure encapsulating host, pref.

Public fields

host string
host
pref int
field (int)

struct NS

XuAPI
pub struct NS {
    pub host string
}

Purpose

Structure encapsulating host.

Public fields

host string
host

struct SRV

XuAPI
pub struct SRV {
    pub target string
    pub port int
    pub priority int
    pub weight int
}

Purpose

Structure encapsulating target, port, priority, weight.

Public fields

target string
field (string)
port int
port
priority int
field (int)
weight int
field (int)

lookup_host

XuAPI
pub fn lookup_host(host string) []string

Purpose

Lookup host. Throws on failure; handle the error or propagate it to the caller.

Parameters

host string
host (string)

Returns

[]string — slice result

lookup_ip

XuAPI
pub fn lookup_ip(host string) []string

Purpose

Lookup IP. Throws on failure; handle the error or propagate it to the caller.

Parameters

host string
host (string)

Returns

[]string — slice result

lookup_cname

XuAPI
pub fn lookup_cname(host string) string

Purpose

Lookup cname. Throws on failure; handle the error or propagate it to the caller.

Parameters

host string
host (string)

Returns

string — result string

lookup_mx

XuAPI
pub fn lookup_mx(name string) []MX

Purpose

Lookup mx.

Parameters

name string
name (string)

Returns

[]MX — slice result

lookup_ns

XuAPI
pub fn lookup_ns(name string) []NS

Purpose

Lookup ns.

Parameters

name string
name (string)

Returns

[]NS — slice result

lookup_txt

XuAPI
pub fn lookup_txt(name string) []string

Purpose

Lookup txt.

Parameters

name string
name (string)

Returns

[]string — slice result

lookup_srv

XuAPI
pub fn lookup_srv(service string, proto string, name string) []SRV

Purpose

Lookup srv. Throws on failure; handle the error or propagate it to the caller.

Parameters

service string
service (string)
proto string
proto (string)
name string
name (string)

Returns

[]SRV — slice result

lookup_addr

XuAPI
pub fn lookup_addr(addr string) []string

Purpose

Lookup address. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)

Returns

[]string — slice result

hardware_addr_string

XuAPI
pub fn hardware_addr_string(a &string) string

Purpose

Hardware address string.

Parameters

a &string
value (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

parse_mac

XuAPI
pub fn parse_mac(s &string) string

Purpose

Parse as mac. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

listen_multicast_udp

XuAPI
pub fn listen_multicast_udp(network string, gaddr UDPAddr) PacketConn

Purpose

listen_multicast_udp binds 0.0.0.0:gaddr.port with address/port reuse, so it can share the port with a system responder (e.g. mDNS on 5353), and joins gaddr on the default interface. Use join_group for more interfaces. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
gaddr UDPAddr
gaddr (UDPAddr)

Returns

PacketConn — a value of this type

(&PacketConn) join_group

XuAPI
pub fn (c &PacketConn) join_group(group string, iface_ip string) int

Purpose

Operation on &PacketConn: join group. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
group string
group (string)
iface_ip string
iface_ip (string)

Returns

int — a value of this type

(&PacketConn) leave_group

XuAPI
pub fn (c &PacketConn) leave_group(group string, iface_ip string) int

Purpose

Operation on &PacketConn: leave group. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
group string
group (string)
iface_ip string
iface_ip (string)

Returns

int — a value of this type

(&PacketConn) set_multicast_interface

XuAPI
pub fn (c &PacketConn) set_multicast_interface(iface_ip string) int

Purpose

Outgoing multicast interface by IPv4 address ("" = system default). Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
iface_ip string
iface_ip (string)

Returns

int — a value of this type

(&PacketConn) set_multicast_ttl

XuAPI
pub fn (c &PacketConn) set_multicast_ttl(ttl int) int

Purpose

Operation on &PacketConn: set multicast ttl. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
ttl int
ttl (int)

Returns

int — a value of this type

(&PacketConn) set_multicast_loopback

XuAPI
pub fn (c &PacketConn) set_multicast_loopback(on bool) int

Purpose

Operation on &PacketConn: set multicast loopback. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
on bool
on (bool)

Returns

int — a value of this type

struct PipeConn

XuAPI
pub struct PipeConn {
    pub w chan string
    pub r chan string
    pub closed int
}

Purpose

Structure encapsulating w, r, closed.

Public fields

w chan string
writer or width
r chan string
rune (Unicode code point)
closed int
field (int)

struct PipePair

XuAPI
pub struct PipePair {
    pub c1 PipeConn
    pub c2 PipeConn
}

Purpose

Structure encapsulating c1, c2.

Public fields

c1 PipeConn
field (PipeConn)
c2 PipeConn
field (PipeConn)

pipe

XuAPI
pub fn pipe() PipePair

Purpose

Create a pair of connected synchronous in-memory pipe endpoints.

Parameters

No arguments are required.

Returns

PipePair — a value of this type

(PipeConn) read

XuAPI
pub fn (c PipeConn) read() string

Purpose

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

Parameters

c PipeConn
The PipeConn instance used by this call (value receiver).

Returns

string — result string

(PipeConn) write

XuAPI
pub fn (c PipeConn) write(data string) int

Purpose

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

Parameters

c PipeConn
The PipeConn instance used by this call (value receiver).
data string
data (string)

Returns

int — bytes written

($&PipeConn) close

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

Purpose

Operation on $&PipeConn: close the resource.

Parameters

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

Returns

int — a value of this type

(PipeConn) local_addr

XuAPI
pub fn (c PipeConn) local_addr() string

Purpose

Operation on PipeConn: local address.

Parameters

c PipeConn
The PipeConn instance used by this call (value receiver).

Returns

string — result string

(PipeConn) remote_addr

XuAPI
pub fn (c PipeConn) remote_addr() string

Purpose

Operation on PipeConn: remote address.

Parameters

c PipeConn
The PipeConn instance used by this call (value receiver).

Returns

string — result string

(PipeConn) network

XuAPI
pub fn (c PipeConn) network() string

Purpose

Return the network protocol family name (e.g. "tcp", "udp").

Parameters

c PipeConn
The PipeConn instance used by this call (value receiver).

Returns

string — result string

lookup_port

XuAPI
pub fn lookup_port(network string, service string) int

Purpose

Lookup port. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
service string
service (string)

Returns

int — a value of this type

lookup_protocol

XuAPI
pub fn lookup_protocol(name string) int

Purpose

Lookup protocol. Throws on failure; handle the error or propagate it to the caller.

Parameters

name string
name (string)

Returns

int — a value of this type

(&Conn) read_result

XuAPI
pub fn (c &Conn) read_result(n int) io.ReadResult

Purpose

Operation on &Conn: read result.

Parameters

c &Conn
The Conn instance used by this call (borrow).
n int
count, length, or limit (int)

Returns

io.ReadResult — a value of this type

(&Conn) write_result

XuAPI
pub fn (c &Conn) write_result(data string) io.WriteResult

Purpose

Operation on &Conn: write result.

Parameters

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

Returns

io.WriteResult — a value of this type

const IPPROTO_TCP

XuAPI
pub const IPPROTO_TCP = 6

Purpose

Constant IPPROTO_TCP, defining protocol or algorithm parameters.

const TCP_NODELAY

XuAPI
pub const TCP_NODELAY = 1

Purpose

Constant TCP_NODELAY, defining protocol or algorithm parameters.

(&Conn) read_n

XuAPI
pub fn (c &Conn) read_n(n int) string

Purpose

io stream adapters preserve the existing per-connection deadline behavior. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Conn
The Conn instance used by this call (borrow).
n int
count, length, or limit (int)

Returns

string — result string

(&Conn) write_str

XuAPI
pub fn (c &Conn) write_str(data string) int

Purpose

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

Parameters

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

Returns

int — a value of this type

struct PacketConn

XuAPI
pub struct PacketConn {
    pub network string
    pub laddr string
    pub raddr string
}

Purpose

Structure encapsulating network, laddr, raddr.

Public fields

network string
field (string)
laddr string
field (string)
raddr string
field (string)

struct UDPPacket

XuAPI
pub struct UDPPacket {
    pub addr UDPAddr
    pub data string
}

Purpose

Structure encapsulating addr, data.

Public fields

addr UDPAddr
address
data string
data

(PacketConn) local_addr

XuAPI
pub fn (c PacketConn) local_addr() string

Purpose

Operation on PacketConn: local address.

Parameters

c PacketConn
The PacketConn instance used by this call (value receiver).

Returns

string — result string

(PacketConn) remote_addr

XuAPI
pub fn (c PacketConn) remote_addr() string

Purpose

Operation on PacketConn: remote address.

Parameters

c PacketConn
The PacketConn instance used by this call (value receiver).

Returns

string — result string

($&PacketConn) set_deadline

XuAPI
pub fn (c $&PacketConn) set_deadline(t_ns int) int

Purpose

Operation on $&PacketConn: set deadline.

Parameters

c $&PacketConn
The PacketConn instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&PacketConn) set_read_deadline

XuAPI
pub fn (c $&PacketConn) set_read_deadline(t_ns int) int

Purpose

Operation on $&PacketConn: set read deadline.

Parameters

c $&PacketConn
The PacketConn instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&PacketConn) set_write_deadline

XuAPI
pub fn (c $&PacketConn) set_write_deadline(t_ns int) int

Purpose

Operation on $&PacketConn: set write deadline.

Parameters

c $&PacketConn
The PacketConn instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

(&PacketConn) set_broadcast

XuAPI
pub fn (c &PacketConn) set_broadcast(on bool) int

Purpose

Operation on &PacketConn: set broadcast. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
on bool
on (bool)

Returns

int — a value of this type

(&PacketConn) set_read_buffer

XuAPI
pub fn (c &PacketConn) set_read_buffer(bytes int) int

Purpose

Operation on &PacketConn: set read buffer. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
bytes int
bytes (int)

Returns

int — a value of this type

(&PacketConn) set_write_buffer

XuAPI
pub fn (c &PacketConn) set_write_buffer(bytes int) int

Purpose

Operation on &PacketConn: set write buffer. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
bytes int
bytes (int)

Returns

int — a value of this type

(&PacketConn) read

XuAPI
pub fn (c &PacketConn) read(max int) string

Purpose

Connected packet I/O uses socket recv/send so the Windows path reaches Winsock rather than the file-handle WriteFile/ReadFile helpers. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
max int
maximum (int)

Returns

string — result string

(&PacketConn) write

XuAPI
pub fn (c &PacketConn) write(data &string) int

Purpose

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

Parameters

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

Returns

int — bytes written

(&PacketConn) read_from

XuAPI
pub fn (c &PacketConn) read_from(max int) UDPPacket

Purpose

Operation on &PacketConn: read from. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
max int
maximum (int)

Returns

UDPPacket — a value of this type

(&PacketConn) write_to

XuAPI
pub fn (c &PacketConn) write_to(data &string, addr &UDPAddr) int

Purpose

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

Parameters

c &PacketConn
The PacketConn instance used by this call (borrow).
data &string
data (read-only borrow; caller keeps the original; type &string)
addr &UDPAddr
address (read-only borrow; caller keeps the original; type &UDPAddr)

Returns

int — a value of this type

($&PacketConn) close

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

Purpose

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

Parameters

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

Returns

int — a value of this type

dial_udp

XuAPI
pub fn dial_udp(network string, laddr UDPAddr, raddr UDPAddr) PacketConn

Purpose

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

Parameters

network string
network (string)
laddr UDPAddr
laddr (UDPAddr)
raddr UDPAddr
raddr (UDPAddr)

Returns

PacketConn — a value of this type

listen_udp_config

XuAPI
pub fn listen_udp_config(network string, laddr UDPAddr, reuse bool) PacketConn

Purpose

Listen UDP config. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
laddr UDPAddr
laddr (UDPAddr)
reuse bool
reuse (bool)

Returns

PacketConn — a value of this type

listen_udp

XuAPI
pub fn listen_udp(network string, laddr UDPAddr) PacketConn

Purpose

Listen UDP.

Parameters

network string
network (string)
laddr UDPAddr
laddr (UDPAddr)

Returns

PacketConn — a value of this type

dial_unix

XuAPI
pub fn dial_unix(network string, laddr UnixAddr, raddr UnixAddr) Conn

Purpose

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

Parameters

network string
network (string)
laddr UnixAddr
laddr (UnixAddr)
raddr UnixAddr
raddr (UnixAddr)

Returns

Conn — a value of this type

listen_unix

XuAPI
pub fn listen_unix(network string, laddr UnixAddr) Listener

Purpose

Listen unix. Throws on failure; handle the error or propagate it to the caller.

Parameters

network string
network (string)
laddr UnixAddr
laddr (UnixAddr)

Returns

Listener — a value of this type