import { StreamReader } from "../stream.js"; import { FutureReader } from "../future.js"; /** * Creates a new TCP socket * WIT: createTcpSocket: func(address-family: ip-address-family) -> result * * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6) * @returns {TcpSocket>} A new TCP socket instance * @throws {SocketError} with payload.tag 'invalid-argument' if `addressFamily` is not IPV4 or IPV6 * @throws {SocketError} for other errors, payload.tag maps the low-level system error_ */ export declare function createTcpSocket(addressFamily: any): TcpSocket; export declare class TcpSocket { #private; /** * WIT static constructor for `wasi:sockets/types.tcp-socket`. * * WIT: * ``` * create: static func(address-family: ip-address-family) -> result * ``` * * @static * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6) * @returns {TcpSocket} A new TcpSocket instance * @throws {SocketError} with payload.tag 'invalid-argument' if `addressFamily` is not IPV4 or IPV6 * @throws {SocketError} for other socket creation errors */ static create(addressFamily: any): TcpSocket; /** * Creates a new TCP socket * WIT: * ``` * constructor(address-family: ip-address-family) * ``` * * @static * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6) * @param {number} socketId - The internal socket identifier * @returns {TcpSocket} A new TcpSocket instance * @private */ static _create(t: any, addressFamily: any, socketId: any): TcpSocket; /** * Binds the socket to a local address * WIT: * ``` * bind: func(local-address: ip-socket-address) -> result<_, error-code> * ``` * * @param {Object} localAddress - The local address to bind to * @returns {void} * @throws {SocketError} with payload.tag 'invalid-state' if the socket is not in ~STATE.UNBOUND~ * @throws {SocketError} with payload.tag 'invalid-argument' if ~localAddress~ is invalid * @throws {SocketError} for other errors, payload.tag maps the system error */ bind(localAddress: any): void; /** * Connects to a remote endpoint * WIT: * ``` * connect: async func(remote-address: ip-socket-address) -> result<_, error-code> * ``` * * @async * @param {Object} remoteAddress - The remote address to connect to * @returns {Promise} * @throws {SocketError} with payload.tag 'invalid-state' if socket is CONNECTING, CONNECTED, or LISTENING * @throws {SocketError} with payload.tag 'invalid-argument' if ~remoteAddress~ is invalid or port == 0 * @throws {SocketError} for other errors, payload.tag maps the system error */ connect(remoteAddress: any): Promise; /** * Starts listening for connections * WIT: * ``` * listen: func() -> result, error-code> * ``` * * @returns {StreamReader} A stream of incoming TCP socket connections * @throws {SocketError} with payload.tag 'invalid-state' if socket is LISTENING or CONNECTED * @throws {SocketError} for other errors, payload.tag maps the system error */ listen(): StreamReader; /** * Sends data to the connected peer * WIT: * ``` * send: async func(data: stream) -> result<_, error-code> * ``` * * @async * @param {object} data - The byte stream to send. * @returns {Promise} * @throws {SocketError} With payload.tag 'invalid-state' if socket is not CONNECTED * @throws {SocketError} With payload.tag 'invalid-argument' if `data` is not a readable byte stream * @throws {SocketError} for other errors, payload.tag maps the system error */ send(data: any): Promise; /** * Receives data from the connected peer * WIT: * ``` * receive: func() -> tuple, future>> * ``` * * @throws {SocketError} with payload.tag 'invalid-state' if socket is not CONNECTED * @throws {SocketError} for other errors, payload.tag maps the system error * @returns {{ stream: StreamReader, future: FutureReader }} */ receive(): (StreamReader | FutureReader)[]; /** * Gets the bound local address * WIT: * ``` * local-address: func() -> result * ``` * * @returns {Object} The local socket address * @throws {SocketError} with payload.tag 'invalid-state' if socket is not BOUND * @throws {SocketError} for other errors, payload.tag maps the system error */ getLocalAddress(): any; /** * Gets the remote address * WIT: * ``` * remote-address: func() -> result * ``` * * @returns {Object} The remote socket address * @throws {SocketError} with payload.tag 'invalid-state' if socket is not CONNECTED * @throws {SocketError} for other errors, payload.tag maps the system error */ getRemoteAddress(): any; /** * Checks if the socket is in listening state * WIT: * ``` * is-listening: func() -> bool * ``` * * @returns {boolean} True if socket is listening, false otherwise */ getIsListening(): boolean; /** * Gets the address family * WIT: * ``` * address-family: func() -> ip-address-family * ``` * * @returns {IP_ADDRESS_FAMILY} The IP address family (IPv4 or IPv6) */ getAddressFamily(): any; /** * Sets the listen backlog size * WIT: * ``` * set-listen-backlog-size: func(value: u64) -> result<_, error-code> * ``` * * @param {bigint} value - The backlog size * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is 0 * @throws {SocketError} with payload.tag 'not-supported' if socket is CONNECTING or CONNECTED * @throws {SocketError} with payload.tag 'invalid-state' if socket is not UNBOUND or BOUND * @throws {SocketError} for other errors, payload.tag maps the system error */ setListenBacklogSize(value: any): void; /** * Gets whether keep-alive is enabled * WIT: * ``` * keep-alive-enabled: func() -> result * ``` * * @returns {boolean} True if keep-alive is enabled, false otherwise */ getKeepAliveEnabled(): boolean; /** * Sets keep-alive enabled state * WIT: * ``` * set-keep-alive-enabled: func(value: bool) -> result<_, error-code> * ``` * * @async * @param {boolean} value - Whether to enable keep-alive * @returns {void} * @throws {SocketError} for other errors, payload.tag maps the system error */ setKeepAliveEnabled(value: any): void; /** * Gets the keep-alive idle time * WIT: * ``` * keep-alive-idle-time: func() -> result * ``` * * @returns {bigint} The keep-alive idle time in nanoseconds */ getKeepAliveIdleTime(): bigint; /** * Sets the keep-alive idle time * WIT: * ``` * set-keep-alive-idle-time: func(value: duration) -> result<_, error-code> * ``` * * @param {bigint} value - The idle time in nanoseconds * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1 * @throws {SocketError} for other errors, payload.tag maps the system error */ setKeepAliveIdleTime(value: any): void; /** * Gets the keep-alive interval * WIT: * ``` * keep-alive-interval: func() -> result * ``` * * @returns {bigint} The keep-alive interval in nanoseconds */ getKeepAliveInterval(): bigint; /** * Sets the keep-alive interval * WIT: * ``` * set-keep-alive-interval: func(value: duration) -> result<_, error-code> * ``` * * @param {bigint} value - The interval in nanoseconds * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1 */ setKeepAliveInterval(value: any): void; /** * Gets the keep-alive count * WIT: * ``` * keep-alive-count: func() -> result * ``` * * @returns {number} The keep-alive count */ getKeepAliveCount(): number; /** * Sets the keep-alive count * WIT: * ``` * set-keep-alive-count: func(value: u32) -> result<_, error-code> * ``` * * @param {number} value - The keep-alive count * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1 */ setKeepAliveCount(value: any): void; /** * Gets the hop limit * WIT: * ``` * hop-limit: func() -> result * ``` * * @returns {number} The hop limit */ getHopLimit(): number; /** * Sets the hop limit * WIT: * ``` * set-hop-limit: func(value: u8) -> result<_, error-code> * ``` * * @param {number} value - The hop limit * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1 */ setHopLimit(value: any): void; /** * Gets the receive buffer size * WIT: * ``` * receive-buffer-size: func() -> result * ``` * * @returns {bigint} The receive buffer size in bytes * @throws {SocketError} for other errors, payload.tag maps the system error */ getReceiveBufferSize(): any; /** * Sets the receive buffer size * WIT: * ``` * set-receive-buffer-size: func(value: u64) -> result<_, error-code> * ``` * * @param {bigint} value - The receive buffer size in bytes * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is 0 */ setReceiveBufferSize(value: any): void; /** * Gets the send buffer size * WIT: * ``` * send-buffer-size: func() -> result * ``` * * @returns {bigint} The send buffer size in bytes * @throws {SocketError} for other errors, payload.tag maps the system error */ getSendBufferSize(): any; /** * Sets the send buffer size * WIT: * ``` * set-send-buffer-size: func(value: u64) -> result<_, error-code> * ``` * * @param {bigint} value - The send buffer size in bytes * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is 0 */ setSendBufferSize(value: any): void; /** * Disposes the socket */ [Symbol.dispose](): void; }