/** * Create a new UDP socket. * WIT: * ``` * createUdpSocket: func(address-family: ip-address-family) -> result * ``` * * @async * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family * @returns {Promise} * @throws {SocketError} with payload.tag 'invalid-argument' if ~addressFamily~ is not IPv4 or IPv6 * @throws {SocketError} for other errors, payload.tag maps the system error */ export declare function createUdpSocket(addressFamily: any): UdpSocket; export declare class UdpSocket { #private; /** * WIT static constructor for `wasi:sockets/types.udp-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 {UdpSocket} A new UdpSocket 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): UdpSocket; /** * Creates a new UDP socket * WIT: * ``` * constructor(address-family: ip-address-family) * ``` * * @static * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6) * @param {string} socketId - The internal socket identifier * @returns {UdpSocket} A new UdpSocket instance * @private */ static _create(t: any, addressFamily: any, socketId: any): UdpSocket; /** * Bind the socket to the provided IP address and port. * 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; /** * Associate this socket with a specific peer address. * WIT: * ``` * connect: func(remote-address: ip-socket-address) -> result<_, error-code> * ``` * * @param {Object} remoteAddress - The remote address to connect to * @returns {void} * @throws {SocketError} with payload.tag 'invalid-state' if the socket is already connected * @throws {SocketError} with payload.tag 'invalid-argument' if ~remoteAddress~ is invalid or wildcard * @throws {SocketError} for other errors, payload.tag maps the system error */ connect(remoteAddress: any): void; /** * Dissociate this socket from its peer address. * WIT: * ``` * disconnect: func() -> result<_, error-code> * ``` * * @returns {void} * @throws {SocketError} with payload.tag 'invalid-state' if the socket is not connected * @throws {SocketError} for other errors, payload.tag maps the system error */ disconnect(): void; /** * Send a message on the socket to a particular peer. * WIT: * ``` * send: func(data: list, remote-address: option) -> result<_, error-code> * ``` * * @async * @param {Uint8Array} data - The datagram payload * @param {?Object} remoteAddress Optional peer address if not connected. * @returns {Promise} * @throws {SocketError} with payload.tag 'invalid-state' if socket is not bound * @throws {SocketError} with payload.tag 'invalid-argument' if ~data~ is not a Uint8Array or address invalid * @throws {SocketError} for other errors, payload.tag maps the system error */ send(data: any, remoteAddress?: any): Promise; /** * Receive a message on the socket. * WIT: * ``` * receive: func() -> result, ip-socket-address>, error-code> * ``` * * @async * @returns {Promise<[Uint8Array, Object]>} Received data and sender address * @throws {SocketError} with payload.tag 'invalid-state' if socket has not been bound * @throws {SocketError} for other errors, payload.tag maps the system error */ receive(): Promise; /** * Get the current bound address. * WIT: * ``` * local-address: func() -> result * ``` * * @returns {Object} The local socket address * @throws {SocketError} with payload.tag 'invalid-state' if the socket hasn't been bound yet * @throws {SocketError} for other errors, payload.tag maps the system error */ getLocalAddress(): any; /** * Get the address the socket is currently connected to. * WIT: * ``` * remote-address: func() -> result * ``` * * @returns {Object} The connected peer address * @throws {SocketError} with payload.tag 'invalid-state' if the socket is not connected */ getRemoteAddress(): any; /** * Whether this is an IPv4 or IPv6 socket. * WIT: * ``` * address-family: func() -> ip-address-family * ``` * * @returns {IP_ADDRESS_FAMILY} */ getAddressFamily(): any; /** * Get the unicast hop limit (TTL). * WIT: * ``` * unicast-hop-limit: func() -> result * ``` * * @returns {number} */ getUnicastHopLimit(): number; /** * Set the unicast hop limit (TTL). * WIT: * ``` * set-unicast-hop-limit: func(value: u8) -> result<_, error-code> * ``` * * @param {number} value - The hop limit (must be ≥1) * @returns {void} * @throws {SocketError} with payload.tag 'invalid-argument' if value < 1 * @throws {SocketError} for other errors, payload.tag maps the system error */ setUnicastHopLimit(value: any): void; /** * Get the receive buffer size. * WIT: * ``` * receive-buffer-size: func() -> result * ``` * * @returns {bigint} * @throws {SocketError} payload.tag maps the system error */ getReceiveBufferSize(): any; /** * Set the receive buffer size. * WIT: * ``` * set-receive-buffer-size: func(value: u64) -> result<_, error-code> * ``` * * @param {bigint} value - The buffer size in bytes (must be >0) * @throws {SocketError} payload.tag maps the system error */ setReceiveBufferSize(value: any): void; /** * Get the send buffer size. * WIT: * ``` * send-buffer-size: func() -> result * ``` * * @async * @returns {bigint} * @throws {SocketError} payload.tag maps the system error */ getSendBufferSize(): any; /** * Set the send buffer size. * WIT: * ``` * set-send-buffer-size: func(value: u64) -> result<_, error-code> * ``` * * @param {bigint} value - The buffer size in bytes (must be >0) * @throws {SocketError} with payload.tag 'invalid-argument' if value == 0 */ setSendBufferSize(value: any): void; /** * Dispose the socket. * * Releases native resources and marks the socket as closed. */ [Symbol.dispose](): void; } export declare const udpCreateSocket: {};