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