@bytecodealliance/preview2-shim 0.0.8 → 0.0.10
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/README.md +1 -0
- package/lib/browser/cli-base.js +48 -0
- package/lib/browser/clocks.js +44 -0
- package/lib/browser/filesystem.js +134 -141
- package/lib/browser/http.js +114 -0
- package/lib/browser/index.js +15 -37
- package/lib/browser/io.js +60 -20
- package/lib/browser/{console.js → logging.js} +7 -5
- package/lib/browser/poll.js +9 -7
- package/lib/browser/random.js +48 -24
- package/lib/browser/sockets.js +200 -0
- package/lib/nodejs/{preopens.js → cli-base.js} +38 -8
- package/lib/nodejs/clocks.js +44 -0
- package/lib/nodejs/filesystem.js +240 -237
- package/lib/nodejs/http.js +114 -0
- package/lib/nodejs/index.js +15 -37
- package/lib/nodejs/io.js +148 -19
- package/lib/nodejs/{console.js → logging.js} +7 -5
- package/lib/nodejs/poll.js +9 -7
- package/lib/nodejs/random.js +27 -13
- package/lib/nodejs/sockets.js +200 -0
- package/package.json +1 -1
- package/types/exports/{HTTP.d.ts → wasi-http-incoming-handler.d.ts} +1 -1
- package/types/imports/environment.d.ts +14 -1
- package/types/imports/exit.d.ts +4 -1
- package/types/imports/filesystem.d.ts +695 -48
- package/types/imports/handler.d.ts +40 -0
- package/types/imports/insecure-seed.d.ts +22 -0
- package/types/imports/insecure.d.ts +20 -0
- package/types/imports/instance-network.d.ts +4 -1
- package/types/imports/ip-name-lookup.d.ts +66 -9
- package/types/imports/monotonic-clock.d.ts +18 -2
- package/types/imports/network.d.ts +171 -9
- package/types/imports/{default-outgoing-HTTP.d.ts → outgoing-handler.d.ts} +1 -1
- package/types/imports/poll.d.ts +38 -2
- package/types/imports/preopens.d.ts +6 -9
- package/types/imports/random.d.ts +19 -2
- package/types/imports/stderr.d.ts +5 -0
- package/types/imports/stdin.d.ts +5 -0
- package/types/imports/stdout.d.ts +5 -0
- package/types/imports/streams.d.ts +161 -4
- package/types/imports/tcp-create-socket.d.ts +27 -3
- package/types/imports/tcp.d.ts +248 -15
- package/types/imports/timezone.d.ts +60 -2
- package/types/imports/types.d.ts +28 -28
- package/types/imports/udp-create-socket.d.ts +27 -3
- package/types/imports/udp.d.ts +195 -12
- package/types/imports/wall-clock.d.ts +24 -1
- package/types/wasi-command.d.ts +23 -0
- package/types/wasi-proxy.d.ts +10 -44
- package/types/wasi-reactor.d.ts +23 -70
- package/lib/browser/default-outgoing-HTTP.js +0 -3
- package/lib/browser/environment.js +0 -17
- package/lib/browser/exit.js +0 -21
- package/lib/browser/instance-network.js +0 -3
- package/lib/browser/ip-name-lookup.js +0 -23
- package/lib/browser/monotonic-clock.js +0 -14
- package/lib/browser/network.js +0 -3
- package/lib/browser/preopens.js +0 -11
- package/lib/browser/stderr.js +0 -4
- package/lib/browser/streams.js +0 -60
- package/lib/browser/tcp-create-socket.js +0 -3
- package/lib/browser/tcp.js +0 -75
- package/lib/browser/timezone.js +0 -12
- package/lib/browser/types.js +0 -99
- package/lib/browser/udp-create-socket.js +0 -3
- package/lib/browser/udp.js +0 -75
- package/lib/browser/wall-clock.js +0 -9
- package/lib/nodejs/default-outgoing-HTTP.js +0 -3
- package/lib/nodejs/environment.js +0 -19
- package/lib/nodejs/exit.js +0 -3
- package/lib/nodejs/instance-network.js +0 -3
- package/lib/nodejs/ip-name-lookup.js +0 -23
- package/lib/nodejs/monotonic-clock.js +0 -14
- package/lib/nodejs/network.js +0 -3
- package/lib/nodejs/stderr.js +0 -4
- package/lib/nodejs/streams.js +0 -97
- package/lib/nodejs/tcp-create-socket.js +0 -3
- package/lib/nodejs/tcp.js +0 -75
- package/lib/nodejs/timezone.js +0 -12
- package/lib/nodejs/types.js +0 -99
- package/lib/nodejs/udp-create-socket.js +0 -3
- package/lib/nodejs/udp.js +0 -75
- package/lib/nodejs/wall-clock.js +0 -9
- package/types/imports/console.d.ts +0 -17
- package/types/index.d.ts +0 -8
|
@@ -1,23 +1,180 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace ImportsStreams {
|
|
2
|
+
/**
|
|
3
|
+
* Read bytes from a stream.
|
|
4
|
+
*
|
|
5
|
+
* This function returns a list of bytes containing the data that was
|
|
6
|
+
* read, along with a bool which, when true, indicates that the end of the
|
|
7
|
+
* stream was reached. The returned list will contain up to `len` bytes; it
|
|
8
|
+
* may return fewer than requested, but not more.
|
|
9
|
+
*
|
|
10
|
+
* Once a stream has reached the end, subsequent calls to read or
|
|
11
|
+
* `skip` will always report end-of-stream rather than producing more
|
|
12
|
+
* data.
|
|
13
|
+
*
|
|
14
|
+
* If `len` is 0, it represents a request to read 0 bytes, which should
|
|
15
|
+
* always succeed, assuming the stream hasn't reached its end yet, and
|
|
16
|
+
* return an empty list.
|
|
17
|
+
*
|
|
18
|
+
* The len here is a `u64`, but some callees may not be able to allocate
|
|
19
|
+
* a buffer as large as that would imply.
|
|
20
|
+
* FIXME: describe what happens if allocation fails.
|
|
21
|
+
*/
|
|
2
22
|
export function read(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
|
|
23
|
+
/**
|
|
24
|
+
* Read bytes from a stream, with blocking.
|
|
25
|
+
*
|
|
26
|
+
* This is similar to `read`, except that it blocks until at least one
|
|
27
|
+
* byte can be read.
|
|
28
|
+
*/
|
|
3
29
|
export function blockingRead(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
|
|
30
|
+
/**
|
|
31
|
+
* Skip bytes from a stream.
|
|
32
|
+
*
|
|
33
|
+
* This is similar to the `read` function, but avoids copying the
|
|
34
|
+
* bytes into the instance.
|
|
35
|
+
*
|
|
36
|
+
* Once a stream has reached the end, subsequent calls to read or
|
|
37
|
+
* `skip` will always report end-of-stream rather than producing more
|
|
38
|
+
* data.
|
|
39
|
+
*
|
|
40
|
+
* This function returns the number of bytes skipped, along with a bool
|
|
41
|
+
* indicating whether the end of the stream was reached. The returned
|
|
42
|
+
* value will be at most `len`; it may be less.
|
|
43
|
+
*/
|
|
4
44
|
export function skip(this: InputStream, len: bigint): [bigint, boolean];
|
|
45
|
+
/**
|
|
46
|
+
* Skip bytes from a stream, with blocking.
|
|
47
|
+
*
|
|
48
|
+
* This is similar to `skip`, except that it blocks until at least one
|
|
49
|
+
* byte can be consumed.
|
|
50
|
+
*/
|
|
5
51
|
export function blockingSkip(this: InputStream, len: bigint): [bigint, boolean];
|
|
52
|
+
/**
|
|
53
|
+
* Create a `pollable` which will resolve once either the specified stream
|
|
54
|
+
* has bytes available to read or the other end of the stream has been
|
|
55
|
+
* closed.
|
|
56
|
+
*/
|
|
6
57
|
export function subscribeToInputStream(this: InputStream): Pollable;
|
|
58
|
+
/**
|
|
59
|
+
* Dispose of the specified `input-stream`, after which it may no longer
|
|
60
|
+
* be used.
|
|
61
|
+
*/
|
|
7
62
|
export function dropInputStream(this: InputStream): void;
|
|
63
|
+
/**
|
|
64
|
+
* Write bytes to a stream.
|
|
65
|
+
*
|
|
66
|
+
* This function returns a `u64` indicating the number of bytes from
|
|
67
|
+
* `buf` that were written; it may be less than the full list.
|
|
68
|
+
*/
|
|
8
69
|
export function write(this: OutputStream, buf: Uint8Array): bigint;
|
|
70
|
+
/**
|
|
71
|
+
* Write bytes to a stream, with blocking.
|
|
72
|
+
*
|
|
73
|
+
* This is similar to `write`, except that it blocks until at least one
|
|
74
|
+
* byte can be written.
|
|
75
|
+
*/
|
|
9
76
|
export function blockingWrite(this: OutputStream, buf: Uint8Array): bigint;
|
|
77
|
+
/**
|
|
78
|
+
* Write multiple zero bytes to a stream.
|
|
79
|
+
*
|
|
80
|
+
* This function returns a `u64` indicating the number of zero bytes
|
|
81
|
+
* that were written; it may be less than `len`.
|
|
82
|
+
*/
|
|
10
83
|
export function writeZeroes(this: OutputStream, len: bigint): bigint;
|
|
84
|
+
/**
|
|
85
|
+
* Write multiple zero bytes to a stream, with blocking.
|
|
86
|
+
*
|
|
87
|
+
* This is similar to `write-zeroes`, except that it blocks until at least
|
|
88
|
+
* one byte can be written.
|
|
89
|
+
*/
|
|
11
90
|
export function blockingWriteZeroes(this: OutputStream, len: bigint): bigint;
|
|
91
|
+
/**
|
|
92
|
+
* Read from one stream and write to another.
|
|
93
|
+
*
|
|
94
|
+
* This function returns the number of bytes transferred; it may be less
|
|
95
|
+
* than `len`.
|
|
96
|
+
*
|
|
97
|
+
* Unlike other I/O functions, this function blocks until all the data
|
|
98
|
+
* read from the input stream has been written to the output stream.
|
|
99
|
+
*/
|
|
12
100
|
export function splice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
|
|
101
|
+
/**
|
|
102
|
+
* Read from one stream and write to another, with blocking.
|
|
103
|
+
*
|
|
104
|
+
* This is similar to `splice`, except that it blocks until at least
|
|
105
|
+
* one byte can be read.
|
|
106
|
+
*/
|
|
13
107
|
export function blockingSplice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
|
|
108
|
+
/**
|
|
109
|
+
* Forward the entire contents of an input stream to an output stream.
|
|
110
|
+
*
|
|
111
|
+
* This function repeatedly reads from the input stream and writes
|
|
112
|
+
* the data to the output stream, until the end of the input stream
|
|
113
|
+
* is reached, or an error is encountered.
|
|
114
|
+
*
|
|
115
|
+
* Unlike other I/O functions, this function blocks until the end
|
|
116
|
+
* of the input stream is seen and all the data has been written to
|
|
117
|
+
* the output stream.
|
|
118
|
+
*
|
|
119
|
+
* This function returns the number of bytes transferred.
|
|
120
|
+
*/
|
|
14
121
|
export function forward(this: OutputStream, src: InputStream): bigint;
|
|
122
|
+
/**
|
|
123
|
+
* Create a `pollable` which will resolve once either the specified stream
|
|
124
|
+
* is ready to accept bytes or the other end of the stream has been closed.
|
|
125
|
+
*/
|
|
15
126
|
export function subscribeToOutputStream(this: OutputStream): Pollable;
|
|
127
|
+
/**
|
|
128
|
+
* Dispose of the specified `output-stream`, after which it may no longer
|
|
129
|
+
* be used.
|
|
130
|
+
*/
|
|
16
131
|
export function dropOutputStream(this: OutputStream): void;
|
|
17
132
|
}
|
|
18
|
-
export type InputStream = number;
|
|
19
|
-
export interface StreamError {
|
|
20
|
-
}
|
|
21
133
|
import type { Pollable } from '../imports/poll';
|
|
22
134
|
export { Pollable };
|
|
135
|
+
/**
|
|
136
|
+
* An error type returned from a stream operation. Currently this
|
|
137
|
+
* doesn't provide any additional information.
|
|
138
|
+
*/
|
|
139
|
+
export interface StreamError {
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* An output bytestream. In the future, this will be replaced by handle
|
|
143
|
+
* types.
|
|
144
|
+
*
|
|
145
|
+
* This conceptually represents a `stream<u8, _>`. It's temporary
|
|
146
|
+
* scaffolding until component-model's async features are ready.
|
|
147
|
+
*
|
|
148
|
+
* `output-stream`s are *non-blocking* to the extent practical on
|
|
149
|
+
* underlying platforms. Except where specified otherwise, I/O operations also
|
|
150
|
+
* always return promptly, after the number of bytes that can be written
|
|
151
|
+
* promptly, which could even be zero. To wait for the stream to be ready to
|
|
152
|
+
* accept data, the `subscribe-to-output-stream` function to obtain a
|
|
153
|
+
* `pollable` which can be polled for using `wasi_poll`.
|
|
154
|
+
*
|
|
155
|
+
* And at present, it is a `u32` instead of being an actual handle, until
|
|
156
|
+
* the wit-bindgen implementation of handles and resources is ready.
|
|
157
|
+
*
|
|
158
|
+
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
159
|
+
*/
|
|
23
160
|
export type OutputStream = number;
|
|
161
|
+
/**
|
|
162
|
+
* An input bytestream. In the future, this will be replaced by handle
|
|
163
|
+
* types.
|
|
164
|
+
*
|
|
165
|
+
* This conceptually represents a `stream<u8, _>`. It's temporary
|
|
166
|
+
* scaffolding until component-model's async features are ready.
|
|
167
|
+
*
|
|
168
|
+
* `input-stream`s are *non-blocking* to the extent practical on underlying
|
|
169
|
+
* platforms. I/O operations always return promptly; if fewer bytes are
|
|
170
|
+
* promptly available than requested, they return the number of bytes promptly
|
|
171
|
+
* available, which could even be zero. To wait for data to be available,
|
|
172
|
+
* use the `subscribe-to-input-stream` function to obtain a `pollable` which
|
|
173
|
+
* can be polled for using `wasi_poll`.
|
|
174
|
+
*
|
|
175
|
+
* And at present, it is a `u32` instead of being an actual handle, until
|
|
176
|
+
* the wit-bindgen implementation of handles and resources is ready.
|
|
177
|
+
*
|
|
178
|
+
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
179
|
+
*/
|
|
180
|
+
export type InputStream = number;
|
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace ImportsTcpCreateSocket {
|
|
2
|
+
/**
|
|
3
|
+
* Create a new TCP socket.
|
|
4
|
+
*
|
|
5
|
+
* Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX.
|
|
6
|
+
*
|
|
7
|
+
* This function does not require a network capability handle. This is considered to be safe because
|
|
8
|
+
* at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`listen`/`connect`
|
|
9
|
+
* is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
|
|
10
|
+
*
|
|
11
|
+
* All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
|
|
12
|
+
*
|
|
13
|
+
* # Typical errors
|
|
14
|
+
* - `not-supported`: The host does not support TCP sockets. (EOPNOTSUPP)
|
|
15
|
+
* - `address-family-not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT)
|
|
16
|
+
* - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
|
|
17
|
+
*
|
|
18
|
+
* # References
|
|
19
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
|
|
20
|
+
* - <https://man7.org/linux/man-pages/man2/socket.2.html>
|
|
21
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw>
|
|
22
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2>
|
|
23
|
+
*/
|
|
2
24
|
export function createTcpSocket(addressFamily: IpAddressFamily): TcpSocket;
|
|
3
25
|
}
|
|
26
|
+
import type { Network } from '../imports/network';
|
|
27
|
+
export { Network };
|
|
28
|
+
import type { ErrorCode } from '../imports/network';
|
|
29
|
+
export { ErrorCode };
|
|
4
30
|
import type { IpAddressFamily } from '../imports/network';
|
|
5
31
|
export { IpAddressFamily };
|
|
6
32
|
import type { TcpSocket } from '../imports/tcp';
|
|
7
33
|
export { TcpSocket };
|
|
8
|
-
import type { Error } from '../imports/network';
|
|
9
|
-
export { Error };
|
package/types/imports/tcp.d.ts
CHANGED
|
@@ -1,52 +1,285 @@
|
|
|
1
|
-
export namespace
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export namespace ImportsTcp {
|
|
2
|
+
/**
|
|
3
|
+
* Bind the socket to a specific network on the provided IP address and port.
|
|
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 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 a listen or connect operation will
|
|
10
|
+
* implicitly bind the socket.
|
|
11
|
+
*
|
|
12
|
+
* Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
|
|
13
|
+
*
|
|
14
|
+
* # Typical `start` errors
|
|
15
|
+
* - `address-family-mismatch`: The `local-address` has the wrong address family. (EINVAL)
|
|
16
|
+
* - `already-bound`: The socket is already bound. (EINVAL)
|
|
17
|
+
* - `concurrency-conflict`: Another `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
18
|
+
*
|
|
19
|
+
* # Typical `finish` errors
|
|
20
|
+
* - `ephemeral-ports-exhausted`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
|
|
21
|
+
* - `address-in-use`: Address is already in use. (EADDRINUSE)
|
|
22
|
+
* - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
|
|
23
|
+
* - `not-in-progress`: A `bind` operation is not in progress.
|
|
24
|
+
* - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
|
|
25
|
+
*
|
|
26
|
+
* # References
|
|
27
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
|
|
28
|
+
* - <https://man7.org/linux/man-pages/man2/bind.2.html>
|
|
29
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind>
|
|
30
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html>
|
|
31
|
+
*/
|
|
32
|
+
export function startBind(this: TcpSocket, network: Network, localAddress: IpSocketAddress): void;
|
|
33
|
+
export function finishBind(this: TcpSocket): void;
|
|
34
|
+
/**
|
|
35
|
+
* Connect to a remote endpoint.
|
|
36
|
+
*
|
|
37
|
+
* On success:
|
|
38
|
+
* - the socket is transitioned into the Connection state
|
|
39
|
+
* - a pair of streams is returned that can be used to read & write to the connection
|
|
40
|
+
*
|
|
41
|
+
* # Typical `start` errors
|
|
42
|
+
* - `address-family-mismatch`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
43
|
+
* - `invalid-remote-address`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows)
|
|
44
|
+
* - `invalid-remote-address`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows)
|
|
45
|
+
* - `already-attached`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
|
|
46
|
+
* - `already-connected`: The socket is already in the Connection state. (EISCONN)
|
|
47
|
+
* - `already-listening`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows)
|
|
48
|
+
* - `concurrency-conflict`: Another `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
49
|
+
*
|
|
50
|
+
* # Typical `finish` errors
|
|
51
|
+
* - `timeout`: Connection timed out. (ETIMEDOUT)
|
|
52
|
+
* - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED)
|
|
53
|
+
* - `connection-reset`: The connection was reset. (ECONNRESET)
|
|
54
|
+
* - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
|
|
55
|
+
* - `ephemeral-ports-exhausted`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
|
|
56
|
+
* - `not-in-progress`: A `connect` operation is not in progress.
|
|
57
|
+
* - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
|
|
58
|
+
*
|
|
59
|
+
* # References
|
|
60
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
|
|
61
|
+
* - <https://man7.org/linux/man-pages/man2/connect.2.html>
|
|
62
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
|
|
63
|
+
* - <https://man.freebsd.org/cgi/man.cgi?connect>
|
|
64
|
+
*/
|
|
65
|
+
export function startConnect(this: TcpSocket, network: Network, remoteAddress: IpSocketAddress): void;
|
|
66
|
+
export function finishConnect(this: TcpSocket): [InputStream, OutputStream];
|
|
67
|
+
/**
|
|
68
|
+
* Start listening for new connections.
|
|
69
|
+
*
|
|
70
|
+
* Transitions the socket into the Listener state.
|
|
71
|
+
*
|
|
72
|
+
* Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
|
|
73
|
+
*
|
|
74
|
+
* # Typical `start` errors
|
|
75
|
+
* - `already-attached`: The socket is already attached to a different network. The `network` passed to `listen` must be identical to the one passed to `bind`.
|
|
76
|
+
* - `already-connected`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD)
|
|
77
|
+
* - `already-listening`: The socket is already in the Listener state.
|
|
78
|
+
* - `concurrency-conflict`: Another `bind`, `connect` or `listen` operation is already in progress. (EINVAL on BSD)
|
|
79
|
+
*
|
|
80
|
+
* # Typical `finish` errors
|
|
81
|
+
* - `ephemeral-ports-exhausted`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
|
|
82
|
+
* - `not-in-progress`: A `listen` operation is not in progress.
|
|
83
|
+
* - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
|
|
84
|
+
*
|
|
85
|
+
* # References
|
|
86
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html>
|
|
87
|
+
* - <https://man7.org/linux/man-pages/man2/listen.2.html>
|
|
88
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen>
|
|
89
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=listen&sektion=2>
|
|
90
|
+
*/
|
|
91
|
+
export function startListen(this: TcpSocket, network: Network): void;
|
|
92
|
+
export function finishListen(this: TcpSocket): void;
|
|
93
|
+
/**
|
|
94
|
+
* Accept a new client socket.
|
|
95
|
+
*
|
|
96
|
+
* The returned socket is bound and in the Connection state.
|
|
97
|
+
*
|
|
98
|
+
* On success, this function returns the newly accepted client socket along with
|
|
99
|
+
* a pair of streams that can be used to read & write to the connection.
|
|
100
|
+
*
|
|
101
|
+
* # Typical errors
|
|
102
|
+
* - `not-listening`: Socket is not in the Listener state. (EINVAL)
|
|
103
|
+
* - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN)
|
|
104
|
+
*
|
|
105
|
+
* Host implementations must skip over transient errors returned by the native accept syscall.
|
|
106
|
+
*
|
|
107
|
+
* # References
|
|
108
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html>
|
|
109
|
+
* - <https://man7.org/linux/man-pages/man2/accept.2.html>
|
|
110
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept>
|
|
111
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=accept&sektion=2>
|
|
112
|
+
*/
|
|
5
113
|
export function accept(this: TcpSocket): [TcpSocket, InputStream, OutputStream];
|
|
114
|
+
/**
|
|
115
|
+
* Get the bound local address.
|
|
116
|
+
*
|
|
117
|
+
* # Typical errors
|
|
118
|
+
* - `not-bound`: The socket is not bound to any local address.
|
|
119
|
+
*
|
|
120
|
+
* # References
|
|
121
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
|
|
122
|
+
* - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
|
|
123
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
|
|
124
|
+
* - <https://man.freebsd.org/cgi/man.cgi?getsockname>
|
|
125
|
+
*/
|
|
6
126
|
export function localAddress(this: TcpSocket): IpSocketAddress;
|
|
127
|
+
/**
|
|
128
|
+
* Get the bound remote address.
|
|
129
|
+
*
|
|
130
|
+
* # Typical errors
|
|
131
|
+
* - `not-connected`: The socket is not connected to a remote address. (ENOTCONN)
|
|
132
|
+
*
|
|
133
|
+
* # References
|
|
134
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
|
|
135
|
+
* - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
|
|
136
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
|
|
137
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
|
|
138
|
+
*/
|
|
7
139
|
export function remoteAddress(this: TcpSocket): IpSocketAddress;
|
|
140
|
+
/**
|
|
141
|
+
* Whether this is a IPv4 or IPv6 socket.
|
|
142
|
+
*
|
|
143
|
+
* Equivalent to the SO_DOMAIN socket option.
|
|
144
|
+
*/
|
|
8
145
|
export function addressFamily(this: TcpSocket): IpAddressFamily;
|
|
146
|
+
/**
|
|
147
|
+
* Whether IPv4 compatibility (dual-stack) mode is disabled or not.
|
|
148
|
+
*
|
|
149
|
+
* Equivalent to the IPV6_V6ONLY socket option.
|
|
150
|
+
*
|
|
151
|
+
* # Typical errors
|
|
152
|
+
* - `ipv6-only-operation`: (get/set) `this` socket is an IPv4 socket.
|
|
153
|
+
* - `already-bound`: (set) The socket is already bound.
|
|
154
|
+
* - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.)
|
|
155
|
+
* - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
156
|
+
*/
|
|
9
157
|
export function ipv6Only(this: TcpSocket): boolean;
|
|
10
158
|
export function setIpv6Only(this: TcpSocket, value: boolean): void;
|
|
159
|
+
/**
|
|
160
|
+
* Hints the desired listen queue size. Implementations are free to ignore this.
|
|
161
|
+
*
|
|
162
|
+
* # Typical errors
|
|
163
|
+
* - `already-connected`: (set) The socket is already in the Connection state.
|
|
164
|
+
* - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
165
|
+
*/
|
|
11
166
|
export function setListenBacklogSize(this: TcpSocket, value: bigint): void;
|
|
167
|
+
/**
|
|
168
|
+
* Equivalent to the SO_KEEPALIVE socket option.
|
|
169
|
+
*
|
|
170
|
+
* # Typical errors
|
|
171
|
+
* - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
172
|
+
*/
|
|
12
173
|
export function keepAlive(this: TcpSocket): boolean;
|
|
13
174
|
export function setKeepAlive(this: TcpSocket, value: boolean): void;
|
|
175
|
+
/**
|
|
176
|
+
* Equivalent to the TCP_NODELAY socket option.
|
|
177
|
+
*
|
|
178
|
+
* # Typical errors
|
|
179
|
+
* - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
180
|
+
*/
|
|
14
181
|
export function noDelay(this: TcpSocket): boolean;
|
|
15
182
|
export function setNoDelay(this: TcpSocket, value: boolean): void;
|
|
183
|
+
/**
|
|
184
|
+
* Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
|
|
185
|
+
*
|
|
186
|
+
* # Typical errors
|
|
187
|
+
* - `already-connected`: (set) The socket is already in the Connection state.
|
|
188
|
+
* - `already-listening`: (set) The socket is already in the Listener state.
|
|
189
|
+
* - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
190
|
+
*/
|
|
16
191
|
export function unicastHopLimit(this: TcpSocket): number;
|
|
17
192
|
export function setUnicastHopLimit(this: TcpSocket, value: number): void;
|
|
193
|
+
/**
|
|
194
|
+
* The kernel buffer space reserved for sends/receives on this socket.
|
|
195
|
+
*
|
|
196
|
+
* Note #1: an implementation may choose to cap or round the buffer size when setting the value.
|
|
197
|
+
* In other words, after setting a value, reading the same setting back may return a different value.
|
|
198
|
+
*
|
|
199
|
+
* Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
|
|
200
|
+
* actual data to be sent/received by the application, because the kernel might also use the buffer space
|
|
201
|
+
* for internal metadata structures.
|
|
202
|
+
*
|
|
203
|
+
* Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
|
|
204
|
+
*
|
|
205
|
+
* # Typical errors
|
|
206
|
+
* - `already-connected`: (set) The socket is already in the Connection state.
|
|
207
|
+
* - `already-listening`: (set) The socket is already in the Listener state.
|
|
208
|
+
* - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
|
|
209
|
+
*/
|
|
18
210
|
export function receiveBufferSize(this: TcpSocket): bigint;
|
|
19
211
|
export function setReceiveBufferSize(this: TcpSocket, value: bigint): void;
|
|
20
212
|
export function sendBufferSize(this: TcpSocket): bigint;
|
|
21
213
|
export function setSendBufferSize(this: TcpSocket, value: bigint): void;
|
|
22
|
-
|
|
23
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Create a `pollable` which will resolve once the socket is ready for I/O.
|
|
216
|
+
*
|
|
217
|
+
* Note: this function is here for WASI Preview2 only.
|
|
218
|
+
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
219
|
+
*/
|
|
24
220
|
export function subscribe(this: TcpSocket): Pollable;
|
|
221
|
+
/**
|
|
222
|
+
* Initiate a graceful shutdown.
|
|
223
|
+
*
|
|
224
|
+
* - receive: the socket is not expecting to receive any more data from the peer. All subsequent read
|
|
225
|
+
* operations on the `input-stream` associated with this socket will return an End Of Stream indication.
|
|
226
|
+
* Any data still in the receive queue at time of calling `shutdown` will be discarded.
|
|
227
|
+
* - send: the socket is not expecting to send any more data to the peer. All subsequent write
|
|
228
|
+
* operations on the `output-stream` associated with this socket will return an error.
|
|
229
|
+
* - both: same effect as receive & send combined.
|
|
230
|
+
*
|
|
231
|
+
* The shutdown function does not close (drop) the socket.
|
|
232
|
+
*
|
|
233
|
+
* # Typical errors
|
|
234
|
+
* - `not-connected`: The socket is not in the Connection state. (ENOTCONN)
|
|
235
|
+
*
|
|
236
|
+
* # References
|
|
237
|
+
* - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html>
|
|
238
|
+
* - <https://man7.org/linux/man-pages/man2/shutdown.2.html>
|
|
239
|
+
* - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown>
|
|
240
|
+
* - <https://man.freebsd.org/cgi/man.cgi?query=shutdown&sektion=2>
|
|
241
|
+
*/
|
|
25
242
|
export function shutdown(this: TcpSocket, shutdownType: ShutdownType): void;
|
|
243
|
+
/**
|
|
244
|
+
* Dispose of the specified `tcp-socket`, after which it may no longer be used.
|
|
245
|
+
*
|
|
246
|
+
* Similar to the POSIX `close` function.
|
|
247
|
+
*
|
|
248
|
+
* Note: this function is scheduled to be removed when Resources are natively supported in Wit.
|
|
249
|
+
*/
|
|
26
250
|
export function dropTcpSocket(this: TcpSocket): void;
|
|
27
251
|
}
|
|
28
|
-
export type TcpSocket = number;
|
|
29
|
-
import type { Network } from '../imports/network';
|
|
30
|
-
export { Network };
|
|
31
|
-
import type { IpSocketAddress } from '../imports/network';
|
|
32
|
-
export { IpSocketAddress };
|
|
33
|
-
import type { Error } from '../imports/network';
|
|
34
|
-
export { Error };
|
|
35
252
|
import type { InputStream } from '../imports/streams';
|
|
36
253
|
export { InputStream };
|
|
37
254
|
import type { OutputStream } from '../imports/streams';
|
|
38
255
|
export { OutputStream };
|
|
39
|
-
import type { IpAddressFamily } from '../imports/network';
|
|
40
|
-
export { IpAddressFamily };
|
|
41
256
|
import type { Pollable } from '../imports/poll';
|
|
42
257
|
export { Pollable };
|
|
258
|
+
import type { Network } from '../imports/network';
|
|
259
|
+
export { Network };
|
|
260
|
+
import type { ErrorCode } from '../imports/network';
|
|
261
|
+
export { ErrorCode };
|
|
262
|
+
import type { IpSocketAddress } from '../imports/network';
|
|
263
|
+
export { IpSocketAddress };
|
|
264
|
+
import type { IpAddressFamily } from '../imports/network';
|
|
265
|
+
export { IpAddressFamily };
|
|
266
|
+
/**
|
|
267
|
+
* A TCP socket handle.
|
|
268
|
+
*/
|
|
269
|
+
export type TcpSocket = number;
|
|
43
270
|
/**
|
|
44
271
|
* # Variants
|
|
45
272
|
*
|
|
46
273
|
* ## `"receive"`
|
|
47
274
|
*
|
|
275
|
+
* Similar to `SHUT_RD` in POSIX.
|
|
276
|
+
*
|
|
48
277
|
* ## `"send"`
|
|
49
278
|
*
|
|
279
|
+
* Similar to `SHUT_WR` in POSIX.
|
|
280
|
+
*
|
|
50
281
|
* ## `"both"`
|
|
282
|
+
*
|
|
283
|
+
* Similar to `SHUT_RDWR` in POSIX.
|
|
51
284
|
*/
|
|
52
285
|
export type ShutdownType = 'receive' | 'send' | 'both';
|
|
@@ -1,13 +1,71 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace ImportsTimezone {
|
|
2
|
+
/**
|
|
3
|
+
* Return information needed to display the given `datetime`. This includes
|
|
4
|
+
* the UTC offset, the time zone name, and a flag indicating whether
|
|
5
|
+
* daylight saving time is active.
|
|
6
|
+
*
|
|
7
|
+
* If the timezone cannot be determined for the given `datetime`, return a
|
|
8
|
+
* `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
|
|
9
|
+
* saving time.
|
|
10
|
+
*/
|
|
2
11
|
export function display(this: Timezone, when: Datetime): TimezoneDisplay;
|
|
12
|
+
/**
|
|
13
|
+
* The same as `display`, but only return the UTC offset.
|
|
14
|
+
*/
|
|
3
15
|
export function utcOffset(this: Timezone, when: Datetime): number;
|
|
16
|
+
/**
|
|
17
|
+
* Dispose of the specified input-stream, after which it may no longer
|
|
18
|
+
* be used.
|
|
19
|
+
*/
|
|
4
20
|
export function dropTimezone(this: Timezone): void;
|
|
5
21
|
}
|
|
6
|
-
export type Timezone = number;
|
|
7
22
|
import type { Datetime } from '../imports/wall-clock';
|
|
8
23
|
export { Datetime };
|
|
24
|
+
/**
|
|
25
|
+
* Information useful for displaying the timezone of a specific `datetime`.
|
|
26
|
+
*
|
|
27
|
+
* This information may vary within a single `timezone` to reflect daylight
|
|
28
|
+
* saving time adjustments.
|
|
29
|
+
*/
|
|
9
30
|
export interface TimezoneDisplay {
|
|
31
|
+
/**
|
|
32
|
+
* The number of seconds difference between UTC time and the local
|
|
33
|
+
* time of the timezone.
|
|
34
|
+
*
|
|
35
|
+
* The returned value will always be less than 86400 which is the
|
|
36
|
+
* number of seconds in a day (24*60*60).
|
|
37
|
+
*
|
|
38
|
+
* In implementations that do not expose an actual time zone, this
|
|
39
|
+
* should return 0.
|
|
40
|
+
*/
|
|
10
41
|
utcOffset: number,
|
|
42
|
+
/**
|
|
43
|
+
* The abbreviated name of the timezone to display to a user. The name
|
|
44
|
+
* `UTC` indicates Coordinated Universal Time. Otherwise, this should
|
|
45
|
+
* reference local standards for the name of the time zone.
|
|
46
|
+
*
|
|
47
|
+
* In implementations that do not expose an actual time zone, this
|
|
48
|
+
* should be the string `UTC`.
|
|
49
|
+
*
|
|
50
|
+
* In time zones that do not have an applicable name, a formatted
|
|
51
|
+
* representation of the UTC offset may be returned, such as `-04:00`.
|
|
52
|
+
*/
|
|
11
53
|
name: string,
|
|
54
|
+
/**
|
|
55
|
+
* Whether daylight saving time is active.
|
|
56
|
+
*
|
|
57
|
+
* In implementations that do not expose an actual time zone, this
|
|
58
|
+
* should return false.
|
|
59
|
+
*/
|
|
12
60
|
inDaylightSavingTime: boolean,
|
|
13
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A timezone.
|
|
64
|
+
*
|
|
65
|
+
* In timezones that recognize daylight saving time, also known as daylight
|
|
66
|
+
* time and summer time, the information returned from the functions varies
|
|
67
|
+
* over time to reflect these adjustments.
|
|
68
|
+
*
|
|
69
|
+
* This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
|
|
70
|
+
*/
|
|
71
|
+
export type Timezone = number;
|
package/types/imports/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export namespace
|
|
1
|
+
export namespace ImportsTypes {
|
|
2
2
|
export function dropFields(fields: Fields): void;
|
|
3
3
|
export function newFields(entries: [string, string][]): Fields;
|
|
4
4
|
export function fieldsGet(fields: Fields, name: string): string[];
|
|
@@ -33,15 +33,32 @@ export namespace Types {
|
|
|
33
33
|
export function futureIncomingResponseGet(f: FutureIncomingResponse): Result<IncomingResponse, Error> | null;
|
|
34
34
|
export function listenToFutureIncomingResponse(f: FutureIncomingResponse): Pollable;
|
|
35
35
|
}
|
|
36
|
-
export type Fields = number;
|
|
37
36
|
import type { InputStream } from '../imports/streams';
|
|
38
37
|
export { InputStream };
|
|
39
|
-
export type IncomingStream = InputStream;
|
|
40
|
-
export type Trailers = Fields;
|
|
41
38
|
import type { OutputStream } from '../imports/streams';
|
|
42
39
|
export { OutputStream };
|
|
40
|
+
import type { Pollable } from '../imports/poll';
|
|
41
|
+
export { Pollable };
|
|
42
|
+
export type StatusCode = number;
|
|
43
|
+
export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
|
|
44
|
+
export interface SchemeHttp {
|
|
45
|
+
tag: 'HTTP',
|
|
46
|
+
}
|
|
47
|
+
export interface SchemeHttps {
|
|
48
|
+
tag: 'HTTPS',
|
|
49
|
+
}
|
|
50
|
+
export interface SchemeOther {
|
|
51
|
+
tag: 'other',
|
|
52
|
+
val: string,
|
|
53
|
+
}
|
|
54
|
+
export type ResponseOutparam = number;
|
|
55
|
+
export interface RequestOptions {
|
|
56
|
+
connectTimeoutMs?: number,
|
|
57
|
+
firstByteTimeoutMs?: number,
|
|
58
|
+
betweenBytesTimeoutMs?: number,
|
|
59
|
+
}
|
|
43
60
|
export type OutgoingStream = OutputStream;
|
|
44
|
-
export type
|
|
61
|
+
export type OutgoingResponse = number;
|
|
45
62
|
export type OutgoingRequest = number;
|
|
46
63
|
export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
|
|
47
64
|
export interface MethodGet {
|
|
@@ -75,20 +92,13 @@ export interface MethodOther {
|
|
|
75
92
|
tag: 'other',
|
|
76
93
|
val: string,
|
|
77
94
|
}
|
|
78
|
-
export type
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
export interface SchemeOther {
|
|
86
|
-
tag: 'other',
|
|
87
|
-
val: string,
|
|
88
|
-
}
|
|
95
|
+
export type IncomingStream = InputStream;
|
|
96
|
+
export type IncomingResponse = number;
|
|
97
|
+
export type IncomingRequest = number;
|
|
98
|
+
export type FutureIncomingResponse = number;
|
|
99
|
+
export type Fields = number;
|
|
100
|
+
export type Trailers = Fields;
|
|
89
101
|
export type Headers = Fields;
|
|
90
|
-
export type ResponseOutparam = number;
|
|
91
|
-
export type OutgoingResponse = number;
|
|
92
102
|
export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
|
|
93
103
|
export interface ErrorInvalidUrl {
|
|
94
104
|
tag: 'invalid-url',
|
|
@@ -106,14 +116,4 @@ export interface ErrorUnexpectedError {
|
|
|
106
116
|
tag: 'unexpected-error',
|
|
107
117
|
val: string,
|
|
108
118
|
}
|
|
109
|
-
export type IncomingResponse = number;
|
|
110
|
-
export type StatusCode = number;
|
|
111
|
-
export type FutureIncomingResponse = number;
|
|
112
|
-
import type { Pollable } from '../imports/poll';
|
|
113
|
-
export { Pollable };
|
|
114
|
-
export interface RequestOptions {
|
|
115
|
-
connectTimeoutMs?: number,
|
|
116
|
-
firstByteTimeoutMs?: number,
|
|
117
|
-
betweenBytesTimeoutMs?: number,
|
|
118
|
-
}
|
|
119
119
|
export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
|