EgretDoc
Back to Home
Location:system/net.tcp

Module

Module documentation.

modulenet.tcp

Classes

Classes and inheritance.

classnet.tcp::TcpConn
@brief`TcpConn` type.
@details`TcpConn` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class TcpConn {
    /*
    @brief `fd` field.

Functions

Free functions and class methods.

functionnet.tcp::__tcp_connect
Signatureextern func __tcp_connect(host: String, port: Int, timeout_ms: Int) -> Int;
extern func __tcp_connect(host: String, port: Int, timeout_ms: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__tcp_listen`.
@briefBinds the low-level runtime symbol `__tcp_connect`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • hostHost name or listen address.
  • portPort number.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionnet.tcp::__tcp_listen
Signatureextern func __tcp_listen(host: String, port: Int, backlog: Int) -> Int;
extern func __tcp_listen(host: String, port: Int, backlog: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__tcp_accept`.
@briefBinds the low-level runtime symbol `__tcp_listen`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • hostHost name or listen address.
  • portPort number.
  • backlogMaximum number of pending inbound connections accepted by the listening socket.
@returnReturns the operation result as `Int`.
functionnet.tcp::__tcp_accept
Signatureextern func __tcp_accept(fd: Int, timeout_ms: Int) -> Int;
extern func __tcp_accept(fd: Int, timeout_ms: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__tcp_sock_port`.
@briefBinds the low-level runtime symbol `__tcp_accept`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionnet.tcp::__tcp_sock_port
Signatureextern func __tcp_sock_port(fd: Int) -> Int;
extern func __tcp_sock_port(fd: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__tcp_send`.
@briefBinds the low-level runtime symbol `__tcp_sock_port`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnReturns the operation result as `Int`.
functionnet.tcp::__tcp_send
Signatureextern func __tcp_send(fd: Int, data: String, timeout_ms: Int) -> Int;
extern func __tcp_send(fd: Int, data: String, timeout_ms: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__tcp_recv`.
@briefBinds the low-level runtime symbol `__tcp_send`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • dataInput or output data buffer.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionnet.tcp::__tcp_recv
Signatureextern func __tcp_recv(fd: Int, max_bytes: Int, timeout_ms: Int) -> String;
extern func __tcp_recv(fd: Int, max_bytes: Int, timeout_ms: Int) -> String;
/*
@brief Binds the low-level runtime symbol `__tcp_close`.
@briefBinds the low-level runtime symbol `__tcp_recv`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • max_bytesMaximum number of bytes to read or process in this operation.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `String`.
functionnet.tcp::__tcp_close
Signatureextern func __tcp_close(fd: Int) -> Void;
extern func __tcp_close(fd: Int) -> Void;

/*
@briefBinds the low-level runtime symbol `__tcp_close`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnVoid
functionnet.tcp::TcpConn.init
Signaturefunc init(self: net.tcp.TcpConn, fd: Int = -1, owns_fd: Bool = false) -> Void
    func init(self: net.tcp.TcpConn, fd: Int = -1, owns_fd: Bool = false) -> Void {
        self.fd = fd;
        self.closed = false;
@briefInitializes a `TcpConn` instance.
@detailsEstablishes the initial field state for `TcpConn` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
  • fdOperating-system file descriptor or socket descriptor.
  • owns_fdWhether the object owns the file descriptor and must close it during cleanup.
@returnVoid
functionnet.tcp::TcpConn.close
Signaturefunc close(self: net.tcp.TcpConn) -> Void
    func close(self: net.tcp.TcpConn) -> Void {
        if self.owns_fd && !self.closed && self.fd > 0 {
            _ = __tcp_close(self.fd);
@briefCloses resources and makes later operations unavailable with `TcpConn.close`.
@detailsExecutes the `close` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.tcp::TcpConn.dispose
Signaturefunc dispose(self: net.tcp.TcpConn) -> Void
    func dispose(self: net.tcp.TcpConn) -> Void {
        _ = self.close();
    }
@briefExplicitly releases resources owned by `TcpConn`.
@detailsThis method deterministically cleans up file descriptors, network connections, native handles, buffers, or other external resources. Implementations should be idempotent where possible, and repeated calls must not corrupt object state.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.tcp::TcpConn.deinit
Signaturefunc deinit(self: net.tcp.TcpConn) -> Void
    func deinit(self: net.tcp.TcpConn) -> Void {
        _ = self.close();
    }
@briefReleases fallback resources at the end of the `TcpConn` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
  • selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionnet.tcp::tcp_connect
Signaturefunc tcp_connect(host: String, port: Int, timeout_ms: Int) -> Int
func tcp_connect(host: String, port: Int, timeout_ms: Int) -> Int {
    return __tcp_connect(host, port, timeout_ms);
}
@briefProvides the system library operation `tcp_connect`.
@detailsExecutes the `tcp_connect` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • hostHost name or listen address.
  • portPort number.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionnet.tcp::tcp_listen
Signaturefunc tcp_listen(host: String, port: Int, backlog: Int) -> Int
func tcp_listen(host: String, port: Int, backlog: Int) -> Int {
    return __tcp_listen(host, port, backlog);
}
@briefProvides the system library operation `tcp_listen`.
@detailsExecutes the `tcp_listen` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • hostHost name or listen address.
  • portPort number.
  • backlogMaximum number of pending inbound connections accepted by the listening socket.
@returnReturns the operation result as `Int`.
functionnet.tcp::tcp_accept
Signaturefunc tcp_accept(fd: Int, timeout_ms: Int) -> Int
func tcp_accept(fd: Int, timeout_ms: Int) -> Int {
    return __tcp_accept(fd, timeout_ms);
}
@briefProvides the system library operation `tcp_accept`.
@detailsExecutes the `tcp_accept` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionnet.tcp::tcp_sock_port
Signaturefunc tcp_sock_port(fd: Int) -> Int
func tcp_sock_port(fd: Int) -> Int {
    return __tcp_sock_port(fd);
}
@briefProvides the system library operation `tcp_sock_port`.
@detailsExecutes the `tcp_sock_port` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnReturns the operation result as `Int`.
functionnet.tcp::tcp_send
Signaturefunc tcp_send(fd: Int, data: String, timeout_ms: Int) -> Int
func tcp_send(fd: Int, data: String, timeout_ms: Int) -> Int {
    return __tcp_send(fd, data, timeout_ms);
}
@briefProvides the system library operation `tcp_send`.
@detailsExecutes the `tcp_send` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • dataInput or output data buffer.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionnet.tcp::tcp_recv
Signaturefunc tcp_recv(fd: Int, max_bytes: Int, timeout_ms: Int) -> String
func tcp_recv(fd: Int, max_bytes: Int, timeout_ms: Int) -> String {
    return __tcp_recv(fd, max_bytes, timeout_ms);
}
@briefProvides the system library operation `tcp_recv`.
@detailsExecutes the `tcp_recv` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • max_bytesMaximum number of bytes to read or process in this operation.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `String`.
functionnet.tcp::tcp_close
Signaturefunc tcp_close(fd: Int) -> Void
func tcp_close(fd: Int) -> Void {
    _ = __tcp_close(fd);
}
@briefProvides the system library operation `tcp_close`.
@detailsExecutes the `tcp_close` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnVoid
functionnet.tcp::connect
Signaturefunc connect(host: String, port: Int, timeout_ms: Int = -1) -> Int, ErrCode
func connect(host: String, port: Int, timeout_ms: Int = -1) -> Int, ErrCode {
    _ = net.clear_last_error();
    let fd: Int = __tcp_connect(host, port, timeout_ms);
@briefEstablishes a connection with `connect`.
@detailsExecutes the `connect` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • hostHost name or listen address.
  • portPort number.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::connect_conn
Signaturefunc connect_conn(host: String, port: Int, timeout_ms: Int = -1) -> net.tcp.TcpConn, ErrCode
func connect_conn(host: String, port: Int, timeout_ms: Int = -1) -> net.tcp.TcpConn, ErrCode {
    let fd: Int = connect(host, port, timeout_ms)?;
    return new net.tcp.TcpConn(fd, true), std.OK;
@briefProvides the system library operation `connect_conn`.
@detailsExecutes the `connect_conn` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • hostHost name or listen address.
  • portPort number.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns `net.tcp.TcpConn, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::conn
Signaturefunc conn(fd: Int) -> net.tcp.TcpConn
func conn(fd: Int) -> net.tcp.TcpConn {
    return new net.tcp.TcpConn(fd);
}
@briefProvides the system library operation `conn`.
@detailsExecutes the `conn` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnReturns the operation result as `net.tcp.TcpConn`.
functionnet.tcp::listen
Signaturefunc listen(host: String, port: Int, backlog: Int) -> Int, ErrCode
func listen(host: String, port: Int, backlog: Int) -> Int, ErrCode {
    _ = net.clear_last_error();
    let fd: Int = __tcp_listen(host, port, backlog);
@briefCreates a listening endpoint with `listen`.
@detailsExecutes the `listen` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • hostHost name or listen address.
  • portPort number.
  • backlogMaximum number of pending inbound connections accepted by the listening socket.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::accept
Signaturefunc accept(fd: Int, timeout_ms: Int = -1) -> Int, ErrCode
func accept(fd: Int, timeout_ms: Int = -1) -> Int, ErrCode {
    _ = net.clear_last_error();
    let c: Int = __tcp_accept(fd, timeout_ms);
@briefAccepts an incoming connection with `accept`.
@detailsExecutes the `accept` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::sock_port
Signaturefunc sock_port(fd: Int) -> Int, ErrCode
func sock_port(fd: Int) -> Int, ErrCode {
    let p: Int = __tcp_sock_port(fd);
    if p > 0 {
@briefProvides the system library operation `sock_port`.
@detailsExecutes the `sock_port` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::set_nonblock
Signaturefunc set_nonblock(fd: Int) -> ErrCode
func set_nonblock(fd: Int) -> ErrCode {
    return net.set_nonblock(fd);
}
@briefSets state or configuration with `set_nonblock`.
@detailsExecutes the `set_nonblock` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::send
Signaturefunc send(fd: Int, data: String, timeout_ms: Int = -1) -> Int, ErrCode
func send(fd: Int, data: String, timeout_ms: Int = -1) -> Int, ErrCode {
    _ = net.clear_last_error();
    let n: Int = __tcp_send(fd, data, timeout_ms);
@briefSends data with `send`.
@detailsExecutes the `send` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • dataInput or output data buffer.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::recv
Signaturefunc recv(fd: Int, max_bytes: Int, timeout_ms: Int = -1) -> String, ErrCode
func recv(fd: Int, max_bytes: Int, timeout_ms: Int = -1) -> String, ErrCode {
    _ = net.clear_last_error();
    let s: String = __tcp_recv(fd, max_bytes, timeout_ms);
@briefReceives data with `recv`.
@detailsExecutes the `recv` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
  • max_bytesMaximum number of bytes to read or process in this operation.
  • timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns `String, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionnet.tcp::close
Signaturefunc close(fd: Int) -> Void
func close(fd: Int) -> Void {
    _ = __tcp_close(fd);
    return;
@briefCloses resources and makes later operations unavailable with `close`.
@detailsExecutes the `close` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • fdOperating-system file descriptor or socket descriptor.
@returnVoid

Variables

Class fields (var).

varnet.tcp::TcpConn.fd
TypeInt
@brief`fd` field.
@detailsStores the underlying file descriptor or socket descriptor. The field type is `Int`, and it is maintained by the constructors and methods of `TcpConn`.
    var fd: Int;
    /*
    @brief `closed` field.
varnet.tcp::TcpConn.closed
TypeBool
@brief`closed` field.
@detailsIndicates whether the resource has already been closed. The field type is `Bool`, and it is maintained by the constructors and methods of `TcpConn`.
    var closed: Bool;
    /*
    @brief `owns_fd` field.
varnet.tcp::TcpConn.owns_fd
TypeBool
@brief`owns_fd` field.
@detailsIndicates whether the object owns and must close the file descriptor. The field type is `Bool`, and it is maintained by the constructors and methods of `TcpConn`.
    var owns_fd: Bool;

    /*