const O_RDONLY
pub const O_RDONLY = 0Purpose
Constant O_RDONLY, defining protocol or algorithm parameters.
#osProcess, files, environment. Hosted File: open/create/read/write/close. getwd returns empty on failure.
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.
36_test_sqlite_pool/main.xu@main
sqlite #github.com/xulang-org/packages/sqlite
#database/sql
#os
#errors
fn remove_if_exists(p string) {
os.remove(p) >>> (e) {
<<
}
}
fn verify_sqlite_pool_deep() {
println("--- SQLite Connection Pool Deep Verification ---")
db_file := "/tmp/xu_sqlite_pool.db"
remove_if_exists(db_file + "")
$db := sqlite.open_pool(db_file + "", 5, 2)
// 1. Ping
db.ping() >>> (err) {
println(" [FAIL] SQLite pool ping failed: " + err.msg())
<<
}
println(" [PASS] SQLite Pool ping succeeded.")
// 2. Schema
db.exec("CREATE TABLE pool_items (id INTEGER PRIMARY KEY, title TEXT, value INT);") >>> (err) {
println(" [FAIL] Create table failed: " + err.msg())
<<
}
println(" [PASS] Schema created.")
// 3. Sequential & Concurrent Inserts through Pool
$i := 1
while i <= 5 {
db.exec("INSERT INTO pool_items (id, title, value) VALUES (?, ?, ?);", i, "item_" + str(i), i * 10) >>> (err) {
println(" [FAIL] Insert failed at item " + str(i) + ": " + err.msg())
<<
}
i = i + 1
}
println(" [PASS] 5 items inserted through SQLite connection pool.")
// 4. Query through Pool
$rows := db.query("SELECT id, title, value FROM pool_items ORDER BY id ASC;") >>> (err) {
println(" [FAIL] Query failed: " + err.msg())
<<
}
$count := 0
while rows.next() {
vals := rows.take() >>> (err) {
<<
}
count = count + 1
}
rows.close()
println(" [PASS] SQLite Pool query verified: retrieved " + str(count) + " rows.")
// 5. Close Pool
db.close() >>> (err) {
println(" [FAIL] Close failed: " + err.msg())
<<
}
os.remove(db_file + "") >>> (e) {
<<
}
println(" [PASS] SQLite Pool closed cleanly.")
}
fn main() {
println("=== SQLite Connection Pool In-Depth Verification ===\n")
verify_sqlite_pool_deep()
println("\n[SQLITE POOL VERIFICATION 100% COMPLETED]")
}18_database_mysql/main.xu@main
#database/sql
mysql #github.com/xulang-org/packages/mysql
#os
// MySQL/MariaDB:XU_MYSQL_DSN 可覆盖本地开发默认值。
// 驱动是普通 XU 包,通过 database/sql 接口使用,不依赖编译器内建。
fn main() int {
$dsn := os.getenv("XU_MYSQL_DSN")
if dsn.len == 0 {
dsn = "root:root@tcp(127.0.0.1:3306)/xu_demo?tls=false"
}
$db := sql.open(mysql.driver(), dsn)
db.ping() >>> (err) {
println("MySQL ping failed")
println(err.msg())
<< 1
}
db.exec("DROP TABLE IF EXISTS xu_people") >>> (err) {
println(err.msg())
<< 1
}
db.exec("CREATE TABLE xu_people (id INTEGER PRIMARY KEY, name VARCHAR(100) NOT NULL, active BOOLEAN NOT NULL)") >>> (err) {
println(err.msg())
<< 1
}
first := db.exec(
"INSERT INTO xu_people (id, name, active) VALUES (?, ?, ?)",
1,
"Ada",
true
) >>> (err) {
println(err.msg())
<< 1
}
println("inserted=" + str(first.rows_affected()))
$insert_person := db.prepare(
"INSERT INTO xu_people (id, name, active) VALUES (?, ?, ?)"
) >>> (err) {
println(err.msg())
<< 1
}
insert_person.exec(2, "Lin", true) >>> (err) {
println(err.msg())
<< 1
}
insert_person.close()
$tx := db.begin() >>> (err) {
println(err.msg())
<< 1
}
tx.exec(
"INSERT INTO xu_people (id, name, active) VALUES (?, ?, ?)",
3,
"Grace",
true
) >>> (err) {
println(err.msg())
<< 1
}
tx.commit() >>> (err) {
println(err.msg())
<< 1
}
$rows := db.query("SELECT id, name FROM xu_people ORDER BY id") >>> (err) {
println(err.msg())
<< 1
}
while rows.next() {
values := rows.take() >>> (err) {
println(err.msg())
<< 1
}
id := values[0] as int
name := values[1] as string
println(str(id) + ": " + name)
}
if rows.err().len > 0 {
println(rows.err())
<< 1
}
rows.close()
row := db.query_row("SELECT name FROM xu_people WHERE id = ?", 2)
values := row.take() >>> (err) {
println(err.msg())
<< 1
}
println("selected=" + (values[0] as string))
db.close() >>> (err) {
println(err.msg())
<< 1
}
<< 0
}17_database_postgres/main.xu@main
#database/sql
postgres #github.com/xulang-org/packages/postgres
#os
// PostgreSQL:XU_POSTGRES_DSN 可覆盖本地开发默认值。
// 驱动是普通 XU 包,通过 database/sql 接口使用,不依赖编译器内建。
fn main() int {
$dsn := os.getenv("XU_POSTGRES_DSN")
if dsn.len == 0 {
dsn = "postgres://postgres:postgres@127.0.0.1:5432/xu_demo?sslmode=disable"
}
$db := sql.open(postgres.driver(), dsn)
db.ping() >>> (err) {
println("PostgreSQL ping failed")
println(err.msg())
<< 1
}
db.exec("DROP TABLE IF EXISTS xu_people") >>> (err) {
println(err.msg())
<< 1
}
db.exec("CREATE TABLE xu_people (id INTEGER PRIMARY KEY, name VARCHAR(100) NOT NULL, active BOOLEAN NOT NULL)") >>> (err) {
println(err.msg())
<< 1
}
first := db.exec(
"INSERT INTO xu_people (id, name, active) VALUES ($$1, $$2, $$3)",
1,
"Ada",
true
) >>> (err) {
println(err.msg())
<< 1
}
println("inserted=" + str(first.rows_affected()))
$insert_person := db.prepare(
"INSERT INTO xu_people (id, name, active) VALUES ($$1, $$2, $$3)"
)
insert_person.exec(2, "Lin", true) >>> (err) {
println(err.msg())
<< 1
}
insert_person.close()
$tx := db.begin() >>> (err) {
println(err.msg())
<< 1
}
tx.exec(
"INSERT INTO xu_people (id, name, active) VALUES ($$1, $$2, $$3)",
3,
"Grace",
true
) >>> (err) {
println(err.msg())
<< 1
}
tx.commit() >>> (err) {
println(err.msg())
<< 1
}
$rows := db.query("SELECT id, name FROM xu_people ORDER BY id") >>> (err) {
println(err.msg())
<< 1
}
while rows.next() {
values := rows.take() >>> (err) {
println(err.msg())
<< 1
}
id := values[0] as int
name := values[1] as string
println(str(id) + ": " + name)
}
if rows.err().len > 0 {
println(rows.err())
<< 1
}
rows.close()
$qrows := db.query("SELECT name FROM xu_people WHERE id = $$1", 2) >>> (err) {
println(err.msg())
<< 1
}
if qrows.next() {
vals := qrows.take() >>> (err) {
println(err.msg())
<< 1
}
println("selected=" + (vals[0] as string))
}
qrows.close()
db.close() >>> (err) {
println(err.msg())
<< 1
}
<< 0
}22_standalone_sqlite/main.xu@main
#database/sql/driver
sqlite #github.com/xulang-org/packages/sqlite
#os
#strings
fn remove_if_exists(p string) {
os.remove(p) >>> (err) {
<<
}
}
fn main() int {
println("=== SQLite Standalone Library Integration Test ===")
db_file := "/tmp/xu_sqlite_test.db"
remove_if_exists(strings.clone(&db_file))
// 1. 打开数据库连接
conn := sqlite.open(strings.clone(&db_file))
// 2. 建表
schema := "CREATE TABLE IF NOT EXISTS developers (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INT, salary REAL, active INT);"
res1 := conn.exec(schema, []driver.NamedValue{})
if res1.err.len > 0 {
println("CREATE TABLE error: " + res1.err)
<< 1
}
println("1. Schema created successfully.")
// 3. 参数化插入记录
$args1 := []driver.NamedValue{}
args1.push(driver.NamedValue{name: "name", ordinal: 1, value: "Ada Lovelace"})
args1.push(driver.NamedValue{name: "age", ordinal: 2, value: 36})
args1.push(driver.NamedValue{name: "salary", ordinal: 3, value: 125000.5})
args1.push(driver.NamedValue{name: "active", ordinal: 4, value: true})
res_ins1 := conn.exec("INSERT INTO developers (name, age, salary, active) VALUES (?, ?, ?, ?);", args1)
if res_ins1.err.len > 0 {
println("INSERT 1 error: " + res_ins1.err)
<< 1
}
println("2. Inserted developer 1, id=" + str(res_ins1.last_insert_id) + ", rows_affected=" + str(res_ins1.rows_affected))
// 4. 第二条记录插入
$args2 := []driver.NamedValue{}
args2.push(driver.NamedValue{name: "name", ordinal: 1, value: "Alan Turing"})
args2.push(driver.NamedValue{name: "age", ordinal: 2, value: 41})
args2.push(driver.NamedValue{name: "salary", ordinal: 3, value: 140000.0})
args2.push(driver.NamedValue{name: "active", ordinal: 4, value: true})
res_ins2 := conn.exec("INSERT INTO developers (name, age, salary, active) VALUES (?, ?, ?, ?);", args2)
if res_ins2.err.len > 0 {
println("INSERT 2 error: " + res_ins2.err)
<< 1
}
println("3. Inserted developer 2, id=" + str(res_ins2.last_insert_id) + ", rows_affected=" + str(res_ins2.rows_affected))
// 5. 查询所有记录
rows := conn.query("SELECT id, name, age, salary, active FROM developers ORDER BY id ASC;", []driver.NamedValue{})
if rows.err.len > 0 {
println("QUERY error: " + rows.err)
<< 1
}
println("4. Query returned columns count: " + str(rows.ncols))
$col_str := " Columns: "
for ci in 0:rows.columns.len {
if ci > 0 {
col_str = col_str + ", "
}
col_str = col_str + rows.columns[ci]
}
println(col_str)
nrows := rows.cells.len / rows.ncols
println(" Total rows: " + str(nrows))
$r := 0
while r < nrows {
base := r * rows.ncols
id_str := rows.cells[base]
name_str := rows.cells[base + 1]
age_str := rows.cells[base + 2]
sal_str := rows.cells[base + 3]
act_str := rows.cells[base + 4]
println(" Row " + str(r + 1) + ": id=" + id_str + ", name=" + name_str + ", age=" + age_str + ", salary=" + sal_str + ", active=" + act_str)
r = r + 1
}
// 6. 带参数的查询
$qargs := []driver.NamedValue{}
qargs.push(driver.NamedValue{name: "name", ordinal: 1, value: "Alan Turing"})
rows_filtered := conn.query("SELECT id, name, age FROM developers WHERE name = ?;", qargs)
if rows_filtered.err.len > 0 {
println("FILTERED QUERY error: " + rows_filtered.err)
<< 1
}
if rows_filtered.cells.len >= 3 {
println("5. Parameterized query successful: found " + rows_filtered.cells[1] + ", age=" + rows_filtered.cells[2])
}
// 7. 更新操作
$uargs := []driver.NamedValue{}
uargs.push(driver.NamedValue{name: "age", ordinal: 1, value: 37})
uargs.push(driver.NamedValue{name: "id", ordinal: 2, value: 1})
res_up := conn.exec("UPDATE developers SET age = ? WHERE id = ?;", uargs)
if res_up.err.len > 0 {
println("UPDATE error: " + res_up.err)
<< 1
}
println("6. Updated developer 1: rows_affected=" + str(res_up.rows_affected))
// 8. 事务支持
tx := conn.begin()
$tx_args := []driver.NamedValue{}
tx_args.push(driver.NamedValue{name: "name", ordinal: 1, value: "Grace Hopper"})
tx_args.push(driver.NamedValue{name: "age", ordinal: 2, value: 85})
tx_args.push(driver.NamedValue{name: "salary", ordinal: 3, value: 160000.0})
tx_args.push(driver.NamedValue{name: "active", ordinal: 4, value: true})
res_tx := conn.exec("INSERT INTO developers (name, age, salary, active) VALUES (?, ?, ?, ?);", tx_args)
if res_tx.err.len > 0 {
println("TX INSERT error: " + res_tx.err)
<< 1
}
commit_err := tx.commit()
if commit_err.len > 0 {
println("TX COMMIT error: " + commit_err)
<< 1
}
println("7. Transaction committed successfully.")
// 9. 关闭与清理
conn.close()
remove_if_exists(db_file)
println("=== SQLite Standalone Tests Completed Successfully! ===")
<< 0
}const O_RDONLYpub const O_RDONLY = 0Constant O_RDONLY, defining protocol or algorithm parameters.
const O_CREATEpub const O_CREATE = 1Constant O_CREATE, defining protocol or algorithm parameters.
const O_APPENDpub const O_APPEND = 2Constant O_APPEND, defining protocol or algorithm parameters.
const O_EXCLpub const O_EXCL = 3Constant O_EXCL, defining protocol or algorithm parameters.
const O_LOCKpub const O_LOCK = 4Constant O_LOCK, defining protocol or algorithm parameters.
const O_LOCK_EXISTINGpub const O_LOCK_EXISTING = 5Constant O_LOCK_EXISTING, defining protocol or algorithm parameters.
const SEEK_SETpub const SEEK_SET = 0Constant SEEK_SET, defining protocol or algorithm parameters.
const SEEK_CURpub const SEEK_CUR = 1Constant SEEK_CUR, defining protocol or algorithm parameters.
const SEEK_ENDpub const SEEK_END = 2Constant SEEK_END, defining protocol or algorithm parameters.
argspub fn args() []stringsys_args is the private builtin spelling. Calling args from this module would resolve to the public wrapper below and recurse.
No arguments are required.
[]string — slice result
argvpub fn argv() []stringargv is retained as the compatibility spelling used by older Xu programs.
No arguments are required.
[]string — slice result
readpub fn read(path string) stringread reads the file named by path and returns the contents. Throws on failure; handle the error or propagate it to the caller.
path stringstring — result string
writepub fn write(path string, data string) intwrite writes data to the named file, creating it if necessary. Throws on failure; handle the error or propagate it to the caller.
path stringdata stringint — bytes written
struct Filepub struct File {
}Streaming file owner. Non-Copy via its compiler-managed drop hook.
This type has no public fields.
open_lockpub fn open_lock(path string, existing bool) FileExclusive nonblocking process lock. Closing File or process termination releases it. The stable lock file must never be unlinked while in use. o_lock creates without truncating; o_lock_existing opens read-only. Throws on failure; handle the error or propagate it to the caller.
path stringexisting boolFile — a value of this type
openpub fn open(path string) FileOpen resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
path stringFile — a value of this type
createpub fn create(path string) FileCreate a new file, directory, or resource. Throws on failure; handle the error or propagate it to the caller.
path stringFile — a value of this type
open_appendpub fn open_append(path string) FileOpen append. Throws on failure; handle the error or propagate it to the caller.
path stringFile — a value of this type
create_exclpub fn create_excl(path string) FileCreate excl. Throws on failure; handle the error or propagate it to the caller.
path stringFile — a value of this type
(&File) readpub fn (f &File) read(max int) stringOperation on &File: read up to max bytes. Throws on failure; handle the error or propagate it to the caller.
f &FileFile instance used by this call (borrow).max intstring — result string
(&File) writepub fn (f &File) write(data string) intOperation on &File: write data and return the byte count. Throws on failure; handle the error or propagate it to the caller.
f &FileFile instance used by this call (borrow).data stringint — bytes written
($&File) closepub fn (f $&File) close() intOperation on $&File: close the resource. Throws on failure; handle the error or propagate it to the caller.
f $&FileFile instance used by this call (exclusive borrow).int — a value of this type
(&File) seekpub fn (f &File) seek(offset int, whence int) intOperation on &File: move the read position. whence 0/1/2 = absolute / relative / from end. Throws on failure; handle the error or propagate it to the caller.
f &FileFile instance used by this call (borrow).offset intwhence intint — a value of this type
struct Pipepub struct Pipe {
pub r File
pub w File
}Structure encapsulating r, w.
r Filew Filepipepub fn pipe() PipeCreate a pair of connected synchronous in-memory pipe endpoints. Throws on failure; handle the error or propagate it to the caller.
No arguments are required.
Pipe — a value of this type
read_dirpub fn read_dir(path string) stringsys_read_dir avoids the same-name wrapper shadowing the private builtin. Throws on failure; handle the error or propagate it to the caller.
path stringstring — result string
listdirpub fn listdir(path string) stringlistdir is retained as a compatibility spelling. Throws on failure; handle the error or propagate it to the caller.
path stringstring — result string
getpidpub fn getpid() intExecute getpid.
No arguments are required.
int — a value of this type
getppidpub fn getppid() intExecute getppid.
No arguments are required.
int — a value of this type
getuidpub fn getuid() intExecute getuid.
No arguments are required.
int — a value of this type
getgidpub fn getgid() intExecute getgid.
No arguments are required.
int — a value of this type
geteuidpub fn geteuid() intExecute geteuid.
No arguments are required.
int — a value of this type
getegidpub fn getegid() intExecute getegid.
No arguments are required.
int — a value of this type
getpagesizepub fn getpagesize() intExecute getpagesize.
No arguments are required.
int — a value of this type
hostnamepub fn hostname() stringExecute hostname.
No arguments are required.
string — result string
getwdpub fn getwd() stringgetwd returns a rooted path name corresponding to the current directory.
No arguments are required.
string — result string
getenvpub fn getenv(name string) stringgetenv retrieves the value of the environment variable named by the key.
name stringstring — result string
struct EnvValpub struct EnvVal {
pub value string
pub found bool
}EnvVal is os.LookupEnv's two results: found is false when unset (empty value with found true is a defined empty string).
value stringfound boollookup_envpub fn lookup_env(name string) EnvValLookup env.
name stringEnvVal — a value of this type
environpub fn environ() []stringExecute environ.
No arguments are required.
[]string — slice result
temp_dirpub fn temp_dir() stringTemp directory.
No arguments are required.
string — result string
home_dirpub fn home_dir() stringHome directory.
No arguments are required.
string — result string
user_home_dirpub fn user_home_dir() stringUser home directory. Throws on failure; handle the error or propagate it to the caller.
No arguments are required.
string — result string
path_separatorpub fn path_separator() intPath separator.
No arguments are required.
int — a value of this type
is_path_separatorpub fn is_path_separator(c int) boolWhether it is path separator.
c intbool — true or false
path_list_separatorpub fn path_list_separator() intpath_list_separator is os.PathListSeparator: ';' on Windows, ':' elsewhere.
No arguments are required.
int — a value of this type
dev_nullpub fn dev_null() stringdev_null is os.DevNull: "NUL" on Windows, "/dev/null" elsewhere.
No arguments are required.
string — result string
user_cache_dirpub fn user_cache_dir() stringUser cache directory. Throws on failure; handle the error or propagate it to the caller.
No arguments are required.
string — result string
user_config_dirpub fn user_config_dir() stringUser config directory. Throws on failure; handle the error or propagate it to the caller.
No arguments are required.
string — result string
statpub fn stat(path string) FileInfoRead metadata. Throws on failure; handle the error or propagate it to the caller.
path stringFileInfo — a value of this type
mkdirpub fn mkdir(path string) intCreate a directory. Throws on failure; handle the error or propagate it to the caller.
path stringint — a value of this type
renamepub fn rename(old string, new string) intRename. Throws on failure; handle the error or propagate it to the caller.
old stringnew stringint — a value of this type
removepub fn remove(path string) intRemove. Throws on failure; handle the error or propagate it to the caller.
path stringint — a value of this type
chmodpub fn chmod(path string, mode int) intExecute chmod. Throws on failure; handle the error or propagate it to the caller.
path stringmode intint — a value of this type
chdirpub fn chdir(path string) intExecute chdir. Throws on failure; handle the error or propagate it to the caller.
path stringint — a value of this type
symlinkpub fn symlink(oldpath string, newpath string) intExecute symlink. Throws on failure; handle the error or propagate it to the caller.
oldpath stringnewpath stringint — a value of this type
readlinkpub fn readlink(path string) stringExecute readlink. Throws on failure; handle the error or propagate it to the caller.
path stringstring — result string
is_dirpub fn is_dir(path string) boolWhether it is a directory.
path stringbool — true or false
is_not_existpub fn is_not_exist(msg string) boolWhether it is not exist.
msg stringbool — true or false
is_existpub fn is_exist(msg string) boolWhether it is exist.
msg stringbool — true or false
is_permissionpub fn is_permission(msg string) boolWhether it is permission.
msg stringbool — true or false
is_timeoutpub fn is_timeout(msg string) boolWhether it is timeout.
msg stringbool — true or false
struct DirEntrypub struct DirEntry {
pub name string
pub is_dir bool
}Structure encapsulating name, is_dir.
name stringis_dir boolentriespub fn entries(path0 string) []DirEntryExecute entries. Throws on failure; handle the error or propagate it to the caller.
path0 string[]DirEntry — slice result
mkdir_allpub fn mkdir_all(path0 string) intMkdir all. Throws on failure; handle the error or propagate it to the caller.
path0 stringint — a value of this type
mkdir_temppub fn mkdir_temp(dir string, pattern string) stringMkdir temp. Throws on failure; handle the error or propagate it to the caller.
dir stringpattern stringstring — result string
create_temppub fn create_temp(dir string, pattern string) stringCreate temp. Throws on failure; handle the error or propagate it to the caller.
dir stringpattern stringstring — result string
remove_allpub fn remove_all(path0 string) intRemove all.
path0 stringint — a value of this type
expand_envpub fn expand_env(s &string) stringExpand env.
s &stringstring — result string
closed_filepub fn closed_file() FileA closed owner for aggregate initialization; no resource is acquired.
No arguments are required.
File — a value of this type
($&File) takepub fn (f $&File) take() FileTransfer a field-owned File without cloning or moving through a borrow. Throws on failure; handle the error or propagate it to the caller.
f $&FileFile instance used by this call (exclusive borrow).File — a value of this type
($&File) release_descriptorpub fn (f $&File) release_descriptor() intExplicit ownership handoff to a raw platform adapter. The adapter must release the returned descriptor exactly once; this owner becomes closed. Throws on failure; handle the error or propagate it to the caller.
f $&FileFile instance used by this call (exclusive borrow).int — a value of this type
(&File) descriptorpub fn (f &File) descriptor() intBorrowed raw descriptor for platform adapters. It does not transfer ownership callers must not close it or manufacture another owner from it. Throws on failure; handle the error or propagate it to the caller.
f &FileFile instance used by this call (borrow).int — a value of this type
struct DirFSpub struct DirFS {
pub dir string
}Structure encapsulating dir.
dir stringdir_fspub fn dir_fs(dir string) DirFSDirectory fs.
dir stringDirFS — a value of this type
(&DirFS) openpub fn (d &DirFS) open(name string) FileOperation on &DirFS: open resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
d &DirFSDirFS instance used by this call (borrow).name stringFile — a value of this type
(&DirFS) statpub fn (d &DirFS) stat(name string) FileInfoOperation on &DirFS: read metadata. Throws on failure; handle the error or propagate it to the caller.
d &DirFSDirFS instance used by this call (borrow).name stringFileInfo — a value of this type
(&DirFS) read_dirpub fn (d &DirFS) read_dir(name string) []DirEntryOperation on &DirFS: read directory. Throws on failure; handle the error or propagate it to the caller.
d &DirFSDirFS instance used by this call (borrow).name string[]DirEntry — slice result
(&DirFS) read_filepub fn (d &DirFS) read_file(name string) stringOperation on &DirFS: read file. Throws on failure; handle the error or propagate it to the caller.
d &DirFSDirFS instance used by this call (borrow).name stringstring — result string
(&DirFS) subpub fn (d &DirFS) sub(name string) DirFSOperation on &DirFS: subtract. Throws on failure; handle the error or propagate it to the caller.
d &DirFSDirFS instance used by this call (borrow).name stringDirFS — a value of this type
(&File) read_resultpub fn (f &File) read_result(n int) io.ReadResultOperation on &File: read result.
f &FileFile instance used by this call (borrow).n intio.ReadResult — a value of this type
(&File) write_resultpub fn (f &File) write_result(data string) io.WriteResultOperation on &File: write result.
f &FileFile instance used by this call (borrow).data stringio.WriteResult — a value of this type
socketpub fn socket(domain int, typ int, proto int) intExecute socket. Throws on failure; handle the error or propagate it to the caller.
domain inttyp intproto intint — a value of this type
bind4pub fn bind4(fd int, a int, b int, c int, d int, port int) intExecute bind4. Throws on failure; handle the error or propagate it to the caller.
fd inta intb intc intd intport intint — a value of this type
connect4pub fn connect4(fd int, a int, b int, c int, d int, port int) intExecute connect4. Throws on failure; handle the error or propagate it to the caller.
fd inta intb intc intd intport intint — a value of this type
bind6pub fn bind6(fd int, ip string, port int) intIPv6 socket address helpers. ip is the 16-byte raw IPv6 value used by net.IP; the runtime validates its length before touching the host socket. Throws on failure; handle the error or propagate it to the caller.
fd intip stringport intint — a value of this type
connect6pub fn connect6(fd int, ip string, port int) intExecute connect6. Throws on failure; handle the error or propagate it to the caller.
fd intip stringport intint — a value of this type
bind_unixpub fn bind_unix(fd int, path string) intUnix-domain pathname sockets. These calls are available on Darwin/Linux the hosted runtime returns an explicit unsupported error on Windows. Throws on failure; handle the error or propagate it to the caller.
fd intpath stringint — a value of this type
connect_unixpub fn connect_unix(fd int, path string) intConnect unix. Throws on failure; handle the error or propagate it to the caller.
fd intpath stringint — a value of this type
listenpub fn listen(fd int, backlog int) intListen for connections. Throws on failure; handle the error or propagate it to the caller.
fd intbacklog intint — a value of this type
acceptpub fn accept(fd int) intAccept one connection. Throws on failure; handle the error or propagate it to the caller.
fd intint — a value of this type
getsocknamepub fn getsockname(fd int) stringExecute getsockname. Throws on failure; handle the error or propagate it to the caller.
fd intstring — result string
getpeernamepub fn getpeername(fd int) stringExecute getpeername. Throws on failure; handle the error or propagate it to the caller.
fd intstring — result string
shutdownpub fn shutdown(fd int, how int) intExecute shutdown. Throws on failure; handle the error or propagate it to the caller.
fd inthow intint — a value of this type
sendtopub fn sendto(fd int, addr string, data string) intExecute sendto. Throws on failure; handle the error or propagate it to the caller.
fd intaddr stringdata stringint — a value of this type
recvfrompub fn recvfrom(fd int, max int) stringExecute recvfrom. Throws on failure; handle the error or propagate it to the caller.
fd intmax intstring — result string
fd_readpub fn fd_read(fd int, max int) stringFd read. Throws on failure; handle the error or propagate it to the caller.
fd intmax intstring — result string
fd_writepub fn fd_write(fd int, data string) intFd write. Throws on failure; handle the error or propagate it to the caller.
fd intdata stringint — a value of this type
fd_closepub fn fd_close(fd int) intFd close. Throws on failure; handle the error or propagate it to the caller.
fd intint — a value of this type
socket_readpub fn socket_read(fd int, max int) stringSocket-specific I/O. Generic fd_* maps to file handles on Windows Winsock SOCKETs must instead use recv/send/closesocket. Keep these wrappers private to the net package's higher-level Conn/PacketConn paths. Throws on failure; handle the error or propagate it to the caller.
fd intmax intstring — result string
socket_writepub fn socket_write(fd int, data string) intSocket write. Throws on failure; handle the error or propagate it to the caller.
fd intdata stringint — a value of this type
socket_closepub fn socket_close(fd int) intSocket close. Throws on failure; handle the error or propagate it to the caller.
fd intint — a value of this type
socket_pollpub fn socket_poll(fd int, events int) intsocket_poll checks readiness immediately. events is 1 for read/accept or 4 for write. Returns 0 when pending and 1 when ready (including EOF). The descriptor's blocking mode is unchanged. Throws on failure; handle the error or propagate it to the caller.
fd intevents intint — a value of this type
set_sock_read_timeoutpub fn set_sock_read_timeout(fd int, ns int) intSet sock read timeout. Throws on failure; handle the error or propagate it to the caller.
fd intns intint — a value of this type
set_sock_write_timeoutpub fn set_sock_write_timeout(fd int, ns int) intSet sock write timeout. Throws on failure; handle the error or propagate it to the caller.
fd intns intint — a value of this type
set_sock_timeoutpub fn set_sock_timeout(fd int, ns int) intset_sock_timeout sets SO_SNDTIMEO and SO_RCVTIMEO. ns is relative 0 clears. connect honors it on Darwin; Linux connect still uses SYN retries. read/write honor it on both. Throws on failure; handle the error or propagate it to the caller.
fd intns intint — a value of this type
setsockoptpub fn setsockopt(fd int, level int, optname int, value string) intsetsockopt passes value as the raw option bytes. level and optname use the host numbering (Darwin, Linux and Winsock differ); net keeps those tables. Throws on failure; handle the error or propagate it to the caller.
fd intlevel intoptname intvalue stringint — a value of this type
setsockopt_intpub fn setsockopt_int(fd int, level int, optname int, value int) intsetsockopt_int encodes value as a native 32-bit little-endian C int. Throws on failure; handle the error or propagate it to the caller.
fd intlevel intoptname intvalue intint — a value of this type
socket_waitpub fn socket_wait(fd int, events int, timeout_ns int) intsocket_wait waits for non-consuming readiness. events uses read=1 and write=2; the runtime normalizes error=4 and hangup=8 across platforms. Throws on failure; handle the error or propagate it to the caller.
fd intevents inttimeout_ns intint — a value of this type
fd_wait_readpub fn fd_wait_read(fd int, timeout_ns int) intfd_wait_read waits for file/pipe readability without consuming bytes or changing blocking mode. Returns 1 for data/EOF and 0 for a timeout. timeout_ns uses 0=infinite, negative=immediate. The caller must own reads from fd; readiness does not reserve bytes against another reader. POSIX poll accepts regular files, unlike Linux epoll. Windows probes pipe HANDLEs (0/1/2 map to standard handles) and treats disks as ready. Console signals can include non-key events, so complete console lines are not guaranteed. Polling has millisecond sleep granularity, not sub-ms latency no overlapped I/O or background reader remains after a timeout. Throws on failure; handle the error or propagate it to the caller.
fd inttimeout_ns intint — a value of this type
socket_wait_readpub fn socket_wait_read(fd int, timeout_ns int) intsocket_wait_read uses kernel poll (or task_poll_wait when peer tasks exist). Returns 1 for data/EOF, 0 for timeout; timeout_ns uses 0=infinite and negative=immediate. Poll errors propagate. The caller must own reads. Throws on failure; handle the error or propagate it to the caller.
fd inttimeout_ns intint — a value of this type
interface_datapub fn interface_data(name string) stringinterface_data returns the host network-interface snapshot used by the net package. Passing an empty name returns NUL-separated interface names passing a name returns a fixed binary metadata record. Platform ABI structs stay behind this os/runtime boundary. Throws on failure; handle the error or propagate it to the caller.
name stringstring — result string
(&File) read_npub fn (f &File) read_n(n int) stringio.StreamReader/StreamWriter adapters. These use the existing descriptor callers retain responsibility for close and may continue using File APIs. Throws on failure; handle the error or propagate it to the caller.
f &FileFile instance used by this call (borrow).n intstring — result string
(&File) write_strpub fn (f &File) write_str(data string) intOperation on &File: write a string. Throws on failure; handle the error or propagate it to the caller.
f &FileFile instance used by this call (borrow).data stringint — a value of this type