@bytecodealliance/preview3-shim 0.1.2 → 0.2.0
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.
- package/dist/nodejs/cli.d.ts +51 -0
- package/dist/nodejs/cli.js +106 -0
- package/dist/nodejs/clocks.d.ts +55 -0
- package/dist/nodejs/clocks.js +83 -0
- package/dist/nodejs/filesystem/descriptor.d.ts +443 -0
- package/dist/nodejs/filesystem/descriptor.js +1010 -0
- package/dist/nodejs/filesystem/error.d.ts +61 -0
- package/dist/nodejs/filesystem/error.js +86 -0
- package/dist/nodejs/filesystem/utils.d.ts +8 -0
- package/dist/nodejs/filesystem/utils.js +25 -0
- package/dist/nodejs/filesystem.js +2 -0
- package/dist/nodejs/finalization.d.ts +2 -0
- package/{lib → dist}/nodejs/finalization.js +15 -21
- package/dist/nodejs/future.d.ts +98 -0
- package/dist/nodejs/future.js +176 -0
- package/dist/nodejs/http/client.d.ts +22 -0
- package/dist/nodejs/http/client.js +138 -0
- package/dist/nodejs/http/error.d.ts +18 -0
- package/dist/nodejs/http/error.js +62 -0
- package/dist/nodejs/http/fields.d.ts +144 -0
- package/dist/nodejs/http/fields.js +327 -0
- package/dist/nodejs/http/request.d.ts +256 -0
- package/dist/nodejs/http/request.js +606 -0
- package/dist/nodejs/http/response.d.ts +82 -0
- package/dist/nodejs/http/response.js +202 -0
- package/dist/nodejs/http/server.d.ts +13 -0
- package/dist/nodejs/http/server.js +127 -0
- package/dist/nodejs/http.d.ts +19 -0
- package/{lib → dist}/nodejs/http.js +13 -18
- package/dist/nodejs/index.js +8 -0
- package/dist/nodejs/random.d.ts +5 -0
- package/{lib → dist}/nodejs/random.js +2 -8
- package/dist/nodejs/sockets/address.d.ts +78 -0
- package/dist/nodejs/sockets/address.js +120 -0
- package/dist/nodejs/sockets/error.d.ts +83 -0
- package/dist/nodejs/sockets/error.js +120 -0
- package/dist/nodejs/sockets/ip-name-lookup.d.ts +18 -0
- package/dist/nodejs/sockets/ip-name-lookup.js +84 -0
- package/dist/nodejs/sockets/tcp.d.ts +333 -0
- package/dist/nodejs/sockets/tcp.js +723 -0
- package/dist/nodejs/sockets/udp.d.ts +224 -0
- package/dist/nodejs/sockets/udp.js +475 -0
- package/dist/nodejs/sockets.d.ts +11 -0
- package/{lib → dist}/nodejs/sockets.js +2 -5
- package/dist/nodejs/stream.d.ts +161 -0
- package/dist/nodejs/stream.js +388 -0
- package/dist/nodejs/workers/cli-worker.d.ts +1 -0
- package/dist/nodejs/workers/cli-worker.js +41 -0
- package/dist/nodejs/workers/filesystem-worker.d.ts +1 -0
- package/dist/nodejs/workers/filesystem-worker.js +102 -0
- package/dist/nodejs/workers/http-worker.d.ts +1 -0
- package/dist/nodejs/workers/http-worker.js +355 -0
- package/dist/nodejs/workers/resource-worker.d.ts +13 -0
- package/dist/nodejs/workers/resource-worker.js +152 -0
- package/dist/nodejs/workers/tcp-worker.d.ts +2 -0
- package/dist/nodejs/workers/tcp-worker.js +318 -0
- package/dist/nodejs/workers/udp-worker.d.ts +1 -0
- package/dist/nodejs/workers/udp-worker.js +156 -0
- package/package.json +20 -12
- package/types/interfaces/wasi-cli-environment.d.ts +3 -3
- package/types/interfaces/wasi-cli-exit.d.ts +12 -1
- package/types/interfaces/wasi-cli-run.d.ts +1 -1
- package/types/interfaces/wasi-cli-stderr.d.ts +3 -3
- package/types/interfaces/wasi-cli-stdin.d.ts +5 -5
- package/types/interfaces/wasi-cli-stdout.d.ts +3 -3
- package/types/interfaces/wasi-cli-terminal-input.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-output.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
- package/types/interfaces/wasi-cli-types.d.ts +5 -5
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +3 -3
- package/types/interfaces/wasi-clocks-system-clock.d.ts +6 -6
- package/types/interfaces/wasi-clocks-types.d.ts +1 -1
- package/types/interfaces/wasi-filesystem-preopens.d.ts +1 -1
- package/types/interfaces/wasi-filesystem-types.d.ts +74 -74
- package/types/interfaces/wasi-http-client.d.ts +1 -1
- package/types/interfaces/wasi-http-handler.d.ts +1 -1
- package/types/interfaces/wasi-http-types.d.ts +34 -34
- package/types/interfaces/wasi-random-insecure-seed.d.ts +5 -5
- package/types/interfaces/wasi-random-insecure.d.ts +5 -5
- package/types/interfaces/wasi-random-random.d.ts +5 -5
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +11 -11
- package/types/interfaces/wasi-sockets-types.d.ts +121 -121
- package/types/wasi-cli-command.d.ts +23 -23
- package/types/wasi-http-service.d.ts +14 -14
- package/lib/nodejs/cli.js +0 -127
- package/lib/nodejs/clocks.js +0 -98
- package/lib/nodejs/filesystem/descriptor.js +0 -1093
- package/lib/nodejs/filesystem/error.js +0 -92
- package/lib/nodejs/filesystem/utils.js +0 -19
- package/lib/nodejs/future.js +0 -190
- package/lib/nodejs/http/client.js +0 -161
- package/lib/nodejs/http/error.js +0 -71
- package/lib/nodejs/http/fields.js +0 -373
- package/lib/nodejs/http/request.js +0 -691
- package/lib/nodejs/http/response.js +0 -227
- package/lib/nodejs/http/server.js +0 -157
- package/lib/nodejs/sockets/address.js +0 -146
- package/lib/nodejs/sockets/error.js +0 -123
- package/lib/nodejs/sockets/ip-name-lookup.js +0 -93
- package/lib/nodejs/sockets/tcp.js +0 -801
- package/lib/nodejs/sockets/udp.js +0 -516
- package/lib/nodejs/stream.js +0 -437
- package/lib/nodejs/workers/cli-worker.js +0 -49
- package/lib/nodejs/workers/filesystem-worker.js +0 -119
- package/lib/nodejs/workers/http-worker.js +0 -417
- package/lib/nodejs/workers/resource-worker.js +0 -195
- package/lib/nodejs/workers/tcp-worker.js +0 -370
- package/lib/nodejs/workers/udp-worker.js +0 -194
- /package/{lib/nodejs/filesystem.js → dist/nodejs/filesystem.d.ts} +0 -0
- /package/{lib/nodejs/index.js → dist/nodejs/index.d.ts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** @module Interface wasi:sockets/types@0.3.0
|
|
1
|
+
/** @module Interface wasi:sockets/types@0.3.0 **/
|
|
2
2
|
export type Duration = import('./wasi-clocks-types.js').Duration;
|
|
3
3
|
/**
|
|
4
4
|
* Error codes.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* In theory, every API can return any error code.
|
|
7
7
|
* In practice, API's typically only return the errors documented per API
|
|
8
8
|
* combined with a couple of errors that are always possible:
|
|
@@ -10,13 +10,13 @@ export type Duration = import('./wasi-clocks-types.js').Duration;
|
|
|
10
10
|
* - `access-denied`
|
|
11
11
|
* - `not-supported`
|
|
12
12
|
* - `out-of-memory`
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* See each individual API for what the POSIX equivalents are. They sometimes differ per API.
|
|
15
15
|
*/
|
|
16
16
|
export type ErrorCode = ErrorCodeAccessDenied | ErrorCodeNotSupported | ErrorCodeInvalidArgument | ErrorCodeOutOfMemory | ErrorCodeTimeout | ErrorCodeInvalidState | ErrorCodeAddressNotBindable | ErrorCodeAddressInUse | ErrorCodeRemoteUnreachable | ErrorCodeConnectionRefused | ErrorCodeConnectionBroken | ErrorCodeConnectionReset | ErrorCodeConnectionAborted | ErrorCodeDatagramTooLarge | ErrorCodeOther;
|
|
17
17
|
/**
|
|
18
18
|
* Access denied.
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* POSIX equivalent: EACCES, EPERM
|
|
21
21
|
*/
|
|
22
22
|
export interface ErrorCodeAccessDenied {
|
|
@@ -24,7 +24,7 @@ export interface ErrorCodeAccessDenied {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* The operation is not supported.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
28
|
* POSIX equivalent: EOPNOTSUPP, ENOPROTOOPT, EPFNOSUPPORT, EPROTONOSUPPORT, ESOCKTNOSUPPORT
|
|
29
29
|
*/
|
|
30
30
|
export interface ErrorCodeNotSupported {
|
|
@@ -32,7 +32,7 @@ export interface ErrorCodeNotSupported {
|
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* One of the arguments is invalid.
|
|
35
|
-
*
|
|
35
|
+
*
|
|
36
36
|
* POSIX equivalent: EINVAL, EDESTADDRREQ, EAFNOSUPPORT
|
|
37
37
|
*/
|
|
38
38
|
export interface ErrorCodeInvalidArgument {
|
|
@@ -40,7 +40,7 @@ export interface ErrorCodeInvalidArgument {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Not enough memory to complete the operation.
|
|
43
|
-
*
|
|
43
|
+
*
|
|
44
44
|
* POSIX equivalent: ENOMEM, ENOBUFS
|
|
45
45
|
*/
|
|
46
46
|
export interface ErrorCodeOutOfMemory {
|
|
@@ -48,7 +48,7 @@ export interface ErrorCodeOutOfMemory {
|
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* The operation timed out before it could finish completely.
|
|
51
|
-
*
|
|
51
|
+
*
|
|
52
52
|
* POSIX equivalent: ETIMEDOUT
|
|
53
53
|
*/
|
|
54
54
|
export interface ErrorCodeTimeout {
|
|
@@ -62,7 +62,7 @@ export interface ErrorCodeInvalidState {
|
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* The local address is not available.
|
|
65
|
-
*
|
|
65
|
+
*
|
|
66
66
|
* POSIX equivalent: EADDRNOTAVAIL
|
|
67
67
|
*/
|
|
68
68
|
export interface ErrorCodeAddressNotBindable {
|
|
@@ -71,7 +71,7 @@ export interface ErrorCodeAddressNotBindable {
|
|
|
71
71
|
/**
|
|
72
72
|
* A bind operation failed because the provided address is already in
|
|
73
73
|
* use or because there are no ephemeral ports available.
|
|
74
|
-
*
|
|
74
|
+
*
|
|
75
75
|
* POSIX equivalent: EADDRINUSE
|
|
76
76
|
*/
|
|
77
77
|
export interface ErrorCodeAddressInUse {
|
|
@@ -79,7 +79,7 @@ export interface ErrorCodeAddressInUse {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* The remote address is not reachable.
|
|
82
|
-
*
|
|
82
|
+
*
|
|
83
83
|
* POSIX equivalent: EHOSTUNREACH, EHOSTDOWN, ENETDOWN, ENETUNREACH, ENONET
|
|
84
84
|
*/
|
|
85
85
|
export interface ErrorCodeRemoteUnreachable {
|
|
@@ -87,7 +87,7 @@ export interface ErrorCodeRemoteUnreachable {
|
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* The connection was forcefully rejected.
|
|
90
|
-
*
|
|
90
|
+
*
|
|
91
91
|
* POSIX equivalent: ECONNREFUSED
|
|
92
92
|
*/
|
|
93
93
|
export interface ErrorCodeConnectionRefused {
|
|
@@ -95,7 +95,7 @@ export interface ErrorCodeConnectionRefused {
|
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* A write failed because the connection was broken.
|
|
98
|
-
*
|
|
98
|
+
*
|
|
99
99
|
* POSIX equivalent: EPIPE
|
|
100
100
|
*/
|
|
101
101
|
export interface ErrorCodeConnectionBroken {
|
|
@@ -103,7 +103,7 @@ export interface ErrorCodeConnectionBroken {
|
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* The connection was reset.
|
|
106
|
-
*
|
|
106
|
+
*
|
|
107
107
|
* POSIX equivalent: ECONNRESET
|
|
108
108
|
*/
|
|
109
109
|
export interface ErrorCodeConnectionReset {
|
|
@@ -111,7 +111,7 @@ export interface ErrorCodeConnectionReset {
|
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* The connection was aborted.
|
|
114
|
-
*
|
|
114
|
+
*
|
|
115
115
|
* POSIX equivalent: ECONNABORTED
|
|
116
116
|
*/
|
|
117
117
|
export interface ErrorCodeConnectionAborted {
|
|
@@ -120,7 +120,7 @@ export interface ErrorCodeConnectionAborted {
|
|
|
120
120
|
/**
|
|
121
121
|
* The size of a datagram sent to a UDP socket exceeded the maximum
|
|
122
122
|
* supported size.
|
|
123
|
-
*
|
|
123
|
+
*
|
|
124
124
|
* POSIX equivalent: EMSGSIZE
|
|
125
125
|
*/
|
|
126
126
|
export interface ErrorCodeDatagramTooLarge {
|
|
@@ -137,12 +137,12 @@ export interface ErrorCodeOther {
|
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* # Variants
|
|
140
|
-
*
|
|
140
|
+
*
|
|
141
141
|
* ## `"ipv4"`
|
|
142
|
-
*
|
|
142
|
+
*
|
|
143
143
|
* Similar to `AF_INET` in POSIX.
|
|
144
144
|
* ## `"ipv6"`
|
|
145
|
-
*
|
|
145
|
+
*
|
|
146
146
|
* Similar to `AF_INET6` in POSIX.
|
|
147
147
|
*/
|
|
148
148
|
export type IpAddressFamily = 'ipv4' | 'ipv6';
|
|
@@ -203,18 +203,18 @@ export class TcpSocket {
|
|
|
203
203
|
private constructor();
|
|
204
204
|
/**
|
|
205
205
|
* Create a new TCP socket.
|
|
206
|
-
*
|
|
206
|
+
*
|
|
207
207
|
* Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)`
|
|
208
208
|
* in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and
|
|
209
209
|
* can't be configured otherwise.
|
|
210
|
-
*
|
|
210
|
+
*
|
|
211
211
|
* Unlike POSIX, WASI sockets have no notion of a socket-level
|
|
212
212
|
* `O_NONBLOCK` flag. Instead they fully rely on the Component Model's
|
|
213
213
|
* async support.
|
|
214
|
-
*
|
|
214
|
+
*
|
|
215
215
|
* # Typical errors
|
|
216
216
|
* - `not-supported`: The `address-family` is not supported. (EAFNOSUPPORT)
|
|
217
|
-
*
|
|
217
|
+
*
|
|
218
218
|
* # References
|
|
219
219
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
|
|
220
220
|
* - <https://man7.org/linux/man-pages/man2/socket.2.html>
|
|
@@ -224,17 +224,17 @@ export class TcpSocket {
|
|
|
224
224
|
static create(addressFamily: IpAddressFamily): TcpSocket;
|
|
225
225
|
/**
|
|
226
226
|
* Bind the socket to the provided IP address and port.
|
|
227
|
-
*
|
|
227
|
+
*
|
|
228
228
|
* If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is
|
|
229
229
|
* left to the implementation to decide which network interface(s) to
|
|
230
230
|
* bind to. If the TCP/UDP port is zero, the socket will be bound to a
|
|
231
231
|
* random free port.
|
|
232
|
-
*
|
|
232
|
+
*
|
|
233
233
|
* Bind can be attempted multiple times on the same socket, even with
|
|
234
234
|
* different arguments on each iteration. But never concurrently and
|
|
235
235
|
* only as long as the previous bind failed. Once a bind succeeds, the
|
|
236
236
|
* binding can't be changed anymore.
|
|
237
|
-
*
|
|
237
|
+
*
|
|
238
238
|
* # Typical errors
|
|
239
239
|
* - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
|
|
240
240
|
* - `invalid-argument`: `local-address` is not a unicast address. (EINVAL)
|
|
@@ -243,14 +243,14 @@ export class TcpSocket {
|
|
|
243
243
|
* - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
|
|
244
244
|
* - `address-in-use`: Address is already in use. (EADDRINUSE)
|
|
245
245
|
* - `address-not-bindable`: `local-address` is not an address that can be bound to. (EADDRNOTAVAIL)
|
|
246
|
-
*
|
|
246
|
+
*
|
|
247
247
|
* # Implementors note
|
|
248
248
|
* The bind operation shouldn't be affected by the TIME_WAIT state of a
|
|
249
249
|
* recently closed socket on the same local address. In practice this
|
|
250
250
|
* means that the SO_REUSEADDR socket option should be set implicitly
|
|
251
251
|
* on all platforms, except on Windows where this is the default
|
|
252
252
|
* behavior and SO_REUSEADDR performs something different.
|
|
253
|
-
*
|
|
253
|
+
*
|
|
254
254
|
* # References
|
|
255
255
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
|
|
256
256
|
* - <https://man7.org/linux/man-pages/man2/bind.2.html>
|
|
@@ -260,18 +260,18 @@ export class TcpSocket {
|
|
|
260
260
|
bind(localAddress: IpSocketAddress): void;
|
|
261
261
|
/**
|
|
262
262
|
* Connect to a remote endpoint.
|
|
263
|
-
*
|
|
263
|
+
*
|
|
264
264
|
* On success, the socket is transitioned into the `connected` state
|
|
265
265
|
* and the `remote-address` of the socket is updated.
|
|
266
266
|
* The `local-address` may be updated as well, based on the best network
|
|
267
267
|
* path to `remote-address`. If the socket was not already explicitly
|
|
268
268
|
* bound, this function will implicitly bind the socket to a random
|
|
269
269
|
* free port.
|
|
270
|
-
*
|
|
270
|
+
*
|
|
271
271
|
* After a failed connection attempt, the socket will be in the `closed`
|
|
272
272
|
* state and the only valid action left is to `drop` the socket. A single
|
|
273
273
|
* socket can not be used to connect more than once.
|
|
274
|
-
*
|
|
274
|
+
*
|
|
275
275
|
* # Typical errors
|
|
276
276
|
* - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
277
277
|
* - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)
|
|
@@ -287,7 +287,7 @@ export class TcpSocket {
|
|
|
287
287
|
* - `connection-aborted`: The connection was aborted. (ECONNABORTED)
|
|
288
288
|
* - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
289
289
|
* - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
|
|
290
|
-
*
|
|
290
|
+
*
|
|
291
291
|
* # References
|
|
292
292
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
|
|
293
293
|
* - <https://man7.org/linux/man-pages/man2/connect.2.html>
|
|
@@ -297,20 +297,20 @@ export class TcpSocket {
|
|
|
297
297
|
connect(remoteAddress: IpSocketAddress): Promise<void>;
|
|
298
298
|
/**
|
|
299
299
|
* Start listening and return a stream of new inbound connections.
|
|
300
|
-
*
|
|
300
|
+
*
|
|
301
301
|
* Transitions the socket into the `listening` state. This can be called
|
|
302
302
|
* at most once per socket.
|
|
303
|
-
*
|
|
303
|
+
*
|
|
304
304
|
* If the socket is not already explicitly bound, this function will
|
|
305
305
|
* implicitly bind the socket to a random free port.
|
|
306
|
-
*
|
|
306
|
+
*
|
|
307
307
|
* Normally, the returned sockets are bound, in the `connected` state
|
|
308
308
|
* and immediately ready for I/O. Though, depending on exact timing and
|
|
309
309
|
* circumstances, a newly accepted connection may already be `closed`
|
|
310
310
|
* by the time the server attempts to perform its first I/O on it. This
|
|
311
311
|
* is true regardless of whether the WASI implementation uses
|
|
312
312
|
* "synthesized" sockets or not (see Implementors Notes below).
|
|
313
|
-
*
|
|
313
|
+
*
|
|
314
314
|
* The following properties are inherited from the listener socket:
|
|
315
315
|
* - `address-family`
|
|
316
316
|
* - `keep-alive-enabled`
|
|
@@ -320,18 +320,18 @@ export class TcpSocket {
|
|
|
320
320
|
* - `hop-limit`
|
|
321
321
|
* - `receive-buffer-size`
|
|
322
322
|
* - `send-buffer-size`
|
|
323
|
-
*
|
|
323
|
+
*
|
|
324
324
|
* # Typical errors
|
|
325
325
|
* - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD)
|
|
326
326
|
* - `invalid-state`: The socket is already in the `listening` state.
|
|
327
327
|
* - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
|
|
328
|
-
*
|
|
328
|
+
*
|
|
329
329
|
* # Implementors note
|
|
330
330
|
* This method returns a single perpetual stream that should only close
|
|
331
331
|
* on fatal errors (if any). Yet, the POSIX' `accept` function may also
|
|
332
332
|
* return transient errors (e.g. ECONNABORTED). The exact details differ
|
|
333
333
|
* per operation system. For example, the Linux manual mentions:
|
|
334
|
-
*
|
|
334
|
+
*
|
|
335
335
|
* > Linux accept() passes already-pending network errors on the new
|
|
336
336
|
* > socket as an error code from accept(). This behavior differs from
|
|
337
337
|
* > other BSD socket implementations. For reliable operation the
|
|
@@ -340,23 +340,23 @@ export class TcpSocket {
|
|
|
340
340
|
* > In the case of TCP/IP, these are ENETDOWN, EPROTO, ENOPROTOOPT,
|
|
341
341
|
* > EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH.
|
|
342
342
|
* Source: https://man7.org/linux/man-pages/man2/accept.2.html
|
|
343
|
-
*
|
|
343
|
+
*
|
|
344
344
|
* WASI implementations have two options to handle this:
|
|
345
345
|
* - Optionally log it and then skip over non-fatal errors returned by
|
|
346
346
|
* `accept`. Guest code never gets to see these failures. Or:
|
|
347
347
|
* - Synthesize a `tcp-socket` resource that exposes the error when
|
|
348
348
|
* attempting to send or receive on it. Guest code then sees these
|
|
349
349
|
* failures as regular I/O errors.
|
|
350
|
-
*
|
|
350
|
+
*
|
|
351
351
|
* In either case, the stream returned by this `listen` method remains
|
|
352
352
|
* operational.
|
|
353
|
-
*
|
|
353
|
+
*
|
|
354
354
|
* WASI requires `listen` to perform an implicit bind if the socket
|
|
355
355
|
* has not already been bound. Not all platforms (notably Windows)
|
|
356
356
|
* exhibit this behavior out of the box. On platforms that require it,
|
|
357
357
|
* the WASI implementation can emulate this behavior by performing
|
|
358
358
|
* the bind itself if the guest hasn't already done so.
|
|
359
|
-
*
|
|
359
|
+
*
|
|
360
360
|
* # References
|
|
361
361
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html>
|
|
362
362
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html>
|
|
@@ -370,22 +370,22 @@ export class TcpSocket {
|
|
|
370
370
|
listen(): ReadableStream<TcpSocket>;
|
|
371
371
|
/**
|
|
372
372
|
* Transmit data to peer.
|
|
373
|
-
*
|
|
373
|
+
*
|
|
374
374
|
* The caller should close the stream when it has no more data to send
|
|
375
375
|
* to the peer. Under normal circumstances this will cause a FIN packet
|
|
376
376
|
* to be sent out. Closing the stream is equivalent to calling
|
|
377
377
|
* `shutdown(SHUT_WR)` in POSIX.
|
|
378
|
-
*
|
|
378
|
+
*
|
|
379
379
|
* This function may be called at most once and returns once the full
|
|
380
380
|
* contents of the stream are transmitted or an error is encountered.
|
|
381
|
-
*
|
|
381
|
+
*
|
|
382
382
|
* # Typical errors
|
|
383
383
|
* - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN)
|
|
384
384
|
* - `invalid-state`: `send` has already been called on this socket.
|
|
385
385
|
* - `connection-broken`: The connection is not writable anymore. (EPIPE, ECONNABORTED on Windows)
|
|
386
386
|
* - `connection-reset`: The connection was reset. (ECONNRESET)
|
|
387
387
|
* - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
388
|
-
*
|
|
388
|
+
*
|
|
389
389
|
* # References
|
|
390
390
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html>
|
|
391
391
|
* - <https://man7.org/linux/man-pages/man2/send.2.html>
|
|
@@ -395,27 +395,27 @@ export class TcpSocket {
|
|
|
395
395
|
send(data: ReadableStream<number>): Promise<Result<void, ErrorCode>>;
|
|
396
396
|
/**
|
|
397
397
|
* Read data from peer.
|
|
398
|
-
*
|
|
398
|
+
*
|
|
399
399
|
* Returns a `stream` of data sent by the peer. The implementation
|
|
400
400
|
* drops the stream once no more data is available. At that point, the
|
|
401
401
|
* returned `future` resolves to:
|
|
402
402
|
* - `ok` after a graceful shutdown from the peer (i.e. a FIN packet), or
|
|
403
403
|
* - `err` if the socket was closed abnormally.
|
|
404
|
-
*
|
|
404
|
+
*
|
|
405
405
|
* `receive` may be called only once per socket. Subsequent calls return
|
|
406
406
|
* a closed stream and a future resolved to `err(invalid-state)`.
|
|
407
|
-
*
|
|
407
|
+
*
|
|
408
408
|
* If the caller is not expecting to receive any more data from the peer,
|
|
409
409
|
* they should drop the stream. Any data still in the receive queue
|
|
410
410
|
* will be discarded. This is equivalent to calling `shutdown(SHUT_RD)`
|
|
411
411
|
* in POSIX.
|
|
412
|
-
*
|
|
412
|
+
*
|
|
413
413
|
* # Typical errors
|
|
414
414
|
* - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN)
|
|
415
415
|
* - `invalid-state`: `receive` has already been called on this socket.
|
|
416
416
|
* - `connection-reset`: The connection was reset. (ECONNRESET)
|
|
417
417
|
* - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
418
|
-
*
|
|
418
|
+
*
|
|
419
419
|
* # References
|
|
420
420
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html>
|
|
421
421
|
* - <https://man7.org/linux/man-pages/man2/recv.2.html>
|
|
@@ -425,17 +425,17 @@ export class TcpSocket {
|
|
|
425
425
|
receive(): [ReadableStream<number>, Promise<Result<void, ErrorCode>>];
|
|
426
426
|
/**
|
|
427
427
|
* Get the bound local address.
|
|
428
|
-
*
|
|
428
|
+
*
|
|
429
429
|
* POSIX mentions:
|
|
430
430
|
* > If the socket has not been bound to a local name, the value
|
|
431
431
|
* > stored in the object pointed to by `address` is unspecified.
|
|
432
|
-
*
|
|
432
|
+
*
|
|
433
433
|
* WASI is stricter and requires `get-local-address` to return
|
|
434
434
|
* `invalid-state` when the socket hasn't been bound yet.
|
|
435
|
-
*
|
|
435
|
+
*
|
|
436
436
|
* # Typical errors
|
|
437
437
|
* - `invalid-state`: The socket is not bound to any local address.
|
|
438
|
-
*
|
|
438
|
+
*
|
|
439
439
|
* # References
|
|
440
440
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
|
|
441
441
|
* - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
|
|
@@ -445,10 +445,10 @@ export class TcpSocket {
|
|
|
445
445
|
getLocalAddress(): IpSocketAddress;
|
|
446
446
|
/**
|
|
447
447
|
* Get the remote address.
|
|
448
|
-
*
|
|
448
|
+
*
|
|
449
449
|
* # Typical errors
|
|
450
450
|
* - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN)
|
|
451
|
-
*
|
|
451
|
+
*
|
|
452
452
|
* # References
|
|
453
453
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
|
|
454
454
|
* - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
|
|
@@ -458,26 +458,26 @@ export class TcpSocket {
|
|
|
458
458
|
getRemoteAddress(): IpSocketAddress;
|
|
459
459
|
/**
|
|
460
460
|
* Whether the socket is in the `listening` state.
|
|
461
|
-
*
|
|
461
|
+
*
|
|
462
462
|
* Equivalent to the SO_ACCEPTCONN socket option.
|
|
463
463
|
*/
|
|
464
464
|
getIsListening(): boolean;
|
|
465
465
|
/**
|
|
466
466
|
* Whether this is a IPv4 or IPv6 socket.
|
|
467
|
-
*
|
|
467
|
+
*
|
|
468
468
|
* This is the value passed to the constructor.
|
|
469
|
-
*
|
|
469
|
+
*
|
|
470
470
|
* Equivalent to the SO_DOMAIN socket option.
|
|
471
471
|
*/
|
|
472
472
|
getAddressFamily(): IpAddressFamily;
|
|
473
473
|
/**
|
|
474
474
|
* Hints the desired listen queue size. Implementations are free to
|
|
475
475
|
* ignore this.
|
|
476
|
-
*
|
|
476
|
+
*
|
|
477
477
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
478
478
|
* Any other value will never cause an error, but it might be silently
|
|
479
479
|
* clamped and/or rounded.
|
|
480
|
-
*
|
|
480
|
+
*
|
|
481
481
|
* # Typical errors
|
|
482
482
|
* - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen.
|
|
483
483
|
* - `invalid-argument`: (set) The provided value was 0.
|
|
@@ -486,14 +486,14 @@ export class TcpSocket {
|
|
|
486
486
|
setListenBacklogSize(value: bigint): void;
|
|
487
487
|
/**
|
|
488
488
|
* Enables or disables keepalive.
|
|
489
|
-
*
|
|
489
|
+
*
|
|
490
490
|
* The keepalive behavior can be adjusted using:
|
|
491
491
|
* - `keep-alive-idle-time`
|
|
492
492
|
* - `keep-alive-interval`
|
|
493
493
|
* - `keep-alive-count`
|
|
494
494
|
* These properties can be configured while `keep-alive-enabled` is
|
|
495
495
|
* false, but only come into effect when `keep-alive-enabled` is true.
|
|
496
|
-
*
|
|
496
|
+
*
|
|
497
497
|
* Equivalent to the SO_KEEPALIVE socket option.
|
|
498
498
|
*/
|
|
499
499
|
getKeepAliveEnabled(): boolean;
|
|
@@ -501,14 +501,14 @@ export class TcpSocket {
|
|
|
501
501
|
/**
|
|
502
502
|
* Amount of time the connection has to be idle before TCP starts
|
|
503
503
|
* sending keepalive packets.
|
|
504
|
-
*
|
|
504
|
+
*
|
|
505
505
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
506
506
|
* All other values are accepted without error, but may be
|
|
507
507
|
* clamped or rounded. As a result, the value read back from
|
|
508
508
|
* this setting may differ from the value that was set.
|
|
509
|
-
*
|
|
509
|
+
*
|
|
510
510
|
* Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)
|
|
511
|
-
*
|
|
511
|
+
*
|
|
512
512
|
* # Typical errors
|
|
513
513
|
* - `invalid-argument`: (set) The provided value was 0.
|
|
514
514
|
*/
|
|
@@ -516,14 +516,14 @@ export class TcpSocket {
|
|
|
516
516
|
setKeepAliveIdleTime(value: Duration): void;
|
|
517
517
|
/**
|
|
518
518
|
* The time between keepalive packets.
|
|
519
|
-
*
|
|
519
|
+
*
|
|
520
520
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
521
521
|
* All other values are accepted without error, but may be
|
|
522
522
|
* clamped or rounded. As a result, the value read back from
|
|
523
523
|
* this setting may differ from the value that was set.
|
|
524
|
-
*
|
|
524
|
+
*
|
|
525
525
|
* Equivalent to the TCP_KEEPINTVL socket option.
|
|
526
|
-
*
|
|
526
|
+
*
|
|
527
527
|
* # Typical errors
|
|
528
528
|
* - `invalid-argument`: (set) The provided value was 0.
|
|
529
529
|
*/
|
|
@@ -532,14 +532,14 @@ export class TcpSocket {
|
|
|
532
532
|
/**
|
|
533
533
|
* The maximum amount of keepalive packets TCP should send before
|
|
534
534
|
* aborting the connection.
|
|
535
|
-
*
|
|
535
|
+
*
|
|
536
536
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
537
537
|
* All other values are accepted without error, but may be
|
|
538
538
|
* clamped or rounded. As a result, the value read back from
|
|
539
539
|
* this setting may differ from the value that was set.
|
|
540
|
-
*
|
|
540
|
+
*
|
|
541
541
|
* Equivalent to the TCP_KEEPCNT socket option.
|
|
542
|
-
*
|
|
542
|
+
*
|
|
543
543
|
* # Typical errors
|
|
544
544
|
* - `invalid-argument`: (set) The provided value was 0.
|
|
545
545
|
*/
|
|
@@ -547,9 +547,9 @@ export class TcpSocket {
|
|
|
547
547
|
setKeepAliveCount(value: number): void;
|
|
548
548
|
/**
|
|
549
549
|
* Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
|
|
550
|
-
*
|
|
550
|
+
*
|
|
551
551
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
552
|
-
*
|
|
552
|
+
*
|
|
553
553
|
* # Typical errors
|
|
554
554
|
* - `invalid-argument`: (set) The TTL value must be 1 or higher.
|
|
555
555
|
*/
|
|
@@ -559,12 +559,12 @@ export class TcpSocket {
|
|
|
559
559
|
* Kernel buffer space reserved for sending/receiving on this socket.
|
|
560
560
|
* Implementations usually treat this as a cap the buffer can grow to,
|
|
561
561
|
* rather than allocating the full amount immediately.
|
|
562
|
-
*
|
|
562
|
+
*
|
|
563
563
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
564
564
|
* All other values are accepted without error, but may be
|
|
565
565
|
* clamped or rounded. As a result, the value read back from
|
|
566
566
|
* this setting may differ from the value that was set.
|
|
567
|
-
*
|
|
567
|
+
*
|
|
568
568
|
* This is only a performance hint. The implementation may ignore it or
|
|
569
569
|
* tweak it based on real traffic patterns.
|
|
570
570
|
* Linux and macOS appear to behave differently depending on whether a
|
|
@@ -572,9 +572,9 @@ export class TcpSocket {
|
|
|
572
572
|
* not set, they dynamically adjust the buffer size as the connection
|
|
573
573
|
* progresses. This is especially noticeable when comparing the values
|
|
574
574
|
* from before and after connection establishment.
|
|
575
|
-
*
|
|
575
|
+
*
|
|
576
576
|
* Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
|
|
577
|
-
*
|
|
577
|
+
*
|
|
578
578
|
* # Typical errors
|
|
579
579
|
* - `invalid-argument`: (set) The provided value was 0.
|
|
580
580
|
*/
|
|
@@ -591,15 +591,15 @@ export class UdpSocket {
|
|
|
591
591
|
private constructor();
|
|
592
592
|
/**
|
|
593
593
|
* Create a new UDP socket.
|
|
594
|
-
*
|
|
594
|
+
*
|
|
595
595
|
* Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)`
|
|
596
596
|
* in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and
|
|
597
597
|
* can't be configured otherwise.
|
|
598
|
-
*
|
|
598
|
+
*
|
|
599
599
|
* Unlike POSIX, WASI sockets have no notion of a socket-level
|
|
600
600
|
* `O_NONBLOCK` flag. Instead they fully rely on the Component Model's
|
|
601
601
|
* async support.
|
|
602
|
-
*
|
|
602
|
+
*
|
|
603
603
|
* # References:
|
|
604
604
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
|
|
605
605
|
* - <https://man7.org/linux/man-pages/man2/socket.2.html>
|
|
@@ -609,19 +609,19 @@ export class UdpSocket {
|
|
|
609
609
|
static create(addressFamily: IpAddressFamily): UdpSocket;
|
|
610
610
|
/**
|
|
611
611
|
* Bind the socket to the provided IP address and port.
|
|
612
|
-
*
|
|
612
|
+
*
|
|
613
613
|
* If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is
|
|
614
614
|
* left to the implementation to decide which network interface(s) to
|
|
615
615
|
* bind to. If the port is zero, the socket will be bound to a random
|
|
616
616
|
* free port.
|
|
617
|
-
*
|
|
617
|
+
*
|
|
618
618
|
* # Typical errors
|
|
619
619
|
* - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
|
|
620
620
|
* - `invalid-state`: The socket is already bound. (EINVAL)
|
|
621
621
|
* - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
|
|
622
622
|
* - `address-in-use`: Address is already in use. (EADDRINUSE)
|
|
623
623
|
* - `address-not-bindable`: `local-address` is not an address that can be bound to. (EADDRNOTAVAIL)
|
|
624
|
-
*
|
|
624
|
+
*
|
|
625
625
|
* # References
|
|
626
626
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
|
|
627
627
|
* - <https://man7.org/linux/man-pages/man2/bind.2.html>
|
|
@@ -631,36 +631,36 @@ export class UdpSocket {
|
|
|
631
631
|
bind(localAddress: IpSocketAddress): void;
|
|
632
632
|
/**
|
|
633
633
|
* Associate this socket with a specific peer address.
|
|
634
|
-
*
|
|
634
|
+
*
|
|
635
635
|
* On success, the `remote-address` of the socket is updated.
|
|
636
636
|
* The `local-address` may be updated as well, based on the best network
|
|
637
637
|
* path to `remote-address`. If the socket was not already explicitly
|
|
638
638
|
* bound, this function will implicitly bind the socket to a random
|
|
639
639
|
* free port.
|
|
640
|
-
*
|
|
640
|
+
*
|
|
641
641
|
* When a UDP socket is "connected", the `send` and `receive` methods
|
|
642
642
|
* are limited to communicating with that peer only:
|
|
643
643
|
* - `send` can only be used to send to this destination.
|
|
644
644
|
* - `receive` will only return datagrams sent from the provided `remote-address`.
|
|
645
|
-
*
|
|
645
|
+
*
|
|
646
646
|
* The name "connect" was kept to align with the existing POSIX
|
|
647
647
|
* terminology. Other than that, this function only changes the local
|
|
648
648
|
* socket configuration and does not generate any network traffic.
|
|
649
649
|
* The peer is not aware of this "connection".
|
|
650
|
-
*
|
|
650
|
+
*
|
|
651
651
|
* This method may be called multiple times on the same socket to change
|
|
652
652
|
* its association, but only the most recent one will be effective.
|
|
653
|
-
*
|
|
653
|
+
*
|
|
654
654
|
* # Typical errors
|
|
655
655
|
* - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
656
656
|
* - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
657
657
|
* - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
658
658
|
* - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
|
|
659
|
-
*
|
|
659
|
+
*
|
|
660
660
|
* # Implementors note
|
|
661
661
|
* If the socket is already connected, some platforms (e.g. Linux)
|
|
662
662
|
* require a disconnect before connecting to a different peer address.
|
|
663
|
-
*
|
|
663
|
+
*
|
|
664
664
|
* # References
|
|
665
665
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
|
|
666
666
|
* - <https://man7.org/linux/man-pages/man2/connect.2.html>
|
|
@@ -670,15 +670,15 @@ export class UdpSocket {
|
|
|
670
670
|
connect(remoteAddress: IpSocketAddress): void;
|
|
671
671
|
/**
|
|
672
672
|
* Dissociate this socket from its peer address.
|
|
673
|
-
*
|
|
673
|
+
*
|
|
674
674
|
* After calling this method, `send` & `receive` are free to communicate
|
|
675
675
|
* with any remote address again.
|
|
676
|
-
*
|
|
676
|
+
*
|
|
677
677
|
* The POSIX equivalent of this is calling `connect` with an `AF_UNSPEC` address.
|
|
678
|
-
*
|
|
678
|
+
*
|
|
679
679
|
* # Typical errors
|
|
680
680
|
* - `invalid-state`: The socket is not connected.
|
|
681
|
-
*
|
|
681
|
+
*
|
|
682
682
|
* # References
|
|
683
683
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
|
|
684
684
|
* - <https://man7.org/linux/man-pages/man2/connect.2.html>
|
|
@@ -688,20 +688,20 @@ export class UdpSocket {
|
|
|
688
688
|
disconnect(): void;
|
|
689
689
|
/**
|
|
690
690
|
* Send a message on the socket to a particular peer.
|
|
691
|
-
*
|
|
691
|
+
*
|
|
692
692
|
* If the socket is connected, the peer address may be left empty. In
|
|
693
693
|
* that case this is equivalent to `send` in POSIX. Otherwise it is
|
|
694
694
|
* equivalent to `sendto`.
|
|
695
|
-
*
|
|
695
|
+
*
|
|
696
696
|
* Additionally, if the socket is connected, a `remote-address` argument
|
|
697
697
|
* _may_ be provided but then it must be identical to the address
|
|
698
698
|
* passed to `connect`.
|
|
699
|
-
*
|
|
699
|
+
*
|
|
700
700
|
* If the socket has not been explicitly bound, it will be
|
|
701
701
|
* implicitly bound to a random free port.
|
|
702
|
-
*
|
|
702
|
+
*
|
|
703
703
|
* Implementations may trap if the `data` length exceeds 64 KiB.
|
|
704
|
-
*
|
|
704
|
+
*
|
|
705
705
|
* # Typical errors
|
|
706
706
|
* - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
707
707
|
* - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
@@ -712,14 +712,14 @@ export class UdpSocket {
|
|
|
712
712
|
* - `connection-refused`: The connection was refused. (ECONNREFUSED)
|
|
713
713
|
* - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
|
|
714
714
|
* - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
|
|
715
|
-
*
|
|
715
|
+
*
|
|
716
716
|
* # Implementors note
|
|
717
717
|
* WASI requires `send` to perform an implicit bind if the socket
|
|
718
718
|
* has not been bound. Not all platforms (notably Windows) exhibit
|
|
719
719
|
* this behavior natively. On such platforms, the WASI implementation
|
|
720
720
|
* should emulate it by performing the bind if the guest has not
|
|
721
721
|
* already done so.
|
|
722
|
-
*
|
|
722
|
+
*
|
|
723
723
|
* # References
|
|
724
724
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
|
|
725
725
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
|
|
@@ -733,20 +733,20 @@ export class UdpSocket {
|
|
|
733
733
|
send(data: Uint8Array, remoteAddress: IpSocketAddress | undefined): Promise<void>;
|
|
734
734
|
/**
|
|
735
735
|
* Receive a message on the socket.
|
|
736
|
-
*
|
|
736
|
+
*
|
|
737
737
|
* On success, the return value contains a tuple of the received data
|
|
738
738
|
* and the address of the sender. Theoretical maximum length of the
|
|
739
739
|
* data is 64 KiB. Though in practice, it will typically be less than
|
|
740
740
|
* 1500 bytes.
|
|
741
|
-
*
|
|
741
|
+
*
|
|
742
742
|
* If the socket is connected, the sender address is guaranteed to
|
|
743
743
|
* match the remote address passed to `connect`.
|
|
744
|
-
*
|
|
744
|
+
*
|
|
745
745
|
* # Typical errors
|
|
746
746
|
* - `invalid-state`: The socket has not been bound yet.
|
|
747
747
|
* - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
748
748
|
* - `connection-refused`: The connection was refused. (ECONNREFUSED)
|
|
749
|
-
*
|
|
749
|
+
*
|
|
750
750
|
* # References
|
|
751
751
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>
|
|
752
752
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>
|
|
@@ -759,17 +759,17 @@ export class UdpSocket {
|
|
|
759
759
|
receive(): Promise<[Uint8Array, IpSocketAddress]>;
|
|
760
760
|
/**
|
|
761
761
|
* Get the current bound address.
|
|
762
|
-
*
|
|
762
|
+
*
|
|
763
763
|
* POSIX mentions:
|
|
764
764
|
* > If the socket has not been bound to a local name, the value
|
|
765
765
|
* > stored in the object pointed to by `address` is unspecified.
|
|
766
|
-
*
|
|
766
|
+
*
|
|
767
767
|
* WASI is stricter and requires `get-local-address` to return
|
|
768
768
|
* `invalid-state` when the socket hasn't been bound yet.
|
|
769
|
-
*
|
|
769
|
+
*
|
|
770
770
|
* # Typical errors
|
|
771
771
|
* - `invalid-state`: The socket is not bound to any local address.
|
|
772
|
-
*
|
|
772
|
+
*
|
|
773
773
|
* # References
|
|
774
774
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
|
|
775
775
|
* - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
|
|
@@ -779,10 +779,10 @@ export class UdpSocket {
|
|
|
779
779
|
getLocalAddress(): IpSocketAddress;
|
|
780
780
|
/**
|
|
781
781
|
* Get the address the socket is currently "connected" to.
|
|
782
|
-
*
|
|
782
|
+
*
|
|
783
783
|
* # Typical errors
|
|
784
784
|
* - `invalid-state`: The socket is not "connected" to a specific remote address. (ENOTCONN)
|
|
785
|
-
*
|
|
785
|
+
*
|
|
786
786
|
* # References
|
|
787
787
|
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
|
|
788
788
|
* - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
|
|
@@ -792,17 +792,17 @@ export class UdpSocket {
|
|
|
792
792
|
getRemoteAddress(): IpSocketAddress;
|
|
793
793
|
/**
|
|
794
794
|
* Whether this is a IPv4 or IPv6 socket.
|
|
795
|
-
*
|
|
795
|
+
*
|
|
796
796
|
* This is the value passed to the constructor.
|
|
797
|
-
*
|
|
797
|
+
*
|
|
798
798
|
* Equivalent to the SO_DOMAIN socket option.
|
|
799
799
|
*/
|
|
800
800
|
getAddressFamily(): IpAddressFamily;
|
|
801
801
|
/**
|
|
802
802
|
* Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
|
|
803
|
-
*
|
|
803
|
+
*
|
|
804
804
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
805
|
-
*
|
|
805
|
+
*
|
|
806
806
|
* # Typical errors
|
|
807
807
|
* - `invalid-argument`: (set) The TTL value must be 1 or higher.
|
|
808
808
|
*/
|
|
@@ -812,14 +812,14 @@ export class UdpSocket {
|
|
|
812
812
|
* Kernel buffer space reserved for sending/receiving on this socket.
|
|
813
813
|
* Implementations usually treat this as a cap the buffer can grow to,
|
|
814
814
|
* rather than allocating the full amount immediately.
|
|
815
|
-
*
|
|
815
|
+
*
|
|
816
816
|
* If the provided value is 0, an `invalid-argument` error is returned.
|
|
817
817
|
* All other values are accepted without error, but may be
|
|
818
818
|
* clamped or rounded. As a result, the value read back from
|
|
819
819
|
* this setting may differ from the value that was set.
|
|
820
|
-
*
|
|
820
|
+
*
|
|
821
821
|
* Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
|
|
822
|
-
*
|
|
822
|
+
*
|
|
823
823
|
* # Typical errors
|
|
824
824
|
* - `invalid-argument`: (set) The provided value was 0.
|
|
825
825
|
*/
|