@bytecodealliance/preview2-shim 0.0.21 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +4 -14
  2. package/lib/browser/cli.js +2 -4
  3. package/lib/browser/clocks.js +15 -27
  4. package/lib/browser/filesystem.js +2 -30
  5. package/lib/browser/http.js +1 -3
  6. package/lib/browser/io.js +4 -2
  7. package/lib/common/assert.js +7 -0
  8. package/lib/io/calls.js +64 -0
  9. package/lib/io/worker-http.js +95 -0
  10. package/lib/io/worker-io.js +322 -0
  11. package/lib/io/worker-thread.js +569 -0
  12. package/lib/nodejs/cli.js +45 -59
  13. package/lib/nodejs/clocks.js +13 -27
  14. package/lib/nodejs/filesystem.js +539 -459
  15. package/lib/nodejs/http.js +440 -173
  16. package/lib/nodejs/index.js +4 -1
  17. package/lib/nodejs/io.js +1 -0
  18. package/lib/nodejs/sockets/socket-common.js +116 -0
  19. package/lib/nodejs/sockets/socketopts-bindings.js +94 -0
  20. package/lib/nodejs/sockets/tcp-socket-impl.js +794 -0
  21. package/lib/nodejs/sockets/udp-socket-impl.js +628 -0
  22. package/lib/nodejs/sockets/wasi-sockets.js +320 -0
  23. package/lib/nodejs/sockets.js +11 -200
  24. package/lib/synckit/index.js +4 -2
  25. package/package.json +1 -5
  26. package/types/interfaces/wasi-cli-terminal-input.d.ts +4 -0
  27. package/types/interfaces/wasi-cli-terminal-output.d.ts +4 -0
  28. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +19 -6
  29. package/types/interfaces/wasi-filesystem-types.d.ts +1 -178
  30. package/types/interfaces/wasi-http-outgoing-handler.d.ts +2 -2
  31. package/types/interfaces/wasi-http-types.d.ts +412 -82
  32. package/types/interfaces/wasi-io-error.d.ts +16 -0
  33. package/types/interfaces/wasi-io-poll.d.ts +19 -8
  34. package/types/interfaces/wasi-io-streams.d.ts +26 -46
  35. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +9 -21
  36. package/types/interfaces/wasi-sockets-network.d.ts +4 -0
  37. package/types/interfaces/wasi-sockets-tcp.d.ts +75 -18
  38. package/types/interfaces/wasi-sockets-udp-create-socket.d.ts +1 -1
  39. package/types/interfaces/wasi-sockets-udp.d.ts +282 -193
  40. package/types/wasi-cli-command.d.ts +28 -28
  41. package/types/wasi-http-proxy.d.ts +12 -12
  42. package/lib/common/io.js +0 -183
  43. package/lib/common/make-request.js +0 -30
  44. package/types/interfaces/wasi-clocks-timezone.d.ts +0 -56
@@ -4,9 +4,7 @@ export namespace WasiSocketsUdp {
4
4
  *
5
5
  * If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
6
6
  * network interface(s) to bind to.
7
- * If the TCP/UDP port is zero, the socket will be bound to a random free port.
8
- *
9
- * When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket.
7
+ * If the port is zero, the socket will be bound to a random free port.
10
8
  *
11
9
  * Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
12
10
  *
@@ -29,193 +27,284 @@ export namespace WasiSocketsUdp {
29
27
  */
30
28
  export { UdpSocket };
31
29
  /**
32
- * Set the destination address.
33
- *
34
- * The local-address is updated based on the best network path to `remote-address`.
35
- *
36
- * When a destination address is set:
37
- * - all receive operations will only return datagrams sent from the provided `remote-address`.
38
- * - the `send` function can only be used to send to this destination.
39
- *
40
- * Note that this function does not generate any network traffic and the peer is not aware of this "connection".
41
- *
42
- * Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
43
- *
44
- * # Typical `start` errors
45
- * - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
46
- * - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa)
47
- * - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
48
- * - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
49
- * - `invalid-argument`: The socket is already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
50
- *
51
- * # Typical `finish` errors
52
- * - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
53
- * - `not-in-progress`: A `connect` operation is not in progress.
54
- * - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
55
- *
56
- * # References
57
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
58
- * - <https://man7.org/linux/man-pages/man2/connect.2.html>
59
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
60
- * - <https://man.freebsd.org/cgi/man.cgi?connect>
61
- */
62
- /**
63
- * Receive messages on the socket.
64
- *
65
- * This function attempts to receive up to `max-results` datagrams on the socket without blocking.
66
- * The returned list may contain fewer elements than requested, but never more.
67
- * If `max-results` is 0, this function returns successfully with an empty list.
68
- *
69
- * # Typical errors
70
- * - `invalid-state`: The socket is not bound to any local address. (EINVAL)
71
- * - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
72
- * - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN)
73
- *
74
- * # References
75
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>
76
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>
77
- * - <https://man7.org/linux/man-pages/man2/recv.2.html>
78
- * - <https://man7.org/linux/man-pages/man2/recvmmsg.2.html>
79
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv>
80
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom>
81
- * - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
82
- * - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
83
- */
84
- /**
85
- * Send messages on the socket.
86
- *
87
- * This function attempts to send all provided `datagrams` on the socket without blocking and
88
- * returns how many messages were actually sent (or queued for sending).
89
- *
90
- * This function semantically behaves the same as iterating the `datagrams` list and sequentially
91
- * sending each individual datagram until either the end of the list has been reached or the first error occurred.
92
- * If at least one datagram has been sent successfully, this function never returns an error.
93
- *
94
- * If the input list is empty, the function returns `ok(0)`.
95
- *
96
- * The remote address option is required. To send a message to the "connected" peer,
97
- * call `remote-address` to get their address.
98
- *
99
- * # Typical errors
100
- * - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
101
- * - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa)
102
- * - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
103
- * - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
104
- * - `invalid-argument`: The socket is in "connected" mode and the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN)
105
- * - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind.
106
- * - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
107
- * - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
108
- * - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN)
109
- *
110
- * # References
111
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
112
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
113
- * - <https://man7.org/linux/man-pages/man2/send.2.html>
114
- * - <https://man7.org/linux/man-pages/man2/sendmmsg.2.html>
115
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send>
116
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto>
117
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
118
- * - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
119
- */
120
- /**
121
- * Get the current bound address.
122
- *
123
- * POSIX mentions:
124
- * > If the socket has not been bound to a local name, the value
125
- * > stored in the object pointed to by `address` is unspecified.
126
- *
127
- * WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
128
- *
129
- * # Typical errors
130
- * - `invalid-state`: The socket is not bound to any local address.
131
- *
132
- * # References
133
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
134
- * - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
135
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
136
- * - <https://man.freebsd.org/cgi/man.cgi?getsockname>
137
- */
138
- /**
139
- * Get the address set with `connect`.
140
- *
141
- * # Typical errors
142
- * - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN)
143
- *
144
- * # References
145
- * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
146
- * - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
147
- * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
148
- * - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
149
- */
150
- /**
151
- * Whether this is a IPv4 or IPv6 socket.
152
- *
153
- * Equivalent to the SO_DOMAIN socket option.
154
- */
155
- /**
156
- * Whether IPv4 compatibility (dual-stack) mode is disabled or not.
157
- *
158
- * Equivalent to the IPV6_V6ONLY socket option.
159
- *
160
- * # Typical errors
161
- * - `not-supported`: (get/set) `this` socket is an IPv4 socket.
162
- * - `invalid-state`: (set) The socket is already bound.
163
- * - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.)
164
- */
165
- /**
166
- * Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
167
- */
168
- /**
169
- * The kernel buffer space reserved for sends/receives on this socket.
170
- *
171
- * Note #1: an implementation may choose to cap or round the buffer size when setting the value.
172
- * In other words, after setting a value, reading the same setting back may return a different value.
173
- *
174
- * Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
175
- * actual data to be sent/received by the application, because the kernel might also use the buffer space
176
- * for internal metadata structures.
177
- *
178
- * Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
179
- */
180
- /**
181
- * Create a `pollable` which will resolve once the socket is ready for I/O.
182
- *
183
- * Note: this function is here for WASI Preview2 only.
184
- * It's planned to be removed when `future` is natively supported in Preview3.
185
- */
186
- }
187
- import type { Pollable } from '../interfaces/wasi-io-poll.js';
188
- export { Pollable };
189
- import type { Network } from '../interfaces/wasi-sockets-network.js';
190
- export { Network };
191
- import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
192
- export { ErrorCode };
193
- import type { IpSocketAddress } from '../interfaces/wasi-sockets-network.js';
194
- export { IpSocketAddress };
195
- import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
196
- export { IpAddressFamily };
197
- export interface Datagram {
198
- data: Uint8Array,
199
- remoteAddress: IpSocketAddress,
200
- }
201
-
202
- export class UdpSocket {
203
- startBind(network: Network, localAddress: IpSocketAddress): void;
204
- finishBind(): void;
205
- startConnect(network: Network, remoteAddress: IpSocketAddress): void;
206
- finishConnect(): void;
207
- receive(maxResults: bigint): Datagram[];
208
- send(datagrams: Datagram[]): bigint;
209
- localAddress(): IpSocketAddress;
210
- remoteAddress(): IpSocketAddress;
211
- addressFamily(): IpAddressFamily;
212
- ipv6Only(): boolean;
213
- setIpv6Only(value: boolean): void;
214
- unicastHopLimit(): number;
215
- setUnicastHopLimit(value: number): void;
216
- receiveBufferSize(): bigint;
217
- setReceiveBufferSize(value: bigint): void;
218
- sendBufferSize(): bigint;
219
- setSendBufferSize(value: bigint): void;
220
- subscribe(): Pollable;
221
- }
30
+ * Set up inbound & outbound communication channels, optionally to a specific peer.
31
+ *
32
+ * This function only changes the local socket configuration and does not generate any network traffic.
33
+ * On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well,
34
+ * based on the best network path to `remote-address`.
35
+ *
36
+ * When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer:
37
+ * - `send` can only be used to send to this destination.
38
+ * - `receive` will only return datagrams sent from the provided `remote-address`.
39
+ *
40
+ * This method may be called multiple times on the same socket to change its association, but
41
+ * only the most recently returned pair of streams will be operational. Implementations may trap if
42
+ * the streams returned by a previous invocation haven't been dropped yet before calling `stream` again.
43
+ *
44
+ * The POSIX equivalent in pseudo-code is:
45
+ * ```text
46
+ * if (was previously connected) {
47
+ * connect(s, AF_UNSPEC)
48
+ * }
49
+ * if (remote_address is Some) {
50
+ * connect(s, remote_address)
51
+ * }
52
+ * ```
53
+ *
54
+ * Unlike in POSIX, the socket must already be explicitly bound.
55
+ *
56
+ * # Typical errors
57
+ * - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
58
+ * - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa)
59
+ * - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
60
+ * - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
61
+ * - `invalid-state`: The socket is not bound.
62
+ * - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
63
+ * - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
64
+ * - `connection-refused`: The connection was refused. (ECONNREFUSED)
65
+ *
66
+ * # References
67
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
68
+ * - <https://man7.org/linux/man-pages/man2/connect.2.html>
69
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
70
+ * - <https://man.freebsd.org/cgi/man.cgi?connect>
71
+ */
72
+ /**
73
+ * Get the current bound address.
74
+ *
75
+ * POSIX mentions:
76
+ * > If the socket has not been bound to a local name, the value
77
+ * > stored in the object pointed to by `address` is unspecified.
78
+ *
79
+ * WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
80
+ *
81
+ * # Typical errors
82
+ * - `invalid-state`: The socket is not bound to any local address.
83
+ *
84
+ * # References
85
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
86
+ * - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
87
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
88
+ * - <https://man.freebsd.org/cgi/man.cgi?getsockname>
89
+ */
90
+ /**
91
+ * Get the address the socket is currently streaming to.
92
+ *
93
+ * # Typical errors
94
+ * - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN)
95
+ *
96
+ * # References
97
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
98
+ * - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
99
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
100
+ * - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
101
+ */
102
+ /**
103
+ * Whether this is a IPv4 or IPv6 socket.
104
+ *
105
+ * Equivalent to the SO_DOMAIN socket option.
106
+ */
107
+ /**
108
+ * Whether IPv4 compatibility (dual-stack) mode is disabled or not.
109
+ *
110
+ * Equivalent to the IPV6_V6ONLY socket option.
111
+ *
112
+ * # Typical errors
113
+ * - `not-supported`: (get/set) `this` socket is an IPv4 socket.
114
+ * - `invalid-state`: (set) The socket is already bound.
115
+ * - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.)
116
+ */
117
+ /**
118
+ * Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
119
+ *
120
+ * If the provided value is 0, an `invalid-argument` error is returned.
121
+ *
122
+ * # Typical errors
123
+ * - `invalid-argument`: (set) The TTL value must be 1 or higher.
124
+ */
125
+ /**
126
+ * The kernel buffer space reserved for sends/receives on this socket.
127
+ *
128
+ * If the provided value is 0, an `invalid-argument` error is returned.
129
+ * Any other value will never cause an error, but it might be silently clamped and/or rounded.
130
+ * I.e. after setting a value, reading the same setting back may return a different value.
131
+ *
132
+ * Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
133
+ *
134
+ * # Typical errors
135
+ * - `invalid-argument`: (set) The provided value was 0.
136
+ */
137
+ /**
138
+ * Create a `pollable` which will resolve once the socket is ready for I/O.
139
+ *
140
+ * Note: this function is here for WASI Preview2 only.
141
+ * It's planned to be removed when `future` is natively supported in Preview3.
142
+ */
143
+ /**
144
+ * Receive messages on the socket.
145
+ *
146
+ * This function attempts to receive up to `max-results` datagrams on the socket without blocking.
147
+ * The returned list may contain fewer elements than requested, but never more.
148
+ *
149
+ * This function returns successfully with an empty list when either:
150
+ * - `max-results` is 0, or:
151
+ * - `max-results` is greater than 0, but no results are immediately available.
152
+ * This function never returns `error(would-block)`.
153
+ *
154
+ * # Typical errors
155
+ * - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
156
+ * - `connection-refused`: The connection was refused. (ECONNREFUSED)
157
+ *
158
+ * # References
159
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>
160
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>
161
+ * - <https://man7.org/linux/man-pages/man2/recv.2.html>
162
+ * - <https://man7.org/linux/man-pages/man2/recvmmsg.2.html>
163
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv>
164
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom>
165
+ * - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
166
+ * - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
167
+ */
168
+ export { IncomingDatagramStream };
169
+ /**
170
+ * Create a `pollable` which will resolve once the stream is ready to receive again.
171
+ *
172
+ * Note: this function is here for WASI Preview2 only.
173
+ * It's planned to be removed when `future` is natively supported in Preview3.
174
+ */
175
+ /**
176
+ * Check readiness for sending. This function never blocks.
177
+ *
178
+ * Returns the number of datagrams permitted for the next call to `send`,
179
+ * or an error. Calling `send` with more datagrams than this function has
180
+ * permitted will trap.
181
+ *
182
+ * When this function returns ok(0), the `subscribe` pollable will
183
+ * become ready when this function will report at least ok(1), or an
184
+ * error.
185
+ *
186
+ * Never returns `would-block`.
187
+ */
188
+ export { OutgoingDatagramStream };
189
+ /**
190
+ * Send messages on the socket.
191
+ *
192
+ * This function attempts to send all provided `datagrams` on the socket without blocking and
193
+ * returns how many messages were actually sent (or queued for sending). This function never
194
+ * returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned.
195
+ *
196
+ * This function semantically behaves the same as iterating the `datagrams` list and sequentially
197
+ * sending each individual datagram until either the end of the list has been reached or the first error occurred.
198
+ * If at least one datagram has been sent successfully, this function never returns an error.
199
+ *
200
+ * If the input list is empty, the function returns `ok(0)`.
201
+ *
202
+ * Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if
203
+ * either `check-send` was not called or `datagrams` contains more items than `check-send` permitted.
204
+ *
205
+ * # Typical errors
206
+ * - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
207
+ * - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa)
208
+ * - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
209
+ * - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
210
+ * - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN)
211
+ * - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ)
212
+ * - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
213
+ * - `connection-refused`: The connection was refused. (ECONNREFUSED)
214
+ * - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
215
+ *
216
+ * # References
217
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
218
+ * - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
219
+ * - <https://man7.org/linux/man-pages/man2/send.2.html>
220
+ * - <https://man7.org/linux/man-pages/man2/sendmmsg.2.html>
221
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send>
222
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto>
223
+ * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
224
+ * - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
225
+ */
226
+ /**
227
+ * Create a `pollable` which will resolve once the stream is ready to send again.
228
+ *
229
+ * Note: this function is here for WASI Preview2 only.
230
+ * It's planned to be removed when `future` is natively supported in Preview3.
231
+ */
232
+ }
233
+ import type { Pollable } from '../interfaces/wasi-io-poll.js';
234
+ export { Pollable };
235
+ import type { Network } from '../interfaces/wasi-sockets-network.js';
236
+ export { Network };
237
+ import type { ErrorCode } from '../interfaces/wasi-sockets-network.js';
238
+ export { ErrorCode };
239
+ import type { IpSocketAddress } from '../interfaces/wasi-sockets-network.js';
240
+ export { IpSocketAddress };
241
+ import type { IpAddressFamily } from '../interfaces/wasi-sockets-network.js';
242
+ export { IpAddressFamily };
243
+ /**
244
+ * A received datagram.
245
+ */
246
+ export interface IncomingDatagram {
247
+ /**
248
+ * The payload.
249
+ *
250
+ * Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes.
251
+ */
252
+ data: Uint8Array,
253
+ /**
254
+ * The source address.
255
+ *
256
+ * This field is guaranteed to match the remote address the stream was initialized with, if any.
257
+ *
258
+ * Equivalent to the `src_addr` out parameter of `recvfrom`.
259
+ */
260
+ remoteAddress: IpSocketAddress,
261
+ }
262
+ /**
263
+ * A datagram to be sent out.
264
+ */
265
+ export interface OutgoingDatagram {
266
+ /**
267
+ * The payload.
268
+ */
269
+ data: Uint8Array,
270
+ /**
271
+ * The destination address.
272
+ *
273
+ * The requirements on this field depend on how the stream was initialized:
274
+ * - with a remote address: this field must be None or match the stream's remote address exactly.
275
+ * - without a remote address: this field is required.
276
+ *
277
+ * If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`.
278
+ */
279
+ remoteAddress?: IpSocketAddress,
280
+ }
281
+
282
+ export class UdpSocket {
283
+ startBind(network: Network, localAddress: IpSocketAddress): void;
284
+ finishBind(): void;
285
+ stream(remoteAddress: IpSocketAddress | undefined): [IncomingDatagramStream, OutgoingDatagramStream];
286
+ localAddress(): IpSocketAddress;
287
+ remoteAddress(): IpSocketAddress;
288
+ addressFamily(): IpAddressFamily;
289
+ ipv6Only(): boolean;
290
+ setIpv6Only(value: boolean): void;
291
+ unicastHopLimit(): number;
292
+ setUnicastHopLimit(value: number): void;
293
+ receiveBufferSize(): bigint;
294
+ setReceiveBufferSize(value: bigint): void;
295
+ sendBufferSize(): bigint;
296
+ setSendBufferSize(value: bigint): void;
297
+ subscribe(): Pollable;
298
+ }
299
+
300
+ export class IncomingDatagramStream {
301
+ receive(maxResults: bigint): IncomingDatagram[];
302
+ subscribe(): Pollable;
303
+ }
304
+
305
+ export class OutgoingDatagramStream {
306
+ checkSend(): bigint;
307
+ send(datagrams: OutgoingDatagram[]): bigint;
308
+ subscribe(): Pollable;
309
+ }
310
+
@@ -1,29 +1,29 @@
1
- import { WasiCliEnvironment } from './interfaces/wasi-cli-environment';
2
- import { WasiCliExit } from './interfaces/wasi-cli-exit';
3
- import { WasiCliStderr } from './interfaces/wasi-cli-stderr';
4
- import { WasiCliStdin } from './interfaces/wasi-cli-stdin';
5
- import { WasiCliStdout } from './interfaces/wasi-cli-stdout';
6
- import { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input';
7
- import { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output';
8
- import { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr';
9
- import { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin';
10
- import { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout';
11
- import { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock';
12
- import { WasiClocksTimezone } from './interfaces/wasi-clocks-timezone';
13
- import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock';
14
- import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens';
15
- import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types';
16
- import { WasiIoPoll } from './interfaces/wasi-io-poll';
17
- import { WasiIoStreams } from './interfaces/wasi-io-streams';
18
- import { WasiRandomInsecureSeed } from './interfaces/wasi-random-insecure-seed';
19
- import { WasiRandomInsecure } from './interfaces/wasi-random-insecure';
20
- import { WasiRandomRandom } from './interfaces/wasi-random-random';
21
- import { WasiSocketsInstanceNetwork } from './interfaces/wasi-sockets-instance-network';
22
- import { WasiSocketsIpNameLookup } from './interfaces/wasi-sockets-ip-name-lookup';
23
- import { WasiSocketsNetwork } from './interfaces/wasi-sockets-network';
24
- import { WasiSocketsTcpCreateSocket } from './interfaces/wasi-sockets-tcp-create-socket';
25
- import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp';
26
- import { WasiSocketsUdpCreateSocket } from './interfaces/wasi-sockets-udp-create-socket';
27
- import { WasiSocketsUdp } from './interfaces/wasi-sockets-udp';
28
- import { WasiCliRun } from './interfaces/wasi-cli-run';
1
+ import { WasiCliEnvironment } from './interfaces/wasi-cli-environment.js';
2
+ import { WasiCliExit } from './interfaces/wasi-cli-exit.js';
3
+ import { WasiCliStderr } from './interfaces/wasi-cli-stderr.js';
4
+ import { WasiCliStdin } from './interfaces/wasi-cli-stdin.js';
5
+ import { WasiCliStdout } from './interfaces/wasi-cli-stdout.js';
6
+ import { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input.js';
7
+ import { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output.js';
8
+ import { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr.js';
9
+ import { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin.js';
10
+ import { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout.js';
11
+ import { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock.js';
12
+ import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.js';
13
+ import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens.js';
14
+ import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types.js';
15
+ import { WasiIoError } from './interfaces/wasi-io-error.js';
16
+ import { WasiIoPoll } from './interfaces/wasi-io-poll.js';
17
+ import { WasiIoStreams } from './interfaces/wasi-io-streams.js';
18
+ import { WasiRandomInsecureSeed } from './interfaces/wasi-random-insecure-seed.js';
19
+ import { WasiRandomInsecure } from './interfaces/wasi-random-insecure.js';
20
+ import { WasiRandomRandom } from './interfaces/wasi-random-random.js';
21
+ import { WasiSocketsInstanceNetwork } from './interfaces/wasi-sockets-instance-network.js';
22
+ import { WasiSocketsIpNameLookup } from './interfaces/wasi-sockets-ip-name-lookup.js';
23
+ import { WasiSocketsNetwork } from './interfaces/wasi-sockets-network.js';
24
+ import { WasiSocketsTcpCreateSocket } from './interfaces/wasi-sockets-tcp-create-socket.js';
25
+ import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp.js';
26
+ import { WasiSocketsUdpCreateSocket } from './interfaces/wasi-sockets-udp-create-socket.js';
27
+ import { WasiSocketsUdp } from './interfaces/wasi-sockets-udp.js';
28
+ import { WasiCliRun } from './interfaces/wasi-cli-run.js';
29
29
  export const run: typeof WasiCliRun;
@@ -1,13 +1,13 @@
1
- import { WasiCliStderr } from './interfaces/wasi-cli-stderr';
2
- import { WasiCliStdin } from './interfaces/wasi-cli-stdin';
3
- import { WasiCliStdout } from './interfaces/wasi-cli-stdout';
4
- import { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock';
5
- import { WasiClocksTimezone } from './interfaces/wasi-clocks-timezone';
6
- import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock';
7
- import { WasiHttpOutgoingHandler } from './interfaces/wasi-http-outgoing-handler';
8
- import { WasiHttpTypes } from './interfaces/wasi-http-types';
9
- import { WasiIoPoll } from './interfaces/wasi-io-poll';
10
- import { WasiIoStreams } from './interfaces/wasi-io-streams';
11
- import { WasiRandomRandom } from './interfaces/wasi-random-random';
12
- import { WasiHttpIncomingHandler } from './interfaces/wasi-http-incoming-handler';
1
+ import { WasiCliStderr } from './interfaces/wasi-cli-stderr.js';
2
+ import { WasiCliStdin } from './interfaces/wasi-cli-stdin.js';
3
+ import { WasiCliStdout } from './interfaces/wasi-cli-stdout.js';
4
+ import { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock.js';
5
+ import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.js';
6
+ import { WasiHttpOutgoingHandler } from './interfaces/wasi-http-outgoing-handler.js';
7
+ import { WasiHttpTypes } from './interfaces/wasi-http-types.js';
8
+ import { WasiIoError } from './interfaces/wasi-io-error.js';
9
+ import { WasiIoPoll } from './interfaces/wasi-io-poll.js';
10
+ import { WasiIoStreams } from './interfaces/wasi-io-streams.js';
11
+ import { WasiRandomRandom } from './interfaces/wasi-random-random.js';
12
+ import { WasiHttpIncomingHandler } from './interfaces/wasi-http-incoming-handler.js';
13
13
  export const incomingHandler: typeof WasiHttpIncomingHandler;