diff --git a/proposals/cli/command.md b/proposals/cli/command.md new file mode 100644 index 00000000..006b06fd --- /dev/null +++ b/proposals/cli/command.md @@ -0,0 +1,2524 @@ +

World command

+ +

Import interface wasi:cli/environment@0.3.1

+
+

Functions

+

get-environment: func

+

Get the POSIX-style environment variables.

+

Each environment variable is provided as a pair of string variable names +and string value.

+

Morally, these are a value import, but until value imports are available +in the component model, this import function should return the same +values each time it is called.

+
Return values
+ +

get-arguments: func

+

Get the POSIX-style arguments to the program.

+
Return values
+ +

get-initial-cwd: func

+

Return a path that programs should use as their initial current working +directory, interpreting . as shorthand for this.

+
Return values
+ +

Import interface wasi:cli/exit@0.3.1

+
+

Functions

+

exit: func

+

Exit the current instance and any linked instances.

+
Params
+ +

exit-with-code: func

+

Exit the current instance and any linked instances, reporting the +specified status code to the host.

+

The meaning of the code depends on the context, with 0 usually meaning +"success", and other values indicating various types of failure.

+

This function does not return; the effect is analogous to a trap, but +without the connotation that something bad has happened.

+
Params
+ +

Import interface wasi:cli/types@0.3.1

+
+

Types

+

enum error-code

+
Enum Cases
+ +

Import interface wasi:cli/stdin@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

read-via-stream: func

+

Return a stream for reading from stdin.

+

This function returns a stream which provides data read from stdin, +and a future to signal read results.

+

If the stream's readable end is dropped the future will resolve to success.

+

If the stream's writable end is dropped the future will either resolve to +success if stdin was closed by the writer or to an error-code if reading +failed for some other reason.

+

Multiple streams may be active at the same time. The behavior of concurrent +reads is implementation-specific.

+
Return values
+ +

Import interface wasi:cli/stdout@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stdout.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/stderr@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stderr.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/terminal-input@0.3.1

+

Terminal input.

+

In the future, this may include functions for disabling echoing, +disabling input buffering so that keyboard events are sent through +immediately, querying supported features, and so on.

+
+

Types

+

resource terminal-input

+

The input side of a terminal.

+

Import interface wasi:cli/terminal-output@0.3.1

+

Terminal output.

+

In the future, this may include functions for querying the terminal +size, being notified of terminal size changes, querying supported +features, and so on.

+
+

Types

+

resource terminal-output

+

The output side of a terminal.

+

Import interface wasi:cli/terminal-stdin@0.3.1

+

An interface providing an optional terminal-input for stdin as a +link-time authority.

+
+

Types

+

type terminal-input

+

terminal-input

+

+


+

Functions

+

get-terminal-stdin: func

+

If stdin is connected to a terminal, return a terminal-input handle +allowing further interaction with it.

+
Return values
+ +

Import interface wasi:cli/terminal-stdout@0.3.1

+

An interface providing an optional terminal-output for stdout as a +link-time authority.

+
+

Types

+

type terminal-output

+

terminal-output

+

+


+

Functions

+

get-terminal-stdout: func

+

If stdout is connected to a terminal, return a terminal-output handle +allowing further interaction with it.

+
Return values
+ +

Import interface wasi:cli/terminal-stderr@0.3.1

+

An interface providing an optional terminal-output for stderr as a +link-time authority.

+
+

Types

+

type terminal-output

+

terminal-output

+

+


+

Functions

+

get-terminal-stderr: func

+

If stderr is connected to a terminal, return a terminal-output handle +allowing further interaction with it.

+
Return values
+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:clocks/monotonic-clock@0.3.1

+

WASI Monotonic Clock is a clock API intended to let users measure elapsed +time.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

A monotonic clock is a clock which has an unspecified initial value, and +successive reads of the clock will produce non-decreasing values.

+
+

Types

+

type duration

+

duration

+

+

type mark

+

u64

+

A mark on a monotonic clock is a number of nanoseconds since an +unspecified initial value, and can only be compared to instances from +the same monotonic-clock. +


+

Functions

+

now: func

+

Read the current value of the clock.

+

The clock is monotonic, therefore calling this function repeatedly will +produce a sequence of non-decreasing values.

+

For completeness, this function traps if it's not possible to represent +the value of the clock in a mark. Consequently, implementations +should ensure that the starting time is low enough to avoid the +possibility of overflow in practice.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the duration of time +corresponding to a clock tick.

+
Return values
+ +

wait-until: func

+

Wait until the specified mark has occurred.

+
Params
+ +

wait-for: func

+

Wait for the specified duration to elapse.

+
Params
+ +

Import interface wasi:clocks/system-clock@0.3.1

+

WASI System Clock is a clock API intended to let users query the current +time. The clock is not necessarily monotonic as it may be reset.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

External references may be reset, so this clock is not necessarily +monotonic, making it unsuitable for measuring elapsed time.

+

It is intended for reporting the current date and time for humans.

+
+

Types

+

type duration

+

duration

+

+

record instant

+

An "instant", or "exact time", is a point in time without regard to any +time zone: just the time since a particular external reference point, +often called an "epoch".

+

Here, the epoch is 1970-01-01T00:00:00Z, also known as +POSIX's Seconds Since the Epoch, also known as Unix Time.

+

Note that even if the seconds field is negative, incrementing +nanoseconds always represents moving forwards in time. +For example, { -1 seconds, 999999999 nanoseconds } represents the +instant one nanosecond before the epoch. +For more on various different ways to represent time, see +https://tc39.es/proposal-temporal/docs/timezone.html

+
Record Fields
+ +
+

Functions

+

now: func

+

Read the current value of the clock.

+

This clock is not monotonic, therefore calling this function repeatedly +will not necessarily produce a sequence of non-decreasing values.

+

The nanoseconds field of the output is always less than 1000000000.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.

+
Return values
+ +

Import interface wasi:clocks/timezone@0.3.1

+
+

Types

+

type instant

+

instant

+

+


+

Functions

+

iana-id: func

+

Return the IANA identifier of the currently configured timezone. This +should be an identifier from the IANA Time Zone Database.

+

For displaying to a user, the identifier should be converted into a +localized name by means of an internationalization API.

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, or the timezone does +not have an IANA identifier, this returns nothing.

+
Return values
+ +

utc-offset: func

+

The number of nanoseconds difference between UTC time and the local +time of the currently configured timezone, at the exact time of +instant.

+

The magnitude of the returned value will always be less than +86,400,000,000,000 which is the number of nanoseconds in a day +(246060*1e9).

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, this returns +nothing.

+
Params
+ +
Return values
+ +

to-debug-string: func

+

Returns a string that is suitable to assist humans in debugging whether +any timezone is available, and if so, which. This may be the same string +as iana-id, or a formatted representation of the UTC offset such as +-04:00, or something else.

+

WARNING: The returned string should not be consumed mechanically! It may +change across platforms, hosts, or other implementation details. Parsing +this string is a major platform-compatibility hazard.

+
Return values
+ +

Import interface wasi:filesystem/types@0.3.1

+

WASI filesystem is a filesystem API primarily intended to let users run WASI +programs that access their files on their existing filesystems, without +significant overhead.

+

Paths are passed as interface-type strings, meaning they must consist of +a sequence of Unicode Scalar Values (USVs). Some filesystems may contain +paths which are not accessible by this API.

+

The directory separator in WASI is always the forward-slash (/).

+

All paths in WASI are relative paths, and are interpreted relative to a +descriptor referring to a base directory. If a path argument to any WASI +function starts with /, or if any step of resolving a path, including +.. and symbolic link steps, reaches a directory outside of the base +directory, or reaches a symlink to an absolute or rooted path in the +underlying filesystem, the function fails with error-code::not-permitted.

+

For more information about WASI path resolution and sandboxing, see +WASI filesystem path resolution.

+

Though this package presents a portable interface modelled on POSIX, it +prioritizes compatibility over portability: allowing users to access their +files on their machine is more important than exposing a single semantics +across all platforms. Notably, depending on the underlying operating system +and file system:

+ +

Users that need well-defined, portable semantics should use a key-value +store or a database instead.

+
+

Types

+

type instant

+

instant

+

+

type filesize

+

u64

+

File size or length of a region within a file. +

variant descriptor-type

+

The type of a filesystem object referenced by a descriptor.

+

Note: This was called filetype in earlier versions of WASI.

+
Variant Cases
+ +

flags descriptor-flags

+

Descriptor flags.

+

Note: This was called fdflags in earlier versions of WASI.

+
Flags members
+ +

flags path-flags

+

Flags determining the method of how paths are resolved.

+
Flags members
+ +

flags open-flags

+

Open flags used by open-at.

+
Flags members
+ +

type link-count

+

u64

+

Number of hard links to an inode. +

record descriptor-stat

+

File attributes.

+

Note: This was called filestat in earlier versions of WASI.

+
Record Fields
+ +

variant new-timestamp

+

When setting a timestamp, this gives the value to set it to.

+
Variant Cases
+ +

record directory-entry

+

A directory entry.

+
Record Fields
+ +

variant error-code

+

Error codes returned by functions, similar to errno in POSIX. +Not all of these error codes are returned by the functions provided by this +API; some are used in higher-level library layers, and others are provided +merely for alignment with POSIX.

+
Variant Cases
+ +

enum advice

+

File or memory access pattern advisory information.

+
Enum Cases
+ +

record metadata-hash-value

+

A 128-bit hash value, split into parts because wasm doesn't have a +128-bit integer type.

+
Record Fields
+ +

resource descriptor

+

A descriptor is a reference to a filesystem object, which may be a file, +directory, named pipe, special file, or other object on which filesystem +calls may be made.

+

Functions

+

[method]descriptor.read-via-stream: func

+

Return a stream for reading from a file.

+

Multiple read, write, and append streams may be active on the same open +file and they do not interfere with each other.

+

This function returns a stream which provides the data received from the +file, and a future providing additional error information in case an +error is encountered.

+

If no error is encountered, stream.read on the stream will return +read-status::closed with no error-context and the future resolves to +the value ok. If an error is encountered, stream.read on the +stream returns read-status::closed with an error-context and the future +resolves to err with an error-code.

+

Note: This is similar to pread in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.write-via-stream: func

+

Return a stream for writing to a file, if available.

+

May fail with an error-code describing why the file cannot be written.

+

It is valid to write past the end of a file; the file is extended to the +extent of the write, with bytes between the previous end and the start of +the write set to zero.

+

This function returns once either full contents of the stream are +written or an error is encountered.

+

Note: This is similar to pwrite in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.append-via-stream: func

+

Return a stream for appending to a file, if available.

+

May fail with an error-code describing why the file cannot be appended.

+

This function returns once either full contents of the stream are +written or an error is encountered.

+

Note: This is similar to write with O_APPEND in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.advise: func

+

Provide file advisory information on a descriptor.

+

This is similar to posix_fadvise in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.sync-data: func

+

Synchronize the data of a file to disk.

+

This function succeeds with no effect if the file descriptor is not +opened for writing.

+

Note: This is similar to fdatasync in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.get-flags: func

+

Get flags associated with a descriptor.

+

Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX.

+

Note: This returns the value that was the fs_flags value returned +from fdstat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.get-type: func

+

Get the dynamic type of a descriptor.

+

Note: This returns the same value as the type field of the fd-stat +returned by stat, stat-at and similar.

+

Note: This returns similar flags to the st_mode & S_IFMT value provided +by fstat in POSIX.

+

Note: This returns the value that was the fs_filetype value returned +from fdstat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-size: func

+

Adjust the size of an open file. If this increases the file's size, the +extra bytes are filled with zeros.

+

Note: This was called fd_filestat_set_size in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-times: func

+

Adjust the timestamps of an open file or directory.

+

Note: This is similar to futimens in POSIX.

+

Note: This was called fd_filestat_set_times in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.read-directory: func

+

Read directory entries from a directory.

+

On filesystems where directories contain entries referring to themselves +and their parents, often named . and .. respectively, these entries +are omitted.

+

This always returns a new stream which starts at the beginning of the +directory. Multiple streams may be active on the same directory, and they +do not interfere with each other.

+

This function returns a future, which will resolve to an error code if +reading full contents of the directory fails.

+
Params
+ +
Return values
+ +

[method]descriptor.sync: func

+

Synchronize the data and metadata of a file to disk.

+

This function succeeds with no effect if the file descriptor is not +opened for writing.

+

Note: This is similar to fsync in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.create-directory-at: func

+

Create a directory.

+

Note: This is similar to mkdirat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.stat: func

+

Return the attributes of an open file or directory.

+

Note: This is similar to fstat in POSIX, except that it does not return +device and inode information. For testing whether two descriptors refer to +the same underlying filesystem object, use is-same-object. To obtain +additional data that can be used do determine whether a file has been +modified, use metadata-hash.

+

Note: This was called fd_filestat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.stat-at: func

+

Return the attributes of a file or directory.

+

Note: This is similar to fstatat in POSIX, except that it does not +return device and inode information. See the stat description for a +discussion of alternatives.

+

Note: This was called path_filestat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-times-at: func

+

Adjust the timestamps of a file or directory.

+

Note: This is similar to utimensat in POSIX.

+

Note: This was called path_filestat_set_times in earlier versions of +WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.link-at: func

+

Create a hard link.

+

Fails with error-code::no-entry if the old path does not exist, +with error-code::exist if the new path already exists, and +error-code::not-permitted if the old path is not a file.

+

Note: This is similar to linkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.open-at: func

+

Open a file or directory.

+

If flags contains descriptor-flags::mutate-directory, and the base +descriptor doesn't have descriptor-flags::mutate-directory set, +open-at fails with error-code::read-only.

+

If flags contains write or mutate-directory, or open-flags +contains truncate or create, and the base descriptor doesn't have +descriptor-flags::mutate-directory set, open-at fails with +error-code::read-only.

+

Note: This is similar to openat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.readlink-at: func

+

Read the contents of a symbolic link.

+

If the contents contain an absolute or rooted path in the underlying +filesystem, this function fails with error-code::not-permitted.

+

Note: This is similar to readlinkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.remove-directory-at: func

+

Remove a directory.

+

Return error-code::not-empty if the directory is not empty.

+

Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.rename-at: func

+

Rename a filesystem object.

+

Note: This is similar to renameat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.symlink-at: func

+

Create a symbolic link (also known as a "symlink").

+

If old-path starts with /, the function fails with +error-code::not-permitted.

+

Note: This is similar to symlinkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.unlink-file-at: func

+

Unlink a filesystem object that is not a directory.

+

This is similar to unlinkat(fd, path, 0) in POSIX.

+

Error returns are as specified by POSIX.

+

If the filesystem object is a directory, error-code::access or +error-code::is-directory may be returned instead of the +POSIX-specified error-code::not-permitted.

+
Params
+ +
Return values
+ +

[method]descriptor.is-same-object: func

+

Test whether two descriptors refer to the same filesystem object.

+

In POSIX, this corresponds to testing whether the two descriptors have the +same device (st_dev) and inode (st_ino or d_ino) numbers. +wasi-filesystem does not expose device and inode numbers, so this function +may be used instead.

+
Params
+ +
Return values
+ +

[method]descriptor.metadata-hash: func

+

Return a hash of the metadata associated with a filesystem object referred +to by a descriptor.

+

This returns a hash of the last-modification timestamp and file size, and +may also include the inode number, device number, birth timestamp, and +other metadata fields that may change when the file is modified or +replaced. It may also include a secret value chosen by the +implementation and not otherwise exposed.

+

Implementations are encouraged to provide the following properties:

+ +

However, none of these is required.

+
Params
+ +
Return values
+ +

[method]descriptor.metadata-hash-at: func

+

Return a hash of the metadata associated with a filesystem object referred +to by a directory descriptor and a relative path.

+

This performs the same hash computation as metadata-hash.

+
Params
+ +
Return values
+ +

Import interface wasi:filesystem/preopens@0.3.1

+
+

Types

+

type descriptor

+

descriptor

+

+


+

Functions

+

get-directories: func

+

Return the set of preopened directories, and their paths.

+
Return values
+ +

Import interface wasi:sockets/types@0.3.1

+
+

Types

+

type duration

+

duration

+

+

variant error-code

+

Error codes.

+

In theory, every API can return any error code. +In practice, API's typically only return the errors documented per API +combined with a couple of errors that are always possible:

+ +

See each individual API for what the POSIX equivalents are. They sometimes differ per API.

+
Variant Cases
+ +

enum ip-address-family

+
Enum Cases
+ +

tuple ipv4-address

+
Tuple Fields
+ +

tuple ipv6-address

+
Tuple Fields
+ +

variant ip-address

+
Variant Cases
+ +

record ipv4-socket-address

+
Record Fields
+ +

record ipv6-socket-address

+
Record Fields
+ +

variant ip-socket-address

+
Variant Cases
+ +

resource tcp-socket

+

A TCP socket resource.

+

The socket can be in one of the following states:

+ +

Note: Except where explicitly mentioned, whenever this documentation uses +the term "bound" without backticks it actually means: in the bound state or higher. +(i.e. bound, listening, connecting or connected)

+

WASI uses shared ownership semantics: the tcp-socket handle and all +derived stream and future values reference a single underlying OS +socket:

+ +

The OS socket is closed only after the last handle is dropped. This +model has observable effects; for example, it affects when the local +port binding is released.

+

In addition to the general error codes documented on the +types::error-code type, TCP socket methods may always return +error(invalid-state) when in the closed state.

+

resource udp-socket

+

A UDP socket handle.

+

Functions

+

[static]tcp-socket.create: func

+

Create a new TCP socket.

+

Similar to socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP) +in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and +can't be configured otherwise.

+

Unlike POSIX, WASI sockets have no notion of a socket-level +O_NONBLOCK flag. Instead they fully rely on the Component Model's +async support.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.bind: func

+

Bind the socket to the provided IP address and port.

+

If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is +left to the implementation to decide which network interface(s) to +bind to. If the TCP/UDP port is zero, the socket will be bound to a +random free port.

+

Bind can be attempted multiple times on the same socket, even with +different arguments on each iteration. But never concurrently and +only as long as the previous bind failed. Once a bind succeeds, the +binding can't be changed anymore.

+

Typical errors

+ +

Implementors note

+

The bind operation shouldn't be affected by the TIME_WAIT state of a +recently closed socket on the same local address. In practice this +means that the SO_REUSEADDR socket option should be set implicitly +on all platforms, except on Windows where this is the default +behavior and SO_REUSEADDR performs something different.

+

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.connect: func

+

Connect to a remote endpoint.

+

On success, the socket is transitioned into the connected state +and the remote-address of the socket is updated. +The local-address may be updated as well, based on the best network +path to remote-address. If the socket was not already explicitly +bound, this function will implicitly bind the socket to a random +free port.

+

After a failed connection attempt, the socket will be in the closed +state and the only valid action left is to drop the socket. A single +socket can not be used to connect more than once.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.listen: func

+

Start listening and return a stream of new inbound connections.

+

Transitions the socket into the listening state. This can be called +at most once per socket.

+

If the socket is not already explicitly bound, this function will +implicitly bind the socket to a random free port.

+

Normally, the returned sockets are bound, in the connected state +and immediately ready for I/O. Though, depending on exact timing and +circumstances, a newly accepted connection may already be closed +by the time the server attempts to perform its first I/O on it. This +is true regardless of whether the WASI implementation uses +"synthesized" sockets or not (see Implementors Notes below).

+

The following properties are inherited from the listener socket:

+ +

Typical errors

+ +

Implementors note

+

This method returns a single perpetual stream that should only close +on fatal errors (if any). Yet, the POSIX' accept function may also +return transient errors (e.g. ECONNABORTED). The exact details differ +per operation system. For example, the Linux manual mentions:

+
+

Linux accept() passes already-pending network errors on the new +socket as an error code from accept(). This behavior differs from +other BSD socket implementations. For reliable operation the +application should detect the network errors defined for the +protocol after accept() and treat them like EAGAIN by retrying. +In the case of TCP/IP, these are ENETDOWN, EPROTO, ENOPROTOOPT, +EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH. +Source: https://man7.org/linux/man-pages/man2/accept.2.html

+
+

WASI implementations have two options to handle this:

+ +

In either case, the stream returned by this listen method remains +operational.

+

WASI requires listen to perform an implicit bind if the socket +has not already been bound. Not all platforms (notably Windows) +exhibit this behavior out of the box. On platforms that require it, +the WASI implementation can emulate this behavior by performing +the bind itself if the guest hasn't already done so.

+

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.send: func

+

Transmit data to peer.

+

The caller should close the stream when it has no more data to send +to the peer. Under normal circumstances this will cause a FIN packet +to be sent out. Closing the stream is equivalent to calling +shutdown(SHUT_WR) in POSIX.

+

This function may be called at most once and returns once the full +contents of the stream are transmitted or an error is encountered.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.receive: func

+

Read data from peer.

+

Returns a stream of data sent by the peer. The implementation +drops the stream once no more data is available. At that point, the +returned future resolves to:

+ +

receive may be called only once per socket. Subsequent calls return +a closed stream and a future resolved to err(invalid-state).

+

If the caller is not expecting to receive any more data from the peer, +they should drop the stream. Any data still in the receive queue +will be discarded. This is equivalent to calling shutdown(SHUT_RD) +in POSIX.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-local-address: func

+

Get the bound local address.

+

POSIX mentions:

+
+

If the socket has not been bound to a local name, the value +stored in the object pointed to by address is unspecified.

+
+

WASI is stricter and requires get-local-address to return +invalid-state when the socket hasn't been bound yet.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-remote-address: func

+

Get the remote address.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-is-listening: func

+

Whether the socket is in the listening state.

+

Equivalent to the SO_ACCEPTCONN socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-address-family: func

+

Whether this is a IPv4 or IPv6 socket.

+

This is the value passed to the constructor.

+

Equivalent to the SO_DOMAIN socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-listen-backlog-size: func

+

Hints the desired listen queue size. Implementations are free to +ignore this.

+

If the provided value is 0, an invalid-argument error is returned. +Any other value will never cause an error, but it might be silently +clamped and/or rounded.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-enabled: func

+

Enables or disables keepalive.

+

The keepalive behavior can be adjusted using:

+ +

Equivalent to the SO_KEEPALIVE socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-enabled: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-idle-time: func

+

Amount of time the connection has to be idle before TCP starts +sending keepalive packets.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-idle-time: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-interval: func

+

The time between keepalive packets.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPINTVL socket option.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-interval: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-count: func

+

The maximum amount of keepalive packets TCP should send before +aborting the connection.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPCNT socket option.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-count: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-hop-limit: func

+

Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.

+

If the provided value is 0, an invalid-argument error is returned.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-hop-limit: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-receive-buffer-size: func

+

Kernel buffer space reserved for sending/receiving on this socket. +Implementations usually treat this as a cap the buffer can grow to, +rather than allocating the full amount immediately.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

This is only a performance hint. The implementation may ignore it or +tweak it based on real traffic patterns. +Linux and macOS appear to behave differently depending on whether a +buffer size was explicitly set. When set, they tend to honor it; when +not set, they dynamically adjust the buffer size as the connection +progresses. This is especially noticeable when comparing the values +from before and after connection establishment.

+

Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-receive-buffer-size: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-send-buffer-size: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-send-buffer-size: func

+
Params
+ +
Return values
+ +

[static]udp-socket.create: func

+

Create a new UDP socket.

+

Similar to socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP) +in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and +can't be configured otherwise.

+

Unlike POSIX, WASI sockets have no notion of a socket-level +O_NONBLOCK flag. Instead they fully rely on the Component Model's +async support.

+

References:

+ +
Params
+ +
Return values
+ +

[method]udp-socket.bind: func

+

Bind the socket to the provided IP address and port.

+

If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is +left to the implementation to decide which network interface(s) to +bind to. If the port is zero, the socket will be bound to a random +free port.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.connect: func

+

Associate this socket with a specific peer address.

+

On success, the remote-address of the socket is updated. +The local-address may be updated as well, based on the best network +path to remote-address. If the socket was not already explicitly +bound, this function will implicitly bind the socket to a random +free port.

+

When a UDP socket is "connected", the send and receive methods +are limited to communicating with that peer only:

+ +

The name "connect" was kept to align with the existing POSIX +terminology. Other than that, this function only changes the local +socket configuration and does not generate any network traffic. +The peer is not aware of this "connection".

+

This method may be called multiple times on the same socket to change +its association, but only the most recent one will be effective.

+

Typical errors

+ +

Implementors note

+

If the socket is already connected, some platforms (e.g. Linux) +require a disconnect before connecting to a different peer address.

+

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.disconnect: func

+

Dissociate this socket from its peer address.

+

After calling this method, send & receive are free to communicate +with any remote address again.

+

The POSIX equivalent of this is calling connect with an AF_UNSPEC address.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.send: func

+

Send a message on the socket to a particular peer.

+

If the socket is connected, the peer address may be left empty. In +that case this is equivalent to send in POSIX. Otherwise it is +equivalent to sendto.

+

Additionally, if the socket is connected, a remote-address argument +may be provided but then it must be identical to the address +passed to connect.

+

If the socket has not been explicitly bound, it will be +implicitly bound to a random free port.

+

Implementations may trap if the data length exceeds 64 KiB.

+

Typical errors

+ +

Implementors note

+

WASI requires send to perform an implicit bind if the socket +has not been bound. Not all platforms (notably Windows) exhibit +this behavior natively. On such platforms, the WASI implementation +should emulate it by performing the bind if the guest has not +already done so.

+

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.receive: func

+

Receive a message on the socket.

+

On success, the return value contains a tuple of the received data +and the address of the sender. Theoretical maximum length of the +data is 64 KiB. Though in practice, it will typically be less than +1500 bytes.

+

If the socket is connected, the sender address is guaranteed to +match the remote address passed to connect.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-local-address: func

+

Get the current bound address.

+

POSIX mentions:

+
+

If the socket has not been bound to a local name, the value +stored in the object pointed to by address is unspecified.

+
+

WASI is stricter and requires get-local-address to return +invalid-state when the socket hasn't been bound yet.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-remote-address: func

+

Get the address the socket is currently "connected" to.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-address-family: func

+

Whether this is a IPv4 or IPv6 socket.

+

This is the value passed to the constructor.

+

Equivalent to the SO_DOMAIN socket option.

+
Params
+ +
Return values
+ +

[method]udp-socket.get-unicast-hop-limit: func

+

Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.

+

If the provided value is 0, an invalid-argument error is returned.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]udp-socket.set-unicast-hop-limit: func

+
Params
+ +
Return values
+ +

[method]udp-socket.get-receive-buffer-size: func

+

Kernel buffer space reserved for sending/receiving on this socket. +Implementations usually treat this as a cap the buffer can grow to, +rather than allocating the full amount immediately.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]udp-socket.set-receive-buffer-size: func

+
Params
+ +
Return values
+ +

[method]udp-socket.get-send-buffer-size: func

+
Params
+ +
Return values
+ +

[method]udp-socket.set-send-buffer-size: func

+
Params
+ +
Return values
+ +

Import interface wasi:sockets/ip-name-lookup@0.3.1

+
+

Types

+

type ip-address

+

ip-address

+

+

variant error-code

+

Lookup error codes.

+
Variant Cases
+ +
+

Functions

+

resolve-addresses: func

+

Resolve an internet host name to a list of IP addresses.

+

Unicode domain names are automatically converted to ASCII using IDNA +encoding. If the input is an IP address string, the address is parsed +and returned as-is without making any external requests.

+

See the wasi-socket proposal README.md for a comparison with getaddrinfo.

+

The results are returned in connection order preference.

+

This function never succeeds with 0 results. It either fails or succeeds +with at least one address. Additionally, this function never returns +IPv4-mapped IPv6 addresses.

+

References:

+ +
Params
+ +
Return values
+ +

Import interface wasi:random/random@0.3.1

+

WASI Random is a random data API.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-random-bytes: func

+

Return up to max-len cryptographically-secure random or pseudo-random +bytes.

+

This function must produce data at least as cryptographically secure and +fast as an adequately seeded cryptographically-secure pseudo-random +number generator (CSPRNG). It must not block, from the perspective of +the calling program, under any circumstances, including on the first +request and on requests for numbers of bytes. The returned data must +always be unpredictable.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+

This function must always return fresh data. Deterministic environments +must omit this function, rather than implementing it with deterministic +data.

+
Params
+ +
Return values
+ +

get-random-u64: func

+

Return a cryptographically-secure random or pseudo-random u64 value.

+

This function returns the same type of data as get-random-bytes, +represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure@0.3.1

+

The insecure interface for insecure pseudo-random numbers.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-random-bytes: func

+

Return up to max-len insecure pseudo-random bytes.

+

This function is not cryptographically secure. Do not use it for +anything related to security.

+

There are no requirements on the values of the returned bytes, however +implementations are encouraged to return evenly distributed values with +a long period.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+
Params
+ +
Return values
+ +

get-insecure-random-u64: func

+

Return an insecure pseudo-random u64 value.

+

This function returns the same type of pseudo-random data as +get-insecure-random-bytes, represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure-seed@0.3.1

+

The insecure-seed interface for seeding hash-map DoS resistance.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-seed: func

+

Return a 128-bit value that may contain a pseudo-random value.

+

The returned value is not required to be computed from a CSPRNG, and may +even be entirely deterministic. Host implementations are encouraged to +provide pseudo-random values to any program exposed to +attacker-controlled content, to enable DoS protection built into many +languages' hash-map implementations.

+

This function is intended to only be called once, by a source language +to initialize Denial Of Service (DoS) protection in its hash-map +implementation.

+

Expected future evolution

+

This will likely be changed to a value import, to prevent it from being +called multiple times and potentially used for purposes other than DoS +protection.

+
Return values
+ +

Export interface wasi:cli/run@0.3.1

+
+

Functions

+

run: func

+

Run the program.

+
Return values
+ diff --git a/proposals/cli/imports.md b/proposals/cli/imports.md new file mode 100644 index 00000000..9e51c24c --- /dev/null +++ b/proposals/cli/imports.md @@ -0,0 +1,2510 @@ +

World imports

+ +

Import interface wasi:cli/environment@0.3.1

+
+

Functions

+

get-environment: func

+

Get the POSIX-style environment variables.

+

Each environment variable is provided as a pair of string variable names +and string value.

+

Morally, these are a value import, but until value imports are available +in the component model, this import function should return the same +values each time it is called.

+
Return values
+ +

get-arguments: func

+

Get the POSIX-style arguments to the program.

+
Return values
+ +

get-initial-cwd: func

+

Return a path that programs should use as their initial current working +directory, interpreting . as shorthand for this.

+
Return values
+ +

Import interface wasi:cli/exit@0.3.1

+
+

Functions

+

exit: func

+

Exit the current instance and any linked instances.

+
Params
+ +

exit-with-code: func

+

Exit the current instance and any linked instances, reporting the +specified status code to the host.

+

The meaning of the code depends on the context, with 0 usually meaning +"success", and other values indicating various types of failure.

+

This function does not return; the effect is analogous to a trap, but +without the connotation that something bad has happened.

+
Params
+ +

Import interface wasi:cli/types@0.3.1

+
+

Types

+

enum error-code

+
Enum Cases
+ +

Import interface wasi:cli/stdin@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

read-via-stream: func

+

Return a stream for reading from stdin.

+

This function returns a stream which provides data read from stdin, +and a future to signal read results.

+

If the stream's readable end is dropped the future will resolve to success.

+

If the stream's writable end is dropped the future will either resolve to +success if stdin was closed by the writer or to an error-code if reading +failed for some other reason.

+

Multiple streams may be active at the same time. The behavior of concurrent +reads is implementation-specific.

+
Return values
+ +

Import interface wasi:cli/stdout@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stdout.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/stderr@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stderr.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/terminal-input@0.3.1

+

Terminal input.

+

In the future, this may include functions for disabling echoing, +disabling input buffering so that keyboard events are sent through +immediately, querying supported features, and so on.

+
+

Types

+

resource terminal-input

+

The input side of a terminal.

+

Import interface wasi:cli/terminal-output@0.3.1

+

Terminal output.

+

In the future, this may include functions for querying the terminal +size, being notified of terminal size changes, querying supported +features, and so on.

+
+

Types

+

resource terminal-output

+

The output side of a terminal.

+

Import interface wasi:cli/terminal-stdin@0.3.1

+

An interface providing an optional terminal-input for stdin as a +link-time authority.

+
+

Types

+

type terminal-input

+

terminal-input

+

+


+

Functions

+

get-terminal-stdin: func

+

If stdin is connected to a terminal, return a terminal-input handle +allowing further interaction with it.

+
Return values
+ +

Import interface wasi:cli/terminal-stdout@0.3.1

+

An interface providing an optional terminal-output for stdout as a +link-time authority.

+
+

Types

+

type terminal-output

+

terminal-output

+

+


+

Functions

+

get-terminal-stdout: func

+

If stdout is connected to a terminal, return a terminal-output handle +allowing further interaction with it.

+
Return values
+ +

Import interface wasi:cli/terminal-stderr@0.3.1

+

An interface providing an optional terminal-output for stderr as a +link-time authority.

+
+

Types

+

type terminal-output

+

terminal-output

+

+


+

Functions

+

get-terminal-stderr: func

+

If stderr is connected to a terminal, return a terminal-output handle +allowing further interaction with it.

+
Return values
+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:clocks/monotonic-clock@0.3.1

+

WASI Monotonic Clock is a clock API intended to let users measure elapsed +time.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

A monotonic clock is a clock which has an unspecified initial value, and +successive reads of the clock will produce non-decreasing values.

+
+

Types

+

type duration

+

duration

+

+

type mark

+

u64

+

A mark on a monotonic clock is a number of nanoseconds since an +unspecified initial value, and can only be compared to instances from +the same monotonic-clock. +


+

Functions

+

now: func

+

Read the current value of the clock.

+

The clock is monotonic, therefore calling this function repeatedly will +produce a sequence of non-decreasing values.

+

For completeness, this function traps if it's not possible to represent +the value of the clock in a mark. Consequently, implementations +should ensure that the starting time is low enough to avoid the +possibility of overflow in practice.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the duration of time +corresponding to a clock tick.

+
Return values
+ +

wait-until: func

+

Wait until the specified mark has occurred.

+
Params
+ +

wait-for: func

+

Wait for the specified duration to elapse.

+
Params
+ +

Import interface wasi:clocks/system-clock@0.3.1

+

WASI System Clock is a clock API intended to let users query the current +time. The clock is not necessarily monotonic as it may be reset.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

External references may be reset, so this clock is not necessarily +monotonic, making it unsuitable for measuring elapsed time.

+

It is intended for reporting the current date and time for humans.

+
+

Types

+

type duration

+

duration

+

+

record instant

+

An "instant", or "exact time", is a point in time without regard to any +time zone: just the time since a particular external reference point, +often called an "epoch".

+

Here, the epoch is 1970-01-01T00:00:00Z, also known as +POSIX's Seconds Since the Epoch, also known as Unix Time.

+

Note that even if the seconds field is negative, incrementing +nanoseconds always represents moving forwards in time. +For example, { -1 seconds, 999999999 nanoseconds } represents the +instant one nanosecond before the epoch. +For more on various different ways to represent time, see +https://tc39.es/proposal-temporal/docs/timezone.html

+
Record Fields
+ +
+

Functions

+

now: func

+

Read the current value of the clock.

+

This clock is not monotonic, therefore calling this function repeatedly +will not necessarily produce a sequence of non-decreasing values.

+

The nanoseconds field of the output is always less than 1000000000.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.

+
Return values
+ +

Import interface wasi:clocks/timezone@0.3.1

+
+

Types

+

type instant

+

instant

+

+


+

Functions

+

iana-id: func

+

Return the IANA identifier of the currently configured timezone. This +should be an identifier from the IANA Time Zone Database.

+

For displaying to a user, the identifier should be converted into a +localized name by means of an internationalization API.

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, or the timezone does +not have an IANA identifier, this returns nothing.

+
Return values
+ +

utc-offset: func

+

The number of nanoseconds difference between UTC time and the local +time of the currently configured timezone, at the exact time of +instant.

+

The magnitude of the returned value will always be less than +86,400,000,000,000 which is the number of nanoseconds in a day +(246060*1e9).

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, this returns +nothing.

+
Params
+ +
Return values
+ +

to-debug-string: func

+

Returns a string that is suitable to assist humans in debugging whether +any timezone is available, and if so, which. This may be the same string +as iana-id, or a formatted representation of the UTC offset such as +-04:00, or something else.

+

WARNING: The returned string should not be consumed mechanically! It may +change across platforms, hosts, or other implementation details. Parsing +this string is a major platform-compatibility hazard.

+
Return values
+ +

Import interface wasi:filesystem/types@0.3.1

+

WASI filesystem is a filesystem API primarily intended to let users run WASI +programs that access their files on their existing filesystems, without +significant overhead.

+

Paths are passed as interface-type strings, meaning they must consist of +a sequence of Unicode Scalar Values (USVs). Some filesystems may contain +paths which are not accessible by this API.

+

The directory separator in WASI is always the forward-slash (/).

+

All paths in WASI are relative paths, and are interpreted relative to a +descriptor referring to a base directory. If a path argument to any WASI +function starts with /, or if any step of resolving a path, including +.. and symbolic link steps, reaches a directory outside of the base +directory, or reaches a symlink to an absolute or rooted path in the +underlying filesystem, the function fails with error-code::not-permitted.

+

For more information about WASI path resolution and sandboxing, see +WASI filesystem path resolution.

+

Though this package presents a portable interface modelled on POSIX, it +prioritizes compatibility over portability: allowing users to access their +files on their machine is more important than exposing a single semantics +across all platforms. Notably, depending on the underlying operating system +and file system:

+ +

Users that need well-defined, portable semantics should use a key-value +store or a database instead.

+
+

Types

+

type instant

+

instant

+

+

type filesize

+

u64

+

File size or length of a region within a file. +

variant descriptor-type

+

The type of a filesystem object referenced by a descriptor.

+

Note: This was called filetype in earlier versions of WASI.

+
Variant Cases
+ +

flags descriptor-flags

+

Descriptor flags.

+

Note: This was called fdflags in earlier versions of WASI.

+
Flags members
+ +

flags path-flags

+

Flags determining the method of how paths are resolved.

+
Flags members
+ +

flags open-flags

+

Open flags used by open-at.

+
Flags members
+ +

type link-count

+

u64

+

Number of hard links to an inode. +

record descriptor-stat

+

File attributes.

+

Note: This was called filestat in earlier versions of WASI.

+
Record Fields
+ +

variant new-timestamp

+

When setting a timestamp, this gives the value to set it to.

+
Variant Cases
+ +

record directory-entry

+

A directory entry.

+
Record Fields
+ +

variant error-code

+

Error codes returned by functions, similar to errno in POSIX. +Not all of these error codes are returned by the functions provided by this +API; some are used in higher-level library layers, and others are provided +merely for alignment with POSIX.

+
Variant Cases
+ +

enum advice

+

File or memory access pattern advisory information.

+
Enum Cases
+ +

record metadata-hash-value

+

A 128-bit hash value, split into parts because wasm doesn't have a +128-bit integer type.

+
Record Fields
+ +

resource descriptor

+

A descriptor is a reference to a filesystem object, which may be a file, +directory, named pipe, special file, or other object on which filesystem +calls may be made.

+

Functions

+

[method]descriptor.read-via-stream: func

+

Return a stream for reading from a file.

+

Multiple read, write, and append streams may be active on the same open +file and they do not interfere with each other.

+

This function returns a stream which provides the data received from the +file, and a future providing additional error information in case an +error is encountered.

+

If no error is encountered, stream.read on the stream will return +read-status::closed with no error-context and the future resolves to +the value ok. If an error is encountered, stream.read on the +stream returns read-status::closed with an error-context and the future +resolves to err with an error-code.

+

Note: This is similar to pread in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.write-via-stream: func

+

Return a stream for writing to a file, if available.

+

May fail with an error-code describing why the file cannot be written.

+

It is valid to write past the end of a file; the file is extended to the +extent of the write, with bytes between the previous end and the start of +the write set to zero.

+

This function returns once either full contents of the stream are +written or an error is encountered.

+

Note: This is similar to pwrite in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.append-via-stream: func

+

Return a stream for appending to a file, if available.

+

May fail with an error-code describing why the file cannot be appended.

+

This function returns once either full contents of the stream are +written or an error is encountered.

+

Note: This is similar to write with O_APPEND in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.advise: func

+

Provide file advisory information on a descriptor.

+

This is similar to posix_fadvise in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.sync-data: func

+

Synchronize the data of a file to disk.

+

This function succeeds with no effect if the file descriptor is not +opened for writing.

+

Note: This is similar to fdatasync in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.get-flags: func

+

Get flags associated with a descriptor.

+

Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX.

+

Note: This returns the value that was the fs_flags value returned +from fdstat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.get-type: func

+

Get the dynamic type of a descriptor.

+

Note: This returns the same value as the type field of the fd-stat +returned by stat, stat-at and similar.

+

Note: This returns similar flags to the st_mode & S_IFMT value provided +by fstat in POSIX.

+

Note: This returns the value that was the fs_filetype value returned +from fdstat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-size: func

+

Adjust the size of an open file. If this increases the file's size, the +extra bytes are filled with zeros.

+

Note: This was called fd_filestat_set_size in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-times: func

+

Adjust the timestamps of an open file or directory.

+

Note: This is similar to futimens in POSIX.

+

Note: This was called fd_filestat_set_times in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.read-directory: func

+

Read directory entries from a directory.

+

On filesystems where directories contain entries referring to themselves +and their parents, often named . and .. respectively, these entries +are omitted.

+

This always returns a new stream which starts at the beginning of the +directory. Multiple streams may be active on the same directory, and they +do not interfere with each other.

+

This function returns a future, which will resolve to an error code if +reading full contents of the directory fails.

+
Params
+ +
Return values
+ +

[method]descriptor.sync: func

+

Synchronize the data and metadata of a file to disk.

+

This function succeeds with no effect if the file descriptor is not +opened for writing.

+

Note: This is similar to fsync in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.create-directory-at: func

+

Create a directory.

+

Note: This is similar to mkdirat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.stat: func

+

Return the attributes of an open file or directory.

+

Note: This is similar to fstat in POSIX, except that it does not return +device and inode information. For testing whether two descriptors refer to +the same underlying filesystem object, use is-same-object. To obtain +additional data that can be used do determine whether a file has been +modified, use metadata-hash.

+

Note: This was called fd_filestat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.stat-at: func

+

Return the attributes of a file or directory.

+

Note: This is similar to fstatat in POSIX, except that it does not +return device and inode information. See the stat description for a +discussion of alternatives.

+

Note: This was called path_filestat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-times-at: func

+

Adjust the timestamps of a file or directory.

+

Note: This is similar to utimensat in POSIX.

+

Note: This was called path_filestat_set_times in earlier versions of +WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.link-at: func

+

Create a hard link.

+

Fails with error-code::no-entry if the old path does not exist, +with error-code::exist if the new path already exists, and +error-code::not-permitted if the old path is not a file.

+

Note: This is similar to linkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.open-at: func

+

Open a file or directory.

+

If flags contains descriptor-flags::mutate-directory, and the base +descriptor doesn't have descriptor-flags::mutate-directory set, +open-at fails with error-code::read-only.

+

If flags contains write or mutate-directory, or open-flags +contains truncate or create, and the base descriptor doesn't have +descriptor-flags::mutate-directory set, open-at fails with +error-code::read-only.

+

Note: This is similar to openat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.readlink-at: func

+

Read the contents of a symbolic link.

+

If the contents contain an absolute or rooted path in the underlying +filesystem, this function fails with error-code::not-permitted.

+

Note: This is similar to readlinkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.remove-directory-at: func

+

Remove a directory.

+

Return error-code::not-empty if the directory is not empty.

+

Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.rename-at: func

+

Rename a filesystem object.

+

Note: This is similar to renameat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.symlink-at: func

+

Create a symbolic link (also known as a "symlink").

+

If old-path starts with /, the function fails with +error-code::not-permitted.

+

Note: This is similar to symlinkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.unlink-file-at: func

+

Unlink a filesystem object that is not a directory.

+

This is similar to unlinkat(fd, path, 0) in POSIX.

+

Error returns are as specified by POSIX.

+

If the filesystem object is a directory, error-code::access or +error-code::is-directory may be returned instead of the +POSIX-specified error-code::not-permitted.

+
Params
+ +
Return values
+ +

[method]descriptor.is-same-object: func

+

Test whether two descriptors refer to the same filesystem object.

+

In POSIX, this corresponds to testing whether the two descriptors have the +same device (st_dev) and inode (st_ino or d_ino) numbers. +wasi-filesystem does not expose device and inode numbers, so this function +may be used instead.

+
Params
+ +
Return values
+ +

[method]descriptor.metadata-hash: func

+

Return a hash of the metadata associated with a filesystem object referred +to by a descriptor.

+

This returns a hash of the last-modification timestamp and file size, and +may also include the inode number, device number, birth timestamp, and +other metadata fields that may change when the file is modified or +replaced. It may also include a secret value chosen by the +implementation and not otherwise exposed.

+

Implementations are encouraged to provide the following properties:

+ +

However, none of these is required.

+
Params
+ +
Return values
+ +

[method]descriptor.metadata-hash-at: func

+

Return a hash of the metadata associated with a filesystem object referred +to by a directory descriptor and a relative path.

+

This performs the same hash computation as metadata-hash.

+
Params
+ +
Return values
+ +

Import interface wasi:filesystem/preopens@0.3.1

+
+

Types

+

type descriptor

+

descriptor

+

+


+

Functions

+

get-directories: func

+

Return the set of preopened directories, and their paths.

+
Return values
+ +

Import interface wasi:sockets/types@0.3.1

+
+

Types

+

type duration

+

duration

+

+

variant error-code

+

Error codes.

+

In theory, every API can return any error code. +In practice, API's typically only return the errors documented per API +combined with a couple of errors that are always possible:

+ +

See each individual API for what the POSIX equivalents are. They sometimes differ per API.

+
Variant Cases
+ +

enum ip-address-family

+
Enum Cases
+ +

tuple ipv4-address

+
Tuple Fields
+ +

tuple ipv6-address

+
Tuple Fields
+ +

variant ip-address

+
Variant Cases
+ +

record ipv4-socket-address

+
Record Fields
+ +

record ipv6-socket-address

+
Record Fields
+ +

variant ip-socket-address

+
Variant Cases
+ +

resource tcp-socket

+

A TCP socket resource.

+

The socket can be in one of the following states:

+ +

Note: Except where explicitly mentioned, whenever this documentation uses +the term "bound" without backticks it actually means: in the bound state or higher. +(i.e. bound, listening, connecting or connected)

+

WASI uses shared ownership semantics: the tcp-socket handle and all +derived stream and future values reference a single underlying OS +socket:

+ +

The OS socket is closed only after the last handle is dropped. This +model has observable effects; for example, it affects when the local +port binding is released.

+

In addition to the general error codes documented on the +types::error-code type, TCP socket methods may always return +error(invalid-state) when in the closed state.

+

resource udp-socket

+

A UDP socket handle.

+

Functions

+

[static]tcp-socket.create: func

+

Create a new TCP socket.

+

Similar to socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP) +in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and +can't be configured otherwise.

+

Unlike POSIX, WASI sockets have no notion of a socket-level +O_NONBLOCK flag. Instead they fully rely on the Component Model's +async support.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.bind: func

+

Bind the socket to the provided IP address and port.

+

If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is +left to the implementation to decide which network interface(s) to +bind to. If the TCP/UDP port is zero, the socket will be bound to a +random free port.

+

Bind can be attempted multiple times on the same socket, even with +different arguments on each iteration. But never concurrently and +only as long as the previous bind failed. Once a bind succeeds, the +binding can't be changed anymore.

+

Typical errors

+ +

Implementors note

+

The bind operation shouldn't be affected by the TIME_WAIT state of a +recently closed socket on the same local address. In practice this +means that the SO_REUSEADDR socket option should be set implicitly +on all platforms, except on Windows where this is the default +behavior and SO_REUSEADDR performs something different.

+

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.connect: func

+

Connect to a remote endpoint.

+

On success, the socket is transitioned into the connected state +and the remote-address of the socket is updated. +The local-address may be updated as well, based on the best network +path to remote-address. If the socket was not already explicitly +bound, this function will implicitly bind the socket to a random +free port.

+

After a failed connection attempt, the socket will be in the closed +state and the only valid action left is to drop the socket. A single +socket can not be used to connect more than once.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.listen: func

+

Start listening and return a stream of new inbound connections.

+

Transitions the socket into the listening state. This can be called +at most once per socket.

+

If the socket is not already explicitly bound, this function will +implicitly bind the socket to a random free port.

+

Normally, the returned sockets are bound, in the connected state +and immediately ready for I/O. Though, depending on exact timing and +circumstances, a newly accepted connection may already be closed +by the time the server attempts to perform its first I/O on it. This +is true regardless of whether the WASI implementation uses +"synthesized" sockets or not (see Implementors Notes below).

+

The following properties are inherited from the listener socket:

+ +

Typical errors

+ +

Implementors note

+

This method returns a single perpetual stream that should only close +on fatal errors (if any). Yet, the POSIX' accept function may also +return transient errors (e.g. ECONNABORTED). The exact details differ +per operation system. For example, the Linux manual mentions:

+
+

Linux accept() passes already-pending network errors on the new +socket as an error code from accept(). This behavior differs from +other BSD socket implementations. For reliable operation the +application should detect the network errors defined for the +protocol after accept() and treat them like EAGAIN by retrying. +In the case of TCP/IP, these are ENETDOWN, EPROTO, ENOPROTOOPT, +EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH. +Source: https://man7.org/linux/man-pages/man2/accept.2.html

+
+

WASI implementations have two options to handle this:

+ +

In either case, the stream returned by this listen method remains +operational.

+

WASI requires listen to perform an implicit bind if the socket +has not already been bound. Not all platforms (notably Windows) +exhibit this behavior out of the box. On platforms that require it, +the WASI implementation can emulate this behavior by performing +the bind itself if the guest hasn't already done so.

+

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.send: func

+

Transmit data to peer.

+

The caller should close the stream when it has no more data to send +to the peer. Under normal circumstances this will cause a FIN packet +to be sent out. Closing the stream is equivalent to calling +shutdown(SHUT_WR) in POSIX.

+

This function may be called at most once and returns once the full +contents of the stream are transmitted or an error is encountered.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.receive: func

+

Read data from peer.

+

Returns a stream of data sent by the peer. The implementation +drops the stream once no more data is available. At that point, the +returned future resolves to:

+ +

receive may be called only once per socket. Subsequent calls return +a closed stream and a future resolved to err(invalid-state).

+

If the caller is not expecting to receive any more data from the peer, +they should drop the stream. Any data still in the receive queue +will be discarded. This is equivalent to calling shutdown(SHUT_RD) +in POSIX.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-local-address: func

+

Get the bound local address.

+

POSIX mentions:

+
+

If the socket has not been bound to a local name, the value +stored in the object pointed to by address is unspecified.

+
+

WASI is stricter and requires get-local-address to return +invalid-state when the socket hasn't been bound yet.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-remote-address: func

+

Get the remote address.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-is-listening: func

+

Whether the socket is in the listening state.

+

Equivalent to the SO_ACCEPTCONN socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-address-family: func

+

Whether this is a IPv4 or IPv6 socket.

+

This is the value passed to the constructor.

+

Equivalent to the SO_DOMAIN socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-listen-backlog-size: func

+

Hints the desired listen queue size. Implementations are free to +ignore this.

+

If the provided value is 0, an invalid-argument error is returned. +Any other value will never cause an error, but it might be silently +clamped and/or rounded.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-enabled: func

+

Enables or disables keepalive.

+

The keepalive behavior can be adjusted using:

+ +

Equivalent to the SO_KEEPALIVE socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-enabled: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-idle-time: func

+

Amount of time the connection has to be idle before TCP starts +sending keepalive packets.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-idle-time: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-interval: func

+

The time between keepalive packets.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPINTVL socket option.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-interval: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-count: func

+

The maximum amount of keepalive packets TCP should send before +aborting the connection.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPCNT socket option.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-count: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-hop-limit: func

+

Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.

+

If the provided value is 0, an invalid-argument error is returned.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-hop-limit: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-receive-buffer-size: func

+

Kernel buffer space reserved for sending/receiving on this socket. +Implementations usually treat this as a cap the buffer can grow to, +rather than allocating the full amount immediately.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

This is only a performance hint. The implementation may ignore it or +tweak it based on real traffic patterns. +Linux and macOS appear to behave differently depending on whether a +buffer size was explicitly set. When set, they tend to honor it; when +not set, they dynamically adjust the buffer size as the connection +progresses. This is especially noticeable when comparing the values +from before and after connection establishment.

+

Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-receive-buffer-size: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-send-buffer-size: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-send-buffer-size: func

+
Params
+ +
Return values
+ +

[static]udp-socket.create: func

+

Create a new UDP socket.

+

Similar to socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP) +in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and +can't be configured otherwise.

+

Unlike POSIX, WASI sockets have no notion of a socket-level +O_NONBLOCK flag. Instead they fully rely on the Component Model's +async support.

+

References:

+ +
Params
+ +
Return values
+ +

[method]udp-socket.bind: func

+

Bind the socket to the provided IP address and port.

+

If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is +left to the implementation to decide which network interface(s) to +bind to. If the port is zero, the socket will be bound to a random +free port.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.connect: func

+

Associate this socket with a specific peer address.

+

On success, the remote-address of the socket is updated. +The local-address may be updated as well, based on the best network +path to remote-address. If the socket was not already explicitly +bound, this function will implicitly bind the socket to a random +free port.

+

When a UDP socket is "connected", the send and receive methods +are limited to communicating with that peer only:

+ +

The name "connect" was kept to align with the existing POSIX +terminology. Other than that, this function only changes the local +socket configuration and does not generate any network traffic. +The peer is not aware of this "connection".

+

This method may be called multiple times on the same socket to change +its association, but only the most recent one will be effective.

+

Typical errors

+ +

Implementors note

+

If the socket is already connected, some platforms (e.g. Linux) +require a disconnect before connecting to a different peer address.

+

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.disconnect: func

+

Dissociate this socket from its peer address.

+

After calling this method, send & receive are free to communicate +with any remote address again.

+

The POSIX equivalent of this is calling connect with an AF_UNSPEC address.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.send: func

+

Send a message on the socket to a particular peer.

+

If the socket is connected, the peer address may be left empty. In +that case this is equivalent to send in POSIX. Otherwise it is +equivalent to sendto.

+

Additionally, if the socket is connected, a remote-address argument +may be provided but then it must be identical to the address +passed to connect.

+

If the socket has not been explicitly bound, it will be +implicitly bound to a random free port.

+

Implementations may trap if the data length exceeds 64 KiB.

+

Typical errors

+ +

Implementors note

+

WASI requires send to perform an implicit bind if the socket +has not been bound. Not all platforms (notably Windows) exhibit +this behavior natively. On such platforms, the WASI implementation +should emulate it by performing the bind if the guest has not +already done so.

+

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.receive: func

+

Receive a message on the socket.

+

On success, the return value contains a tuple of the received data +and the address of the sender. Theoretical maximum length of the +data is 64 KiB. Though in practice, it will typically be less than +1500 bytes.

+

If the socket is connected, the sender address is guaranteed to +match the remote address passed to connect.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-local-address: func

+

Get the current bound address.

+

POSIX mentions:

+
+

If the socket has not been bound to a local name, the value +stored in the object pointed to by address is unspecified.

+
+

WASI is stricter and requires get-local-address to return +invalid-state when the socket hasn't been bound yet.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-remote-address: func

+

Get the address the socket is currently "connected" to.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-address-family: func

+

Whether this is a IPv4 or IPv6 socket.

+

This is the value passed to the constructor.

+

Equivalent to the SO_DOMAIN socket option.

+
Params
+ +
Return values
+ +

[method]udp-socket.get-unicast-hop-limit: func

+

Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.

+

If the provided value is 0, an invalid-argument error is returned.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]udp-socket.set-unicast-hop-limit: func

+
Params
+ +
Return values
+ +

[method]udp-socket.get-receive-buffer-size: func

+

Kernel buffer space reserved for sending/receiving on this socket. +Implementations usually treat this as a cap the buffer can grow to, +rather than allocating the full amount immediately.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]udp-socket.set-receive-buffer-size: func

+
Params
+ +
Return values
+ +

[method]udp-socket.get-send-buffer-size: func

+
Params
+ +
Return values
+ +

[method]udp-socket.set-send-buffer-size: func

+
Params
+ +
Return values
+ +

Import interface wasi:sockets/ip-name-lookup@0.3.1

+
+

Types

+

type ip-address

+

ip-address

+

+

variant error-code

+

Lookup error codes.

+
Variant Cases
+ +
+

Functions

+

resolve-addresses: func

+

Resolve an internet host name to a list of IP addresses.

+

Unicode domain names are automatically converted to ASCII using IDNA +encoding. If the input is an IP address string, the address is parsed +and returned as-is without making any external requests.

+

See the wasi-socket proposal README.md for a comparison with getaddrinfo.

+

The results are returned in connection order preference.

+

This function never succeeds with 0 results. It either fails or succeeds +with at least one address. Additionally, this function never returns +IPv4-mapped IPv6 addresses.

+

References:

+ +
Params
+ +
Return values
+ +

Import interface wasi:random/random@0.3.1

+

WASI Random is a random data API.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-random-bytes: func

+

Return up to max-len cryptographically-secure random or pseudo-random +bytes.

+

This function must produce data at least as cryptographically secure and +fast as an adequately seeded cryptographically-secure pseudo-random +number generator (CSPRNG). It must not block, from the perspective of +the calling program, under any circumstances, including on the first +request and on requests for numbers of bytes. The returned data must +always be unpredictable.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+

This function must always return fresh data. Deterministic environments +must omit this function, rather than implementing it with deterministic +data.

+
Params
+ +
Return values
+ +

get-random-u64: func

+

Return a cryptographically-secure random or pseudo-random u64 value.

+

This function returns the same type of data as get-random-bytes, +represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure@0.3.1

+

The insecure interface for insecure pseudo-random numbers.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-random-bytes: func

+

Return up to max-len insecure pseudo-random bytes.

+

This function is not cryptographically secure. Do not use it for +anything related to security.

+

There are no requirements on the values of the returned bytes, however +implementations are encouraged to return evenly distributed values with +a long period.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+
Params
+ +
Return values
+ +

get-insecure-random-u64: func

+

Return an insecure pseudo-random u64 value.

+

This function returns the same type of pseudo-random data as +get-insecure-random-bytes, represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure-seed@0.3.1

+

The insecure-seed interface for seeding hash-map DoS resistance.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-seed: func

+

Return a 128-bit value that may contain a pseudo-random value.

+

The returned value is not required to be computed from a CSPRNG, and may +even be entirely deterministic. Host implementations are encouraged to +provide pseudo-random values to any program exposed to +attacker-controlled content, to enable DoS protection built into many +languages' hash-map implementations.

+

This function is intended to only be called once, by a source language +to initialize Denial Of Service (DoS) protection in its hash-map +implementation.

+

Expected future evolution

+

This will likely be changed to a value import, to prevent it from being +called multiple times and potentially used for purposes other than DoS +protection.

+
Return values
+ diff --git a/proposals/cli/wit/command.wit b/proposals/cli/wit/command.wit index 0310e515..10a13c60 100644 --- a/proposals/cli/wit/command.wit +++ b/proposals/cli/wit/command.wit @@ -1,4 +1,4 @@ -package wasi:cli@0.3.0; +package wasi:cli@0.3.1; @since(version = 0.3.0) world command { diff --git a/proposals/cli/wit/deps.lock b/proposals/cli/wit/deps.lock index 705b4f27..7d0d89d7 100644 --- a/proposals/cli/wit/deps.lock +++ b/proposals/cli/wit/deps.lock @@ -1,19 +1,19 @@ [clocks] path = "../../clocks/wit" -sha256 = "2d288cb781c60ae462537b39e4699de38f88072b501fc7f97d3f20984d550bcf" -sha512 = "1563eeeacbfea89e44f668b8588ef95b31feac7d9ec3bb5dad932320478b1aff1448031f44afa15ed926981855ac5bd504126389ddb7802f79c63b81b3c5ede7" +sha256 = "cee7f7ffff62be2416295a0bbdc13d822f5b4449ce37e0eb7cbdf3195156429d" +sha512 = "446835d225349f00f44b8c47fb3e6189491cfc19fdf3b394e3edd85276e3f1d7a515efb318cd11ef271c164ec54a54307110f2d0b72212a0108324f449d9b946" [filesystem] path = "../../filesystem/wit" -sha256 = "2c804c867e34eabd75171119f062a49a1b9758d1ec1956535e467b7353e61dd3" -sha512 = "db25d5306dc671c7a7db6a273318d056d6e544567636b3759db48ab4e81a06bc5c1fc3aa2d1522d4187a116730b1a8ecc57a4f974925fda6deaaf06d237da6df" +sha256 = "7e29e1b85da02279d2853dff263bbfe647b1b19105b96bb2a850ea8d201e7bbb" +sha512 = "7cdba2ef1090aa6b83eb292dd90992df2a9db24f577728b9275e0c3eb4fe19bcb8f0e7defa914d79e7adee72029d8c9501b2cc6387723b515d0ff296c3c1acff" [random] path = "../../random/wit" -sha256 = "607700294fdbd7de5c4771628db8830b05ae53c48e66c7645feae98f298a5feb" -sha512 = "a059c887a04b2927df93b8eb83e0843d9ab804e31dee060bf83b74fa6fdd24fbafbb7f9cfcbfa7838cbf6c7e684de8fd4c0b338f3006db1077dd338bf01445ce" +sha256 = "5196da126852cb29c39790da453ec6d5f46a266283dadd69a5f93f10a9850376" +sha512 = "4147e0f33b26cd6bf46cc1da4afed21e620fe8ede4b06199c8826fd456ed4977974ac1b6437dccdfb602f1b352d06a455717852f43ae5143fffc01e75ca3d74d" [sockets] path = "../../sockets/wit" -sha256 = "663af53b8a4e6aa66fa24618c5d0d6dd4bfaa970121a85951e8ab52cea0b0852" -sha512 = "4faf0eb9e8f486d3dadddc7f491f87ca6b1626f0296e8e918c529f39696f61398e4c37d0dfa6529a157f65747bbd455487fe0b6bb04e075d65a8d75844225e2a" +sha256 = "8db169a251f64d3b06162f2012a3b0b794a2e65187b130fc21adf5c913ddb140" +sha512 = "6d2a2a4b0b575a3856eb1d0448b4637357587123d12d4633b1e8bded88530085a1f36bfcfda6a2e27ce633581d7e3b778c2658f796b884972d3d2043ae7b5795" diff --git a/proposals/cli/wit/imports.wit b/proposals/cli/wit/imports.wit index 5dbc2ede..488604f4 100644 --- a/proposals/cli/wit/imports.wit +++ b/proposals/cli/wit/imports.wit @@ -1,15 +1,15 @@ -package wasi:cli@0.3.0; +package wasi:cli@0.3.1; @since(version = 0.3.0) world imports { @since(version = 0.3.0) - include wasi:clocks/imports@0.3.0; + include wasi:clocks/imports@0.3.1; @since(version = 0.3.0) - include wasi:filesystem/imports@0.3.0; + include wasi:filesystem/imports@0.3.1; @since(version = 0.3.0) - include wasi:sockets/imports@0.3.0; + include wasi:sockets/imports@0.3.1; @since(version = 0.3.0) - include wasi:random/imports@0.3.0; + include wasi:random/imports@0.3.1; @since(version = 0.3.0) import environment; diff --git a/proposals/clocks/imports.md b/proposals/clocks/imports.md new file mode 100644 index 00000000..b3f30638 --- /dev/null +++ b/proposals/clocks/imports.md @@ -0,0 +1,168 @@ +

World imports

+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:clocks/monotonic-clock@0.3.1

+

WASI Monotonic Clock is a clock API intended to let users measure elapsed +time.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

A monotonic clock is a clock which has an unspecified initial value, and +successive reads of the clock will produce non-decreasing values.

+
+

Types

+

type duration

+

duration

+

+

type mark

+

u64

+

A mark on a monotonic clock is a number of nanoseconds since an +unspecified initial value, and can only be compared to instances from +the same monotonic-clock. +


+

Functions

+

now: func

+

Read the current value of the clock.

+

The clock is monotonic, therefore calling this function repeatedly will +produce a sequence of non-decreasing values.

+

For completeness, this function traps if it's not possible to represent +the value of the clock in a mark. Consequently, implementations +should ensure that the starting time is low enough to avoid the +possibility of overflow in practice.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the duration of time +corresponding to a clock tick.

+
Return values
+ +

wait-until: func

+

Wait until the specified mark has occurred.

+
Params
+ +

wait-for: func

+

Wait for the specified duration to elapse.

+
Params
+ +

Import interface wasi:clocks/system-clock@0.3.1

+

WASI System Clock is a clock API intended to let users query the current +time. The clock is not necessarily monotonic as it may be reset.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

External references may be reset, so this clock is not necessarily +monotonic, making it unsuitable for measuring elapsed time.

+

It is intended for reporting the current date and time for humans.

+
+

Types

+

type duration

+

duration

+

+

record instant

+

An "instant", or "exact time", is a point in time without regard to any +time zone: just the time since a particular external reference point, +often called an "epoch".

+

Here, the epoch is 1970-01-01T00:00:00Z, also known as +POSIX's Seconds Since the Epoch, also known as Unix Time.

+

Note that even if the seconds field is negative, incrementing +nanoseconds always represents moving forwards in time. +For example, { -1 seconds, 999999999 nanoseconds } represents the +instant one nanosecond before the epoch. +For more on various different ways to represent time, see +https://tc39.es/proposal-temporal/docs/timezone.html

+
Record Fields
+ +
+

Functions

+

now: func

+

Read the current value of the clock.

+

This clock is not monotonic, therefore calling this function repeatedly +will not necessarily produce a sequence of non-decreasing values.

+

The nanoseconds field of the output is always less than 1000000000.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.

+
Return values
+ +

Import interface wasi:clocks/timezone@0.3.1

+
+

Types

+

type instant

+

instant

+

+


+

Functions

+

iana-id: func

+

Return the IANA identifier of the currently configured timezone. This +should be an identifier from the IANA Time Zone Database.

+

For displaying to a user, the identifier should be converted into a +localized name by means of an internationalization API.

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, or the timezone does +not have an IANA identifier, this returns nothing.

+
Return values
+ +

utc-offset: func

+

The number of nanoseconds difference between UTC time and the local +time of the currently configured timezone, at the exact time of +instant.

+

The magnitude of the returned value will always be less than +86,400,000,000,000 which is the number of nanoseconds in a day +(246060*1e9).

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, this returns +nothing.

+
Params
+ +
Return values
+ +

to-debug-string: func

+

Returns a string that is suitable to assist humans in debugging whether +any timezone is available, and if so, which. This may be the same string +as iana-id, or a formatted representation of the UTC offset such as +-04:00, or something else.

+

WARNING: The returned string should not be consumed mechanically! It may +change across platforms, hosts, or other implementation details. Parsing +this string is a major platform-compatibility hazard.

+
Return values
+ diff --git a/proposals/clocks/wit/monotonic-clock.wit b/proposals/clocks/wit/monotonic-clock.wit index a750a5cd..537177a4 100644 --- a/proposals/clocks/wit/monotonic-clock.wit +++ b/proposals/clocks/wit/monotonic-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.3.0; +package wasi:clocks@0.3.1; /// WASI Monotonic Clock is a clock API intended to let users measure elapsed /// time. /// diff --git a/proposals/clocks/wit/system-clock.wit b/proposals/clocks/wit/system-clock.wit index 92dfc051..119c3e17 100644 --- a/proposals/clocks/wit/system-clock.wit +++ b/proposals/clocks/wit/system-clock.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.3.0; +package wasi:clocks@0.3.1; /// WASI System Clock is a clock API intended to let users query the current /// time. The clock is not necessarily monotonic as it may be reset. /// diff --git a/proposals/clocks/wit/timezone.wit b/proposals/clocks/wit/timezone.wit index e0b84ec5..2a443659 100644 --- a/proposals/clocks/wit/timezone.wit +++ b/proposals/clocks/wit/timezone.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.3.0; +package wasi:clocks@0.3.1; @unstable(feature = clocks-timezone) interface timezone { diff --git a/proposals/clocks/wit/types.wit b/proposals/clocks/wit/types.wit index e82be54d..027133e4 100644 --- a/proposals/clocks/wit/types.wit +++ b/proposals/clocks/wit/types.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.3.0; +package wasi:clocks@0.3.1; /// This interface common types used throughout wasi:clocks. @since(version = 0.3.0) interface types { diff --git a/proposals/clocks/wit/world.wit b/proposals/clocks/wit/world.wit index c68c4ae3..e605c0eb 100644 --- a/proposals/clocks/wit/world.wit +++ b/proposals/clocks/wit/world.wit @@ -1,4 +1,4 @@ -package wasi:clocks@0.3.0; +package wasi:clocks@0.3.1; @since(version = 0.3.0) world imports { diff --git a/proposals/filesystem/imports.md b/proposals/filesystem/imports.md new file mode 100644 index 00000000..2afa37a9 --- /dev/null +++ b/proposals/filesystem/imports.md @@ -0,0 +1,917 @@ +

World imports

+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:clocks/system-clock@0.3.1

+

WASI System Clock is a clock API intended to let users query the current +time. The clock is not necessarily monotonic as it may be reset.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

External references may be reset, so this clock is not necessarily +monotonic, making it unsuitable for measuring elapsed time.

+

It is intended for reporting the current date and time for humans.

+
+

Types

+

type duration

+

duration

+

+

record instant

+

An "instant", or "exact time", is a point in time without regard to any +time zone: just the time since a particular external reference point, +often called an "epoch".

+

Here, the epoch is 1970-01-01T00:00:00Z, also known as +POSIX's Seconds Since the Epoch, also known as Unix Time.

+

Note that even if the seconds field is negative, incrementing +nanoseconds always represents moving forwards in time. +For example, { -1 seconds, 999999999 nanoseconds } represents the +instant one nanosecond before the epoch. +For more on various different ways to represent time, see +https://tc39.es/proposal-temporal/docs/timezone.html

+
Record Fields
+ +
+

Functions

+

now: func

+

Read the current value of the clock.

+

This clock is not monotonic, therefore calling this function repeatedly +will not necessarily produce a sequence of non-decreasing values.

+

The nanoseconds field of the output is always less than 1000000000.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.

+
Return values
+ +

Import interface wasi:filesystem/types@0.3.1

+

WASI filesystem is a filesystem API primarily intended to let users run WASI +programs that access their files on their existing filesystems, without +significant overhead.

+

Paths are passed as interface-type strings, meaning they must consist of +a sequence of Unicode Scalar Values (USVs). Some filesystems may contain +paths which are not accessible by this API.

+

The directory separator in WASI is always the forward-slash (/).

+

All paths in WASI are relative paths, and are interpreted relative to a +descriptor referring to a base directory. If a path argument to any WASI +function starts with /, or if any step of resolving a path, including +.. and symbolic link steps, reaches a directory outside of the base +directory, or reaches a symlink to an absolute or rooted path in the +underlying filesystem, the function fails with error-code::not-permitted.

+

For more information about WASI path resolution and sandboxing, see +WASI filesystem path resolution.

+

Though this package presents a portable interface modelled on POSIX, it +prioritizes compatibility over portability: allowing users to access their +files on their machine is more important than exposing a single semantics +across all platforms. Notably, depending on the underlying operating system +and file system:

+ +

Users that need well-defined, portable semantics should use a key-value +store or a database instead.

+
+

Types

+

type instant

+

instant

+

+

type filesize

+

u64

+

File size or length of a region within a file. +

variant descriptor-type

+

The type of a filesystem object referenced by a descriptor.

+

Note: This was called filetype in earlier versions of WASI.

+
Variant Cases
+ +

flags descriptor-flags

+

Descriptor flags.

+

Note: This was called fdflags in earlier versions of WASI.

+
Flags members
+ +

flags path-flags

+

Flags determining the method of how paths are resolved.

+
Flags members
+ +

flags open-flags

+

Open flags used by open-at.

+
Flags members
+ +

type link-count

+

u64

+

Number of hard links to an inode. +

record descriptor-stat

+

File attributes.

+

Note: This was called filestat in earlier versions of WASI.

+
Record Fields
+ +

variant new-timestamp

+

When setting a timestamp, this gives the value to set it to.

+
Variant Cases
+ +

record directory-entry

+

A directory entry.

+
Record Fields
+ +

variant error-code

+

Error codes returned by functions, similar to errno in POSIX. +Not all of these error codes are returned by the functions provided by this +API; some are used in higher-level library layers, and others are provided +merely for alignment with POSIX.

+
Variant Cases
+ +

enum advice

+

File or memory access pattern advisory information.

+
Enum Cases
+ +

record metadata-hash-value

+

A 128-bit hash value, split into parts because wasm doesn't have a +128-bit integer type.

+
Record Fields
+ +

resource descriptor

+

A descriptor is a reference to a filesystem object, which may be a file, +directory, named pipe, special file, or other object on which filesystem +calls may be made.

+

Functions

+

[method]descriptor.read-via-stream: func

+

Return a stream for reading from a file.

+

Multiple read, write, and append streams may be active on the same open +file and they do not interfere with each other.

+

This function returns a stream which provides the data received from the +file, and a future providing additional error information in case an +error is encountered.

+

If no error is encountered, stream.read on the stream will return +read-status::closed with no error-context and the future resolves to +the value ok. If an error is encountered, stream.read on the +stream returns read-status::closed with an error-context and the future +resolves to err with an error-code.

+

Note: This is similar to pread in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.write-via-stream: func

+

Return a stream for writing to a file, if available.

+

May fail with an error-code describing why the file cannot be written.

+

It is valid to write past the end of a file; the file is extended to the +extent of the write, with bytes between the previous end and the start of +the write set to zero.

+

This function returns once either full contents of the stream are +written or an error is encountered.

+

Note: This is similar to pwrite in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.append-via-stream: func

+

Return a stream for appending to a file, if available.

+

May fail with an error-code describing why the file cannot be appended.

+

This function returns once either full contents of the stream are +written or an error is encountered.

+

Note: This is similar to write with O_APPEND in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.advise: func

+

Provide file advisory information on a descriptor.

+

This is similar to posix_fadvise in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.sync-data: func

+

Synchronize the data of a file to disk.

+

This function succeeds with no effect if the file descriptor is not +opened for writing.

+

Note: This is similar to fdatasync in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.get-flags: func

+

Get flags associated with a descriptor.

+

Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX.

+

Note: This returns the value that was the fs_flags value returned +from fdstat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.get-type: func

+

Get the dynamic type of a descriptor.

+

Note: This returns the same value as the type field of the fd-stat +returned by stat, stat-at and similar.

+

Note: This returns similar flags to the st_mode & S_IFMT value provided +by fstat in POSIX.

+

Note: This returns the value that was the fs_filetype value returned +from fdstat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-size: func

+

Adjust the size of an open file. If this increases the file's size, the +extra bytes are filled with zeros.

+

Note: This was called fd_filestat_set_size in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-times: func

+

Adjust the timestamps of an open file or directory.

+

Note: This is similar to futimens in POSIX.

+

Note: This was called fd_filestat_set_times in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.read-directory: func

+

Read directory entries from a directory.

+

On filesystems where directories contain entries referring to themselves +and their parents, often named . and .. respectively, these entries +are omitted.

+

This always returns a new stream which starts at the beginning of the +directory. Multiple streams may be active on the same directory, and they +do not interfere with each other.

+

This function returns a future, which will resolve to an error code if +reading full contents of the directory fails.

+
Params
+ +
Return values
+ +

[method]descriptor.sync: func

+

Synchronize the data and metadata of a file to disk.

+

This function succeeds with no effect if the file descriptor is not +opened for writing.

+

Note: This is similar to fsync in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.create-directory-at: func

+

Create a directory.

+

Note: This is similar to mkdirat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.stat: func

+

Return the attributes of an open file or directory.

+

Note: This is similar to fstat in POSIX, except that it does not return +device and inode information. For testing whether two descriptors refer to +the same underlying filesystem object, use is-same-object. To obtain +additional data that can be used do determine whether a file has been +modified, use metadata-hash.

+

Note: This was called fd_filestat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.stat-at: func

+

Return the attributes of a file or directory.

+

Note: This is similar to fstatat in POSIX, except that it does not +return device and inode information. See the stat description for a +discussion of alternatives.

+

Note: This was called path_filestat_get in earlier versions of WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.set-times-at: func

+

Adjust the timestamps of a file or directory.

+

Note: This is similar to utimensat in POSIX.

+

Note: This was called path_filestat_set_times in earlier versions of +WASI.

+
Params
+ +
Return values
+ +

[method]descriptor.link-at: func

+

Create a hard link.

+

Fails with error-code::no-entry if the old path does not exist, +with error-code::exist if the new path already exists, and +error-code::not-permitted if the old path is not a file.

+

Note: This is similar to linkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.open-at: func

+

Open a file or directory.

+

If flags contains descriptor-flags::mutate-directory, and the base +descriptor doesn't have descriptor-flags::mutate-directory set, +open-at fails with error-code::read-only.

+

If flags contains write or mutate-directory, or open-flags +contains truncate or create, and the base descriptor doesn't have +descriptor-flags::mutate-directory set, open-at fails with +error-code::read-only.

+

Note: This is similar to openat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.readlink-at: func

+

Read the contents of a symbolic link.

+

If the contents contain an absolute or rooted path in the underlying +filesystem, this function fails with error-code::not-permitted.

+

Note: This is similar to readlinkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.remove-directory-at: func

+

Remove a directory.

+

Return error-code::not-empty if the directory is not empty.

+

Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.rename-at: func

+

Rename a filesystem object.

+

Note: This is similar to renameat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.symlink-at: func

+

Create a symbolic link (also known as a "symlink").

+

If old-path starts with /, the function fails with +error-code::not-permitted.

+

Note: This is similar to symlinkat in POSIX.

+
Params
+ +
Return values
+ +

[method]descriptor.unlink-file-at: func

+

Unlink a filesystem object that is not a directory.

+

This is similar to unlinkat(fd, path, 0) in POSIX.

+

Error returns are as specified by POSIX.

+

If the filesystem object is a directory, error-code::access or +error-code::is-directory may be returned instead of the +POSIX-specified error-code::not-permitted.

+
Params
+ +
Return values
+ +

[method]descriptor.is-same-object: func

+

Test whether two descriptors refer to the same filesystem object.

+

In POSIX, this corresponds to testing whether the two descriptors have the +same device (st_dev) and inode (st_ino or d_ino) numbers. +wasi-filesystem does not expose device and inode numbers, so this function +may be used instead.

+
Params
+ +
Return values
+ +

[method]descriptor.metadata-hash: func

+

Return a hash of the metadata associated with a filesystem object referred +to by a descriptor.

+

This returns a hash of the last-modification timestamp and file size, and +may also include the inode number, device number, birth timestamp, and +other metadata fields that may change when the file is modified or +replaced. It may also include a secret value chosen by the +implementation and not otherwise exposed.

+

Implementations are encouraged to provide the following properties:

+ +

However, none of these is required.

+
Params
+ +
Return values
+ +

[method]descriptor.metadata-hash-at: func

+

Return a hash of the metadata associated with a filesystem object referred +to by a directory descriptor and a relative path.

+

This performs the same hash computation as metadata-hash.

+
Params
+ +
Return values
+ +

Import interface wasi:filesystem/preopens@0.3.1

+
+

Types

+

type descriptor

+

descriptor

+

+


+

Functions

+

get-directories: func

+

Return the set of preopened directories, and their paths.

+
Return values
+ diff --git a/proposals/filesystem/wit/deps.lock b/proposals/filesystem/wit/deps.lock index 7e6404b9..800f564b 100644 --- a/proposals/filesystem/wit/deps.lock +++ b/proposals/filesystem/wit/deps.lock @@ -1,4 +1,4 @@ [clocks] path = "../../clocks/wit" -sha256 = "2d288cb781c60ae462537b39e4699de38f88072b501fc7f97d3f20984d550bcf" -sha512 = "1563eeeacbfea89e44f668b8588ef95b31feac7d9ec3bb5dad932320478b1aff1448031f44afa15ed926981855ac5bd504126389ddb7802f79c63b81b3c5ede7" +sha256 = "cee7f7ffff62be2416295a0bbdc13d822f5b4449ce37e0eb7cbdf3195156429d" +sha512 = "446835d225349f00f44b8c47fb3e6189491cfc19fdf3b394e3edd85276e3f1d7a515efb318cd11ef271c164ec54a54307110f2d0b72212a0108324f449d9b946" diff --git a/proposals/filesystem/wit/preopens.wit b/proposals/filesystem/wit/preopens.wit index 0b29aae3..2c225f90 100644 --- a/proposals/filesystem/wit/preopens.wit +++ b/proposals/filesystem/wit/preopens.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.3.0; +package wasi:filesystem@0.3.1; @since(version = 0.3.0) interface preopens { diff --git a/proposals/filesystem/wit/types.wit b/proposals/filesystem/wit/types.wit index fede686b..69ac7828 100644 --- a/proposals/filesystem/wit/types.wit +++ b/proposals/filesystem/wit/types.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.3.0; +package wasi:filesystem@0.3.1; /// WASI filesystem is a filesystem API primarily intended to let users run WASI /// programs that access their files on their existing filesystems, without /// significant overhead. @@ -37,7 +37,7 @@ package wasi:filesystem@0.3.0; @since(version = 0.3.0) interface types { @since(version = 0.3.0) - use wasi:clocks/system-clock@0.3.0.{instant}; + use wasi:clocks/system-clock@0.3.1.{instant}; /// File size or length of a region within a file. @since(version = 0.3.0) diff --git a/proposals/filesystem/wit/world.wit b/proposals/filesystem/wit/world.wit index c0ab32af..66cbb4d7 100644 --- a/proposals/filesystem/wit/world.wit +++ b/proposals/filesystem/wit/world.wit @@ -1,4 +1,4 @@ -package wasi:filesystem@0.3.0; +package wasi:filesystem@0.3.1; @since(version = 0.3.0) world imports { diff --git a/proposals/http/middleware.md b/proposals/http/middleware.md new file mode 100644 index 00000000..85964bbe --- /dev/null +++ b/proposals/http/middleware.md @@ -0,0 +1,1146 @@ +

World middleware

+

The wasi:http/middleware world captures HTTP services that forward HTTP +Requests to another handler.

+

Components may implement this world to allow them to participate in handler +"chains" where a request flows through handlers on its way to some terminal +service and corresponding response flows in the opposite direction.

+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:http/types@0.3.1

+

This interface defines all of the types and methods for implementing HTTP +Requests and Responses, as well as their headers, trailers, and bodies.

+
+

Types

+

type duration

+

duration

+

+

variant method

+

This type corresponds to HTTP standard Methods.

+
Variant Cases
+ +

variant scheme

+

This type corresponds to HTTP standard Related Schemes.

+
Variant Cases
+ +

record DNS-error-payload

+

Defines the case payload type for DNS-error above:

+
Record Fields
+ +

record TLS-alert-received-payload

+

Defines the case payload type for TLS-alert-received above:

+
Record Fields
+ +

record field-size-payload

+

Defines the case payload type for HTTP-response-{header,trailer}-size above:

+
Record Fields
+ +

variant error-code

+

These cases are inspired by the IANA HTTP Proxy Error Types: +https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types

+
Variant Cases
+ +

variant header-error

+

This type enumerates the different kinds of errors that may occur when +setting or appending to a fields resource.

+
Variant Cases
+ +

variant request-options-error

+

This type enumerates the different kinds of errors that may occur when +setting fields of a request-options resource.

+
Variant Cases
+ +

type field-name

+

string

+

Field names are always strings. +

Field names should always be treated as case insensitive by the fields +resource for the purposes of equality checking.

+

type field-value

+

field-value

+

Field values should always be ASCII strings. However, in +reality, HTTP implementations often have to interpret malformed values, +so they are provided as a list of bytes. +

resource fields

+

This following block defines the fields resource which corresponds to +HTTP standard Fields. Fields are a common representation used for both +Headers and Trailers.

+

A fields may be mutable or immutable. A fields created using the +constructor, from-list, or clone will be mutable, but a fields +resource given by other means (including, but not limited to, +request.headers) might be be immutable. In an immutable fields, the +set, append, and delete operations will fail with +header-error.immutable.

+

A fields resource should store field-names and field-values in their +original casing used to construct or mutate the fields resource. The fields +resource should use that original casing when returning them from a method. +The fields resource may use a different casing when serializing the value +for transmission, as doing so may improve encoding efficiency.

+

Implementations may impose limits on individual field values and on total +aggregate field section size. Operations that would exceed these limits +fail with header-error.size-exceeded

+

type headers

+

fields

+

Headers is an alias for Fields. +

type trailers

+

fields

+

Trailers is an alias for Fields. +

resource request

+

Represents an HTTP Request.

+

resource request-options

+

Parameters for making an HTTP Request. Each of these parameters is +currently an optional timeout applicable to the transport layer of the +HTTP protocol.

+

These timeouts are separate from any the user may use to bound an +asynchronous call.

+

type status-code

+

u16

+

This type corresponds to the HTTP standard Status Code. +

resource response

+

Represents an HTTP Response.

+

Functions

+

[constructor]fields: func

+

Construct an empty HTTP Fields.

+

The resulting fields is mutable.

+
Return values
+ +

[static]fields.from-list: func

+

Construct an HTTP Fields.

+

The resulting fields is mutable.

+

The list represents each name-value pair in the Fields. Names +which have multiple values are represented by multiple entries in this +list with the same name.

+

The tuple is a pair of the field name, represented as a string, and +Value, represented as a list of bytes. In a valid Fields, all names +and values are valid UTF-8 strings. However, values are not always +well-formed, so they are represented as a raw list of bytes.

+

An error result will be returned if any header or value was +syntactically invalid, if a header was forbidden, or if the +entries would exceed an implementation size limit.

+
Params
+ +
Return values
+ +

[method]fields.get: func

+

Get all of the values corresponding to a name. If the name is not present +in this fields, an empty list is returned. However, if the name is +present but empty, this is represented by a list with one or more +empty field-values present.

+
Params
+ +
Return values
+ +

[method]fields.has: func

+

Returns true when the name is present in this fields. If the name is +syntactically invalid, false is returned.

+
Params
+ +
Return values
+ +

[method]fields.set: func

+

Set all of the values for a name. Clears any existing values for that +name, if they have been set.

+

Fails with header-error.immutable if the fields are immutable.

+

Fails with header-error.size-exceeded if the name or values would +exceed an implementation-defined size limit.

+
Params
+ +
Return values
+ +

[method]fields.delete: func

+

Delete all values for a name. Does nothing if no values for the name +exist.

+

Fails with header-error.immutable if the fields are immutable.

+
Params
+ +
Return values
+ +

[method]fields.get-and-delete: func

+

Delete all values for a name. Does nothing if no values for the name +exist.

+

Returns all values previously corresponding to the name, if any.

+

Fails with header-error.immutable if the fields are immutable.

+
Params
+ +
Return values
+ +

[method]fields.append: func

+

Append a value for a name. Does not change or delete any existing +values for that name.

+

Fails with header-error.immutable if the fields are immutable.

+

Fails with header-error.size-exceeded if the value would exceed +an implementation-defined size limit.

+
Params
+ +
Return values
+ +

[method]fields.copy-all: func

+

Retrieve the full set of names and values in the Fields. Like the +constructor, the list represents each name-value pair.

+

The outer list represents each name-value pair in the Fields. Names +which have multiple values are represented by multiple entries in this +list with the same name.

+

The names and values are always returned in the original casing and in +the order in which they will be serialized for transport.

+
Params
+ +
Return values
+ +

[method]fields.clone: func

+

Make a deep copy of the Fields. Equivalent in behavior to calling the +fields constructor on the return value of copy-all. The resulting +fields is mutable.

+
Params
+ +
Return values
+ +

[static]request.new: func

+

Construct a new request with a default method of GET, and +none values for path-with-query, scheme, and authority.

+

headers is the HTTP Headers for the Request.

+

contents is the optional body content stream with none +representing a zero-length content stream. +Once it is closed, trailers future must resolve to a result. +If trailers resolves to an error, underlying connection +will be closed immediately.

+

options is optional request-options resource to be used +if the request is sent over a network connection.

+

It is possible to construct, or manipulate with the accessor functions +below, a request with an invalid combination of scheme +and authority, or headers which are not permitted to be sent. +It is the obligation of the handler.handle implementation +to reject invalid constructions of request.

+

The returned future resolves to result of transmission of this request.

+
Params
+ +
Return values
+ +

[method]request.get-method: func

+

Get the Method for the Request.

+
Params
+ +
Return values
+ +

[method]request.set-method: func

+

Set the Method for the Request. Fails if the string present in a +method.other argument is not a syntactically valid method.

+
Params
+ +
Return values
+ +

[method]request.get-path-with-query: func

+

Get the combination of the HTTP Path and Query for the Request. When +none, this represents an empty Path and empty Query.

+
Params
+ +
Return values
+ +

[method]request.set-path-with-query: func

+

Set the combination of the HTTP Path and Query for the Request. When +none, this represents an empty Path and empty Query. Fails is the +string given is not a syntactically valid path and query uri component.

+
Params
+ +
Return values
+ +

[method]request.get-scheme: func

+

Get the HTTP Related Scheme for the Request. When none, the +implementation may choose an appropriate default scheme.

+
Params
+ +
Return values
+ +

[method]request.set-scheme: func

+

Set the HTTP Related Scheme for the Request. When none, the +implementation may choose an appropriate default scheme. Fails if the +string given is not a syntactically valid uri scheme.

+
Params
+ +
Return values
+ +

[method]request.get-authority: func

+

Get the authority of the Request's target URI. A value of none may be used +with Related Schemes which do not require an authority. The HTTP and +HTTPS schemes always require an authority.

+
Params
+ +
Return values
+ +

[method]request.set-authority: func

+

Set the authority of the Request's target URI. A value of none may be used +with Related Schemes which do not require an authority. The HTTP and +HTTPS schemes always require an authority. Fails if the string given is +not a syntactically valid URI authority.

+
Params
+ +
Return values
+ +

[method]request.get-options: func

+

Get the request-options to be associated with this request

+

The returned request-options resource is immutable: set-* operations +will fail if invoked.

+

This request-options resource is a child: it must be dropped before +the parent request is dropped, or its ownership is transferred to +another component by e.g. handler.handle.

+
Params
+ +
Return values
+ +

[method]request.get-headers: func

+

Get the headers associated with the Request.

+

The returned headers resource is immutable: set, append, and +delete operations will fail with header-error.immutable.

+
Params
+ +
Return values
+ +

[static]request.consume-body: func

+

Get body of the Request.

+

Stream returned by this method represents the contents of the body. +Once the stream is reported as closed, callers should await the returned +future to determine whether the body was received successfully. +The future will only resolve after the stream is reported as closed.

+

This function takes a res future as a parameter, which can be used to +communicate an error in handling of the request.

+

Note that function will move the request, but references to headers or +request options acquired from it previously will remain valid.

+
Params
+ +
Return values
+ +

[constructor]request-options: func

+

Construct a default request-options value.

+
Return values
+ +

[method]request-options.get-connect-timeout: func

+

The timeout for the initial connect to the HTTP Server.

+
Params
+ +
Return values
+ +

[method]request-options.set-connect-timeout: func

+

Set the timeout for the initial connect to the HTTP Server. An error +return value indicates that this timeout is not supported or that this +handle is immutable.

+
Params
+ +
Return values
+ +

[method]request-options.get-first-byte-timeout: func

+

The timeout for receiving the first byte of the Response body.

+
Params
+ +
Return values
+ +

[method]request-options.set-first-byte-timeout: func

+

Set the timeout for receiving the first byte of the Response body. An +error return value indicates that this timeout is not supported or that +this handle is immutable.

+
Params
+ +
Return values
+ +

[method]request-options.get-between-bytes-timeout: func

+

The timeout for receiving subsequent chunks of bytes in the Response +body stream.

+
Params
+ +
Return values
+ +

[method]request-options.set-between-bytes-timeout: func

+

Set the timeout for receiving subsequent chunks of bytes in the Response +body stream. An error return value indicates that this timeout is not +supported or that this handle is immutable.

+
Params
+ +
Return values
+ +

[method]request-options.clone: func

+

Make a deep copy of the request-options. +The resulting request-options is mutable.

+
Params
+ +
Return values
+ +

[static]response.new: func

+

Construct a new response, with a default status-code of 200. +If a different status-code is needed, it must be set via the +set-status-code method.

+

headers is the HTTP Headers for the Response.

+

contents is the optional body content stream with none +representing a zero-length content stream. +Once it is closed, trailers future must resolve to a result. +If trailers resolves to an error, underlying connection +will be closed immediately.

+

The returned future resolves to result of transmission of this response.

+
Params
+ +
Return values
+ +

[method]response.get-status-code: func

+

Get the HTTP Status Code for the Response.

+
Params
+ +
Return values
+ +

[method]response.set-status-code: func

+

Set the HTTP Status Code for the Response. Fails if the status-code +given is not a valid http status code.

+
Params
+ +
Return values
+ +

[method]response.get-headers: func

+

Get the headers associated with the Response.

+

The returned headers resource is immutable: set, append, and +delete operations will fail with header-error.immutable.

+
Params
+ +
Return values
+ +

[static]response.consume-body: func

+

Get body of the Response.

+

Stream returned by this method represents the contents of the body. +Once the stream is reported as closed, callers should await the returned +future to determine whether the body was received successfully. +The future will only resolve after the stream is reported as closed.

+

This function takes a res future as a parameter, which can be used to +communicate an error in handling of the response.

+

Note that function will move the response, but references to headers +acquired from it previously will remain valid.

+
Params
+ +
Return values
+ +

Import interface wasi:http/handler@0.3.1

+

This interface defines a handler of HTTP Requests.

+

In a wasi:http/service this interface is exported to respond to an +incoming HTTP Request with a Response.

+

In wasi:http/middleware this interface is both exported and imported as +the "downstream" and "upstream" directions of the middleware chain.

+
+

Types

+

type request

+

request

+

+

type response

+

response

+

+

type error-code

+

error-code

+

+


+

Functions

+

handle: func

+

This function may be called with either an incoming request read from the +network or a request synthesized or forwarded by another component.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/types@0.3.1

+
+

Types

+

enum error-code

+
Enum Cases
+ +

Import interface wasi:cli/stdout@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stdout.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/stderr@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stderr.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/stdin@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

read-via-stream: func

+

Return a stream for reading from stdin.

+

This function returns a stream which provides data read from stdin, +and a future to signal read results.

+

If the stream's readable end is dropped the future will resolve to success.

+

If the stream's writable end is dropped the future will either resolve to +success if stdin was closed by the writer or to an error-code if reading +failed for some other reason.

+

Multiple streams may be active at the same time. The behavior of concurrent +reads is implementation-specific.

+
Return values
+ +

Import interface wasi:http/client@0.3.1

+

This interface defines an HTTP client for sending "outgoing" requests.

+

Most components are expected to import this interface to provide the +capability to send HTTP requests to arbitrary destinations on a network.

+

The type signature of client.send is the same as handler.handle. This +duplication is currently necessary because some Component Model tooling +(including WIT itself) is unable to represent a component importing two +instances of the same interface. A client.send import may be linked +directly to a handler.handle export to bypass the network.

+
+

Types

+

type request

+

request

+

+

type response

+

response

+

+

type error-code

+

error-code

+

+


+

Functions

+

send: func

+

This function may be used to either send an outgoing request over the +network or to forward it to another component.

+
Params
+ +
Return values
+ +

Import interface wasi:clocks/monotonic-clock@0.3.1

+

WASI Monotonic Clock is a clock API intended to let users measure elapsed +time.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

A monotonic clock is a clock which has an unspecified initial value, and +successive reads of the clock will produce non-decreasing values.

+
+

Types

+

type duration

+

duration

+

+

type mark

+

u64

+

A mark on a monotonic clock is a number of nanoseconds since an +unspecified initial value, and can only be compared to instances from +the same monotonic-clock. +


+

Functions

+

now: func

+

Read the current value of the clock.

+

The clock is monotonic, therefore calling this function repeatedly will +produce a sequence of non-decreasing values.

+

For completeness, this function traps if it's not possible to represent +the value of the clock in a mark. Consequently, implementations +should ensure that the starting time is low enough to avoid the +possibility of overflow in practice.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the duration of time +corresponding to a clock tick.

+
Return values
+ +

wait-until: func

+

Wait until the specified mark has occurred.

+
Params
+ +

wait-for: func

+

Wait for the specified duration to elapse.

+
Params
+ +

Import interface wasi:clocks/system-clock@0.3.1

+

WASI System Clock is a clock API intended to let users query the current +time. The clock is not necessarily monotonic as it may be reset.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

External references may be reset, so this clock is not necessarily +monotonic, making it unsuitable for measuring elapsed time.

+

It is intended for reporting the current date and time for humans.

+
+

Types

+

type duration

+

duration

+

+

record instant

+

An "instant", or "exact time", is a point in time without regard to any +time zone: just the time since a particular external reference point, +often called an "epoch".

+

Here, the epoch is 1970-01-01T00:00:00Z, also known as +POSIX's Seconds Since the Epoch, also known as Unix Time.

+

Note that even if the seconds field is negative, incrementing +nanoseconds always represents moving forwards in time. +For example, { -1 seconds, 999999999 nanoseconds } represents the +instant one nanosecond before the epoch. +For more on various different ways to represent time, see +https://tc39.es/proposal-temporal/docs/timezone.html

+
Record Fields
+ +
+

Functions

+

now: func

+

Read the current value of the clock.

+

This clock is not monotonic, therefore calling this function repeatedly +will not necessarily produce a sequence of non-decreasing values.

+

The nanoseconds field of the output is always less than 1000000000.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.

+
Return values
+ +

Import interface wasi:clocks/timezone@0.3.1

+
+

Types

+

type instant

+

instant

+

+


+

Functions

+

iana-id: func

+

Return the IANA identifier of the currently configured timezone. This +should be an identifier from the IANA Time Zone Database.

+

For displaying to a user, the identifier should be converted into a +localized name by means of an internationalization API.

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, or the timezone does +not have an IANA identifier, this returns nothing.

+
Return values
+ +

utc-offset: func

+

The number of nanoseconds difference between UTC time and the local +time of the currently configured timezone, at the exact time of +instant.

+

The magnitude of the returned value will always be less than +86,400,000,000,000 which is the number of nanoseconds in a day +(246060*1e9).

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, this returns +nothing.

+
Params
+ +
Return values
+ +

to-debug-string: func

+

Returns a string that is suitable to assist humans in debugging whether +any timezone is available, and if so, which. This may be the same string +as iana-id, or a formatted representation of the UTC offset such as +-04:00, or something else.

+

WARNING: The returned string should not be consumed mechanically! It may +change across platforms, hosts, or other implementation details. Parsing +this string is a major platform-compatibility hazard.

+
Return values
+ +

Import interface wasi:random/random@0.3.1

+

WASI Random is a random data API.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-random-bytes: func

+

Return up to max-len cryptographically-secure random or pseudo-random +bytes.

+

This function must produce data at least as cryptographically secure and +fast as an adequately seeded cryptographically-secure pseudo-random +number generator (CSPRNG). It must not block, from the perspective of +the calling program, under any circumstances, including on the first +request and on requests for numbers of bytes. The returned data must +always be unpredictable.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+

This function must always return fresh data. Deterministic environments +must omit this function, rather than implementing it with deterministic +data.

+
Params
+ +
Return values
+ +

get-random-u64: func

+

Return a cryptographically-secure random or pseudo-random u64 value.

+

This function returns the same type of data as get-random-bytes, +represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure@0.3.1

+

The insecure interface for insecure pseudo-random numbers.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-random-bytes: func

+

Return up to max-len insecure pseudo-random bytes.

+

This function is not cryptographically secure. Do not use it for +anything related to security.

+

There are no requirements on the values of the returned bytes, however +implementations are encouraged to return evenly distributed values with +a long period.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+
Params
+ +
Return values
+ +

get-insecure-random-u64: func

+

Return an insecure pseudo-random u64 value.

+

This function returns the same type of pseudo-random data as +get-insecure-random-bytes, represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure-seed@0.3.1

+

The insecure-seed interface for seeding hash-map DoS resistance.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-seed: func

+

Return a 128-bit value that may contain a pseudo-random value.

+

The returned value is not required to be computed from a CSPRNG, and may +even be entirely deterministic. Host implementations are encouraged to +provide pseudo-random values to any program exposed to +attacker-controlled content, to enable DoS protection built into many +languages' hash-map implementations.

+

This function is intended to only be called once, by a source language +to initialize Denial Of Service (DoS) protection in its hash-map +implementation.

+

Expected future evolution

+

This will likely be changed to a value import, to prevent it from being +called multiple times and potentially used for purposes other than DoS +protection.

+
Return values
+ +

Export interface wasi:http/handler@0.3.1

+
+

Types

+

type request

+

request

+

+

type response

+

response

+

+

type error-code

+

error-code

+

+


+

Functions

+

handle: func

+

This function may be called with either an incoming request read from the +network or a request synthesized or forwarded by another component.

+
Params
+ +
Return values
+ diff --git a/proposals/http/service.md b/proposals/http/service.md new file mode 100644 index 00000000..1a81e15c --- /dev/null +++ b/proposals/http/service.md @@ -0,0 +1,1113 @@ +

World service

+

The wasi:http/service world captures a broad category of HTTP services +including web applications, API servers, and proxies. It may be included +in more specific worlds such as wasi:http/middleware.

+ +

Import interface wasi:cli/types@0.3.1

+
+

Types

+

enum error-code

+
Enum Cases
+ +

Import interface wasi:cli/stdout@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stdout.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/stderr@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

write-via-stream: func

+

Write the given stream to stderr.

+

If the stream's writable end is dropped this function will either return +success once the entire contents of the stream have been written or an +error-code representing a failure.

+

Otherwise if there is an error the readable end of the stream will be +dropped and this function will return an error-code.

+
Params
+ +
Return values
+ +

Import interface wasi:cli/stdin@0.3.1

+
+

Types

+

type error-code

+

error-code

+

+


+

Functions

+

read-via-stream: func

+

Return a stream for reading from stdin.

+

This function returns a stream which provides data read from stdin, +and a future to signal read results.

+

If the stream's readable end is dropped the future will resolve to success.

+

If the stream's writable end is dropped the future will either resolve to +success if stdin was closed by the writer or to an error-code if reading +failed for some other reason.

+

Multiple streams may be active at the same time. The behavior of concurrent +reads is implementation-specific.

+
Return values
+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:http/types@0.3.1

+

This interface defines all of the types and methods for implementing HTTP +Requests and Responses, as well as their headers, trailers, and bodies.

+
+

Types

+

type duration

+

duration

+

+

variant method

+

This type corresponds to HTTP standard Methods.

+
Variant Cases
+ +

variant scheme

+

This type corresponds to HTTP standard Related Schemes.

+
Variant Cases
+ +

record DNS-error-payload

+

Defines the case payload type for DNS-error above:

+
Record Fields
+ +

record TLS-alert-received-payload

+

Defines the case payload type for TLS-alert-received above:

+
Record Fields
+ +

record field-size-payload

+

Defines the case payload type for HTTP-response-{header,trailer}-size above:

+
Record Fields
+ +

variant error-code

+

These cases are inspired by the IANA HTTP Proxy Error Types: +https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types

+
Variant Cases
+ +

variant header-error

+

This type enumerates the different kinds of errors that may occur when +setting or appending to a fields resource.

+
Variant Cases
+ +

variant request-options-error

+

This type enumerates the different kinds of errors that may occur when +setting fields of a request-options resource.

+
Variant Cases
+ +

type field-name

+

string

+

Field names are always strings. +

Field names should always be treated as case insensitive by the fields +resource for the purposes of equality checking.

+

type field-value

+

field-value

+

Field values should always be ASCII strings. However, in +reality, HTTP implementations often have to interpret malformed values, +so they are provided as a list of bytes. +

resource fields

+

This following block defines the fields resource which corresponds to +HTTP standard Fields. Fields are a common representation used for both +Headers and Trailers.

+

A fields may be mutable or immutable. A fields created using the +constructor, from-list, or clone will be mutable, but a fields +resource given by other means (including, but not limited to, +request.headers) might be be immutable. In an immutable fields, the +set, append, and delete operations will fail with +header-error.immutable.

+

A fields resource should store field-names and field-values in their +original casing used to construct or mutate the fields resource. The fields +resource should use that original casing when returning them from a method. +The fields resource may use a different casing when serializing the value +for transmission, as doing so may improve encoding efficiency.

+

Implementations may impose limits on individual field values and on total +aggregate field section size. Operations that would exceed these limits +fail with header-error.size-exceeded

+

type headers

+

fields

+

Headers is an alias for Fields. +

type trailers

+

fields

+

Trailers is an alias for Fields. +

resource request

+

Represents an HTTP Request.

+

resource request-options

+

Parameters for making an HTTP Request. Each of these parameters is +currently an optional timeout applicable to the transport layer of the +HTTP protocol.

+

These timeouts are separate from any the user may use to bound an +asynchronous call.

+

type status-code

+

u16

+

This type corresponds to the HTTP standard Status Code. +

resource response

+

Represents an HTTP Response.

+

Functions

+

[constructor]fields: func

+

Construct an empty HTTP Fields.

+

The resulting fields is mutable.

+
Return values
+ +

[static]fields.from-list: func

+

Construct an HTTP Fields.

+

The resulting fields is mutable.

+

The list represents each name-value pair in the Fields. Names +which have multiple values are represented by multiple entries in this +list with the same name.

+

The tuple is a pair of the field name, represented as a string, and +Value, represented as a list of bytes. In a valid Fields, all names +and values are valid UTF-8 strings. However, values are not always +well-formed, so they are represented as a raw list of bytes.

+

An error result will be returned if any header or value was +syntactically invalid, if a header was forbidden, or if the +entries would exceed an implementation size limit.

+
Params
+ +
Return values
+ +

[method]fields.get: func

+

Get all of the values corresponding to a name. If the name is not present +in this fields, an empty list is returned. However, if the name is +present but empty, this is represented by a list with one or more +empty field-values present.

+
Params
+ +
Return values
+ +

[method]fields.has: func

+

Returns true when the name is present in this fields. If the name is +syntactically invalid, false is returned.

+
Params
+ +
Return values
+ +

[method]fields.set: func

+

Set all of the values for a name. Clears any existing values for that +name, if they have been set.

+

Fails with header-error.immutable if the fields are immutable.

+

Fails with header-error.size-exceeded if the name or values would +exceed an implementation-defined size limit.

+
Params
+ +
Return values
+ +

[method]fields.delete: func

+

Delete all values for a name. Does nothing if no values for the name +exist.

+

Fails with header-error.immutable if the fields are immutable.

+
Params
+ +
Return values
+ +

[method]fields.get-and-delete: func

+

Delete all values for a name. Does nothing if no values for the name +exist.

+

Returns all values previously corresponding to the name, if any.

+

Fails with header-error.immutable if the fields are immutable.

+
Params
+ +
Return values
+ +

[method]fields.append: func

+

Append a value for a name. Does not change or delete any existing +values for that name.

+

Fails with header-error.immutable if the fields are immutable.

+

Fails with header-error.size-exceeded if the value would exceed +an implementation-defined size limit.

+
Params
+ +
Return values
+ +

[method]fields.copy-all: func

+

Retrieve the full set of names and values in the Fields. Like the +constructor, the list represents each name-value pair.

+

The outer list represents each name-value pair in the Fields. Names +which have multiple values are represented by multiple entries in this +list with the same name.

+

The names and values are always returned in the original casing and in +the order in which they will be serialized for transport.

+
Params
+ +
Return values
+ +

[method]fields.clone: func

+

Make a deep copy of the Fields. Equivalent in behavior to calling the +fields constructor on the return value of copy-all. The resulting +fields is mutable.

+
Params
+ +
Return values
+ +

[static]request.new: func

+

Construct a new request with a default method of GET, and +none values for path-with-query, scheme, and authority.

+

headers is the HTTP Headers for the Request.

+

contents is the optional body content stream with none +representing a zero-length content stream. +Once it is closed, trailers future must resolve to a result. +If trailers resolves to an error, underlying connection +will be closed immediately.

+

options is optional request-options resource to be used +if the request is sent over a network connection.

+

It is possible to construct, or manipulate with the accessor functions +below, a request with an invalid combination of scheme +and authority, or headers which are not permitted to be sent. +It is the obligation of the handler.handle implementation +to reject invalid constructions of request.

+

The returned future resolves to result of transmission of this request.

+
Params
+ +
Return values
+ +

[method]request.get-method: func

+

Get the Method for the Request.

+
Params
+ +
Return values
+ +

[method]request.set-method: func

+

Set the Method for the Request. Fails if the string present in a +method.other argument is not a syntactically valid method.

+
Params
+ +
Return values
+ +

[method]request.get-path-with-query: func

+

Get the combination of the HTTP Path and Query for the Request. When +none, this represents an empty Path and empty Query.

+
Params
+ +
Return values
+ +

[method]request.set-path-with-query: func

+

Set the combination of the HTTP Path and Query for the Request. When +none, this represents an empty Path and empty Query. Fails is the +string given is not a syntactically valid path and query uri component.

+
Params
+ +
Return values
+ +

[method]request.get-scheme: func

+

Get the HTTP Related Scheme for the Request. When none, the +implementation may choose an appropriate default scheme.

+
Params
+ +
Return values
+ +

[method]request.set-scheme: func

+

Set the HTTP Related Scheme for the Request. When none, the +implementation may choose an appropriate default scheme. Fails if the +string given is not a syntactically valid uri scheme.

+
Params
+ +
Return values
+ +

[method]request.get-authority: func

+

Get the authority of the Request's target URI. A value of none may be used +with Related Schemes which do not require an authority. The HTTP and +HTTPS schemes always require an authority.

+
Params
+ +
Return values
+ +

[method]request.set-authority: func

+

Set the authority of the Request's target URI. A value of none may be used +with Related Schemes which do not require an authority. The HTTP and +HTTPS schemes always require an authority. Fails if the string given is +not a syntactically valid URI authority.

+
Params
+ +
Return values
+ +

[method]request.get-options: func

+

Get the request-options to be associated with this request

+

The returned request-options resource is immutable: set-* operations +will fail if invoked.

+

This request-options resource is a child: it must be dropped before +the parent request is dropped, or its ownership is transferred to +another component by e.g. handler.handle.

+
Params
+ +
Return values
+ +

[method]request.get-headers: func

+

Get the headers associated with the Request.

+

The returned headers resource is immutable: set, append, and +delete operations will fail with header-error.immutable.

+
Params
+ +
Return values
+ +

[static]request.consume-body: func

+

Get body of the Request.

+

Stream returned by this method represents the contents of the body. +Once the stream is reported as closed, callers should await the returned +future to determine whether the body was received successfully. +The future will only resolve after the stream is reported as closed.

+

This function takes a res future as a parameter, which can be used to +communicate an error in handling of the request.

+

Note that function will move the request, but references to headers or +request options acquired from it previously will remain valid.

+
Params
+ +
Return values
+ +

[constructor]request-options: func

+

Construct a default request-options value.

+
Return values
+ +

[method]request-options.get-connect-timeout: func

+

The timeout for the initial connect to the HTTP Server.

+
Params
+ +
Return values
+ +

[method]request-options.set-connect-timeout: func

+

Set the timeout for the initial connect to the HTTP Server. An error +return value indicates that this timeout is not supported or that this +handle is immutable.

+
Params
+ +
Return values
+ +

[method]request-options.get-first-byte-timeout: func

+

The timeout for receiving the first byte of the Response body.

+
Params
+ +
Return values
+ +

[method]request-options.set-first-byte-timeout: func

+

Set the timeout for receiving the first byte of the Response body. An +error return value indicates that this timeout is not supported or that +this handle is immutable.

+
Params
+ +
Return values
+ +

[method]request-options.get-between-bytes-timeout: func

+

The timeout for receiving subsequent chunks of bytes in the Response +body stream.

+
Params
+ +
Return values
+ +

[method]request-options.set-between-bytes-timeout: func

+

Set the timeout for receiving subsequent chunks of bytes in the Response +body stream. An error return value indicates that this timeout is not +supported or that this handle is immutable.

+
Params
+ +
Return values
+ +

[method]request-options.clone: func

+

Make a deep copy of the request-options. +The resulting request-options is mutable.

+
Params
+ +
Return values
+ +

[static]response.new: func

+

Construct a new response, with a default status-code of 200. +If a different status-code is needed, it must be set via the +set-status-code method.

+

headers is the HTTP Headers for the Response.

+

contents is the optional body content stream with none +representing a zero-length content stream. +Once it is closed, trailers future must resolve to a result. +If trailers resolves to an error, underlying connection +will be closed immediately.

+

The returned future resolves to result of transmission of this response.

+
Params
+ +
Return values
+ +

[method]response.get-status-code: func

+

Get the HTTP Status Code for the Response.

+
Params
+ +
Return values
+ +

[method]response.set-status-code: func

+

Set the HTTP Status Code for the Response. Fails if the status-code +given is not a valid http status code.

+
Params
+ +
Return values
+ +

[method]response.get-headers: func

+

Get the headers associated with the Response.

+

The returned headers resource is immutable: set, append, and +delete operations will fail with header-error.immutable.

+
Params
+ +
Return values
+ +

[static]response.consume-body: func

+

Get body of the Response.

+

Stream returned by this method represents the contents of the body. +Once the stream is reported as closed, callers should await the returned +future to determine whether the body was received successfully. +The future will only resolve after the stream is reported as closed.

+

This function takes a res future as a parameter, which can be used to +communicate an error in handling of the response.

+

Note that function will move the response, but references to headers +acquired from it previously will remain valid.

+
Params
+ +
Return values
+ +

Import interface wasi:http/client@0.3.1

+

This interface defines an HTTP client for sending "outgoing" requests.

+

Most components are expected to import this interface to provide the +capability to send HTTP requests to arbitrary destinations on a network.

+

The type signature of client.send is the same as handler.handle. This +duplication is currently necessary because some Component Model tooling +(including WIT itself) is unable to represent a component importing two +instances of the same interface. A client.send import may be linked +directly to a handler.handle export to bypass the network.

+
+

Types

+

type request

+

request

+

+

type response

+

response

+

+

type error-code

+

error-code

+

+


+

Functions

+

send: func

+

This function may be used to either send an outgoing request over the +network or to forward it to another component.

+
Params
+ +
Return values
+ +

Import interface wasi:clocks/monotonic-clock@0.3.1

+

WASI Monotonic Clock is a clock API intended to let users measure elapsed +time.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

A monotonic clock is a clock which has an unspecified initial value, and +successive reads of the clock will produce non-decreasing values.

+
+

Types

+

type duration

+

duration

+

+

type mark

+

u64

+

A mark on a monotonic clock is a number of nanoseconds since an +unspecified initial value, and can only be compared to instances from +the same monotonic-clock. +


+

Functions

+

now: func

+

Read the current value of the clock.

+

The clock is monotonic, therefore calling this function repeatedly will +produce a sequence of non-decreasing values.

+

For completeness, this function traps if it's not possible to represent +the value of the clock in a mark. Consequently, implementations +should ensure that the starting time is low enough to avoid the +possibility of overflow in practice.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the duration of time +corresponding to a clock tick.

+
Return values
+ +

wait-until: func

+

Wait until the specified mark has occurred.

+
Params
+ +

wait-for: func

+

Wait for the specified duration to elapse.

+
Params
+ +

Import interface wasi:clocks/system-clock@0.3.1

+

WASI System Clock is a clock API intended to let users query the current +time. The clock is not necessarily monotonic as it may be reset.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+

External references may be reset, so this clock is not necessarily +monotonic, making it unsuitable for measuring elapsed time.

+

It is intended for reporting the current date and time for humans.

+
+

Types

+

type duration

+

duration

+

+

record instant

+

An "instant", or "exact time", is a point in time without regard to any +time zone: just the time since a particular external reference point, +often called an "epoch".

+

Here, the epoch is 1970-01-01T00:00:00Z, also known as +POSIX's Seconds Since the Epoch, also known as Unix Time.

+

Note that even if the seconds field is negative, incrementing +nanoseconds always represents moving forwards in time. +For example, { -1 seconds, 999999999 nanoseconds } represents the +instant one nanosecond before the epoch. +For more on various different ways to represent time, see +https://tc39.es/proposal-temporal/docs/timezone.html

+
Record Fields
+ +
+

Functions

+

now: func

+

Read the current value of the clock.

+

This clock is not monotonic, therefore calling this function repeatedly +will not necessarily produce a sequence of non-decreasing values.

+

The nanoseconds field of the output is always less than 1000000000.

+
Return values
+ +

get-resolution: func

+

Query the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.

+
Return values
+ +

Import interface wasi:clocks/timezone@0.3.1

+
+

Types

+

type instant

+

instant

+

+


+

Functions

+

iana-id: func

+

Return the IANA identifier of the currently configured timezone. This +should be an identifier from the IANA Time Zone Database.

+

For displaying to a user, the identifier should be converted into a +localized name by means of an internationalization API.

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, or the timezone does +not have an IANA identifier, this returns nothing.

+
Return values
+ +

utc-offset: func

+

The number of nanoseconds difference between UTC time and the local +time of the currently configured timezone, at the exact time of +instant.

+

The magnitude of the returned value will always be less than +86,400,000,000,000 which is the number of nanoseconds in a day +(246060*1e9).

+

If the implementation does not expose an actual timezone, or is unable +to provide mappings from times to deltas between the configured timezone +and UTC, or determining the current timezone fails, this returns +nothing.

+
Params
+ +
Return values
+ +

to-debug-string: func

+

Returns a string that is suitable to assist humans in debugging whether +any timezone is available, and if so, which. This may be the same string +as iana-id, or a formatted representation of the UTC offset such as +-04:00, or something else.

+

WARNING: The returned string should not be consumed mechanically! It may +change across platforms, hosts, or other implementation details. Parsing +this string is a major platform-compatibility hazard.

+
Return values
+ +

Import interface wasi:random/random@0.3.1

+

WASI Random is a random data API.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-random-bytes: func

+

Return up to max-len cryptographically-secure random or pseudo-random +bytes.

+

This function must produce data at least as cryptographically secure and +fast as an adequately seeded cryptographically-secure pseudo-random +number generator (CSPRNG). It must not block, from the perspective of +the calling program, under any circumstances, including on the first +request and on requests for numbers of bytes. The returned data must +always be unpredictable.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+

This function must always return fresh data. Deterministic environments +must omit this function, rather than implementing it with deterministic +data.

+
Params
+ +
Return values
+ +

get-random-u64: func

+

Return a cryptographically-secure random or pseudo-random u64 value.

+

This function returns the same type of data as get-random-bytes, +represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure@0.3.1

+

The insecure interface for insecure pseudo-random numbers.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-random-bytes: func

+

Return up to max-len insecure pseudo-random bytes.

+

This function is not cryptographically secure. Do not use it for +anything related to security.

+

There are no requirements on the values of the returned bytes, however +implementations are encouraged to return evenly distributed values with +a long period.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+
Params
+ +
Return values
+ +

get-insecure-random-u64: func

+

Return an insecure pseudo-random u64 value.

+

This function returns the same type of pseudo-random data as +get-insecure-random-bytes, represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure-seed@0.3.1

+

The insecure-seed interface for seeding hash-map DoS resistance.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-seed: func

+

Return a 128-bit value that may contain a pseudo-random value.

+

The returned value is not required to be computed from a CSPRNG, and may +even be entirely deterministic. Host implementations are encouraged to +provide pseudo-random values to any program exposed to +attacker-controlled content, to enable DoS protection built into many +languages' hash-map implementations.

+

This function is intended to only be called once, by a source language +to initialize Denial Of Service (DoS) protection in its hash-map +implementation.

+

Expected future evolution

+

This will likely be changed to a value import, to prevent it from being +called multiple times and potentially used for purposes other than DoS +protection.

+
Return values
+ +

Export interface wasi:http/handler@0.3.1

+
+

Types

+

type request

+

request

+

+

type response

+

response

+

+

type error-code

+

error-code

+

+


+

Functions

+

handle: func

+

This function may be called with either an incoming request read from the +network or a request synthesized or forwarded by another component.

+
Params
+ +
Return values
+ diff --git a/proposals/http/wit/deps.lock b/proposals/http/wit/deps.lock index 45858782..aa0f72c0 100644 --- a/proposals/http/wit/deps.lock +++ b/proposals/http/wit/deps.lock @@ -1,22 +1,22 @@ [cli] path = "../../cli/wit" -sha256 = "d9f51b8ac7fb9612ff406783658a254c7873a9ebbcfb790cfd6df74c1ef8b385" -sha512 = "38f0f890ca7d95a652d4004bb9b0b870fb883f4b90e219e155a853f1ab1f7f13b1d2331db1c986b28747df5a084dd3a0ae7a9f3067ca92167bfb3c34b5adc56b" +sha256 = "9645378e1dafc659329f0f7ff92451e7b356283996614363be5b3e0d70aba742" +sha512 = "38e0276ae6da58d8475aa00c1db1707b01a53b38cfc96132379ab0d22c4d26c24352bf33f5316b0d33369553eaba4c2fca3a001373b6bbfabd48849f223c1702" deps = ["filesystem", "random", "sockets"] [clocks] path = "../../clocks/wit" -sha256 = "2d288cb781c60ae462537b39e4699de38f88072b501fc7f97d3f20984d550bcf" -sha512 = "1563eeeacbfea89e44f668b8588ef95b31feac7d9ec3bb5dad932320478b1aff1448031f44afa15ed926981855ac5bd504126389ddb7802f79c63b81b3c5ede7" +sha256 = "cee7f7ffff62be2416295a0bbdc13d822f5b4449ce37e0eb7cbdf3195156429d" +sha512 = "446835d225349f00f44b8c47fb3e6189491cfc19fdf3b394e3edd85276e3f1d7a515efb318cd11ef271c164ec54a54307110f2d0b72212a0108324f449d9b946" [filesystem] -sha256 = "2c804c867e34eabd75171119f062a49a1b9758d1ec1956535e467b7353e61dd3" -sha512 = "db25d5306dc671c7a7db6a273318d056d6e544567636b3759db48ab4e81a06bc5c1fc3aa2d1522d4187a116730b1a8ecc57a4f974925fda6deaaf06d237da6df" +sha256 = "7e29e1b85da02279d2853dff263bbfe647b1b19105b96bb2a850ea8d201e7bbb" +sha512 = "7cdba2ef1090aa6b83eb292dd90992df2a9db24f577728b9275e0c3eb4fe19bcb8f0e7defa914d79e7adee72029d8c9501b2cc6387723b515d0ff296c3c1acff" [random] -sha256 = "607700294fdbd7de5c4771628db8830b05ae53c48e66c7645feae98f298a5feb" -sha512 = "a059c887a04b2927df93b8eb83e0843d9ab804e31dee060bf83b74fa6fdd24fbafbb7f9cfcbfa7838cbf6c7e684de8fd4c0b338f3006db1077dd338bf01445ce" +sha256 = "5196da126852cb29c39790da453ec6d5f46a266283dadd69a5f93f10a9850376" +sha512 = "4147e0f33b26cd6bf46cc1da4afed21e620fe8ede4b06199c8826fd456ed4977974ac1b6437dccdfb602f1b352d06a455717852f43ae5143fffc01e75ca3d74d" [sockets] -sha256 = "663af53b8a4e6aa66fa24618c5d0d6dd4bfaa970121a85951e8ab52cea0b0852" -sha512 = "4faf0eb9e8f486d3dadddc7f491f87ca6b1626f0296e8e918c529f39696f61398e4c37d0dfa6529a157f65747bbd455487fe0b6bb04e075d65a8d75844225e2a" +sha256 = "8db169a251f64d3b06162f2012a3b0b794a2e65187b130fc21adf5c913ddb140" +sha512 = "6d2a2a4b0b575a3856eb1d0448b4637357587123d12d4633b1e8bded88530085a1f36bfcfda6a2e27ce633581d7e3b778c2658f796b884972d3d2043ae7b5795" diff --git a/proposals/http/wit/types.wit b/proposals/http/wit/types.wit index fc19d2c8..47a6d621 100644 --- a/proposals/http/wit/types.wit +++ b/proposals/http/wit/types.wit @@ -1,10 +1,10 @@ -package wasi:http@0.3.0; +package wasi:http@0.3.1; /// This interface defines all of the types and methods for implementing HTTP /// Requests and Responses, as well as their headers, trailers, and bodies. @since(version = 0.3.0) interface types { - use wasi:clocks/types@0.3.0.{duration}; + use wasi:clocks/types@0.3.1.{duration}; /// This type corresponds to HTTP standard Methods. @since(version = 0.3.0) diff --git a/proposals/http/wit/worlds.wit b/proposals/http/wit/worlds.wit index a6492947..d79414d2 100644 --- a/proposals/http/wit/worlds.wit +++ b/proposals/http/wit/worlds.wit @@ -1,4 +1,4 @@ -package wasi:http@0.3.0; +package wasi:http@0.3.1; /// The `wasi:http/service` world captures a broad category of HTTP services /// including web applications, API servers, and proxies. It may be `include`d @@ -6,19 +6,19 @@ package wasi:http@0.3.0; @since(version = 0.3.0) world service { /// HTTP services have access to time and randomness. - include wasi:clocks/imports@0.3.0; - include wasi:random/imports@0.3.0; + include wasi:clocks/imports@0.3.1; + include wasi:random/imports@0.3.1; /// Services have standard output and error streams which are expected to /// terminate in a developer-facing console provided by the host. - import wasi:cli/stdout@0.3.0; - import wasi:cli/stderr@0.3.0; + import wasi:cli/stdout@0.3.1; + import wasi:cli/stderr@0.3.1; /// TODO: this is a temporary workaround until component tooling is able to /// gracefully handle the absence of stdin. Hosts must return an eof stream /// for this import, which is what wasi-libc + tooling will do automatically /// when this import is properly removed. - import wasi:cli/stdin@0.3.0; + import wasi:cli/stdin@0.3.1; /// This is the default `client` to use when user code simply wants to make an /// HTTP request (e.g., via `fetch()`). diff --git a/proposals/random/imports.md b/proposals/random/imports.md new file mode 100644 index 00000000..8ecac0b5 --- /dev/null +++ b/proposals/random/imports.md @@ -0,0 +1,109 @@ +

World imports

+ +

Import interface wasi:random/random@0.3.1

+

WASI Random is a random data API.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-random-bytes: func

+

Return up to max-len cryptographically-secure random or pseudo-random +bytes.

+

This function must produce data at least as cryptographically secure and +fast as an adequately seeded cryptographically-secure pseudo-random +number generator (CSPRNG). It must not block, from the perspective of +the calling program, under any circumstances, including on the first +request and on requests for numbers of bytes. The returned data must +always be unpredictable.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+

This function must always return fresh data. Deterministic environments +must omit this function, rather than implementing it with deterministic +data.

+
Params
+ +
Return values
+ +

get-random-u64: func

+

Return a cryptographically-secure random or pseudo-random u64 value.

+

This function returns the same type of data as get-random-bytes, +represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure@0.3.1

+

The insecure interface for insecure pseudo-random numbers.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-random-bytes: func

+

Return up to max-len insecure pseudo-random bytes.

+

This function is not cryptographically secure. Do not use it for +anything related to security.

+

There are no requirements on the values of the returned bytes, however +implementations are encouraged to return evenly distributed values with +a long period.

+

Implementations MAY return fewer bytes than requested (a short read). +Callers that require exactly max-len bytes MUST call this function in +a loop until the desired number of bytes has been accumulated. +Implementations MUST return at least 1 byte when max-len is greater +than zero. When max-len is zero, implementations MUST return an empty +list without trapping.

+
Params
+ +
Return values
+ +

get-insecure-random-u64: func

+

Return an insecure pseudo-random u64 value.

+

This function returns the same type of pseudo-random data as +get-insecure-random-bytes, represented as a u64.

+
Return values
+ +

Import interface wasi:random/insecure-seed@0.3.1

+

The insecure-seed interface for seeding hash-map DoS resistance.

+

It is intended to be portable at least between Unix-family platforms and +Windows.

+
+

Functions

+

get-insecure-seed: func

+

Return a 128-bit value that may contain a pseudo-random value.

+

The returned value is not required to be computed from a CSPRNG, and may +even be entirely deterministic. Host implementations are encouraged to +provide pseudo-random values to any program exposed to +attacker-controlled content, to enable DoS protection built into many +languages' hash-map implementations.

+

This function is intended to only be called once, by a source language +to initialize Denial Of Service (DoS) protection in its hash-map +implementation.

+

Expected future evolution

+

This will likely be changed to a value import, to prevent it from being +called multiple times and potentially used for purposes other than DoS +protection.

+
Return values
+ diff --git a/proposals/random/wit/insecure-seed.wit b/proposals/random/wit/insecure-seed.wit index 86c988c2..5442acb9 100644 --- a/proposals/random/wit/insecure-seed.wit +++ b/proposals/random/wit/insecure-seed.wit @@ -1,4 +1,4 @@ -package wasi:random@0.3.0; +package wasi:random@0.3.1; /// The insecure-seed interface for seeding hash-map DoS resistance. /// /// It is intended to be portable at least between Unix-family platforms and diff --git a/proposals/random/wit/insecure.wit b/proposals/random/wit/insecure.wit index 73026f7e..2332118e 100644 --- a/proposals/random/wit/insecure.wit +++ b/proposals/random/wit/insecure.wit @@ -1,4 +1,4 @@ -package wasi:random@0.3.0; +package wasi:random@0.3.1; /// The insecure interface for insecure pseudo-random numbers. /// /// It is intended to be portable at least between Unix-family platforms and diff --git a/proposals/random/wit/random.wit b/proposals/random/wit/random.wit index a7fdee94..f16e3ff7 100644 --- a/proposals/random/wit/random.wit +++ b/proposals/random/wit/random.wit @@ -1,4 +1,4 @@ -package wasi:random@0.3.0; +package wasi:random@0.3.1; /// WASI Random is a random data API. /// /// It is intended to be portable at least between Unix-family platforms and diff --git a/proposals/random/wit/world.wit b/proposals/random/wit/world.wit index 838d3802..25d7dfdb 100644 --- a/proposals/random/wit/world.wit +++ b/proposals/random/wit/world.wit @@ -1,4 +1,4 @@ -package wasi:random@0.3.0; +package wasi:random@0.3.1; @since(version = 0.3.0) world imports { diff --git a/proposals/sockets/imports.md b/proposals/sockets/imports.md new file mode 100644 index 00000000..8e744aa7 --- /dev/null +++ b/proposals/sockets/imports.md @@ -0,0 +1,1188 @@ +

World imports

+ +

Import interface wasi:clocks/types@0.3.1

+

This interface common types used throughout wasi:clocks.

+
+

Types

+

type duration

+

u64

+

A duration of time, in nanoseconds. +

Import interface wasi:sockets/types@0.3.1

+
+

Types

+

type duration

+

duration

+

+

variant error-code

+

Error codes.

+

In theory, every API can return any error code. +In practice, API's typically only return the errors documented per API +combined with a couple of errors that are always possible:

+ +

See each individual API for what the POSIX equivalents are. They sometimes differ per API.

+
Variant Cases
+ +

enum ip-address-family

+
Enum Cases
+ +

tuple ipv4-address

+
Tuple Fields
+ +

tuple ipv6-address

+
Tuple Fields
+ +

variant ip-address

+
Variant Cases
+ +

record ipv4-socket-address

+
Record Fields
+ +

record ipv6-socket-address

+
Record Fields
+ +

variant ip-socket-address

+
Variant Cases
+ +

resource tcp-socket

+

A TCP socket resource.

+

The socket can be in one of the following states:

+ +

Note: Except where explicitly mentioned, whenever this documentation uses +the term "bound" without backticks it actually means: in the bound state or higher. +(i.e. bound, listening, connecting or connected)

+

WASI uses shared ownership semantics: the tcp-socket handle and all +derived stream and future values reference a single underlying OS +socket:

+ +

The OS socket is closed only after the last handle is dropped. This +model has observable effects; for example, it affects when the local +port binding is released.

+

In addition to the general error codes documented on the +types::error-code type, TCP socket methods may always return +error(invalid-state) when in the closed state.

+

resource udp-socket

+

A UDP socket handle.

+

Functions

+

[static]tcp-socket.create: func

+

Create a new TCP socket.

+

Similar to socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP) +in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and +can't be configured otherwise.

+

Unlike POSIX, WASI sockets have no notion of a socket-level +O_NONBLOCK flag. Instead they fully rely on the Component Model's +async support.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.bind: func

+

Bind the socket to the provided IP address and port.

+

If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is +left to the implementation to decide which network interface(s) to +bind to. If the TCP/UDP port is zero, the socket will be bound to a +random free port.

+

Bind can be attempted multiple times on the same socket, even with +different arguments on each iteration. But never concurrently and +only as long as the previous bind failed. Once a bind succeeds, the +binding can't be changed anymore.

+

Typical errors

+ +

Implementors note

+

The bind operation shouldn't be affected by the TIME_WAIT state of a +recently closed socket on the same local address. In practice this +means that the SO_REUSEADDR socket option should be set implicitly +on all platforms, except on Windows where this is the default +behavior and SO_REUSEADDR performs something different.

+

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.connect: func

+

Connect to a remote endpoint.

+

On success, the socket is transitioned into the connected state +and the remote-address of the socket is updated. +The local-address may be updated as well, based on the best network +path to remote-address. If the socket was not already explicitly +bound, this function will implicitly bind the socket to a random +free port.

+

After a failed connection attempt, the socket will be in the closed +state and the only valid action left is to drop the socket. A single +socket can not be used to connect more than once.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.listen: func

+

Start listening and return a stream of new inbound connections.

+

Transitions the socket into the listening state. This can be called +at most once per socket.

+

If the socket is not already explicitly bound, this function will +implicitly bind the socket to a random free port.

+

Normally, the returned sockets are bound, in the connected state +and immediately ready for I/O. Though, depending on exact timing and +circumstances, a newly accepted connection may already be closed +by the time the server attempts to perform its first I/O on it. This +is true regardless of whether the WASI implementation uses +"synthesized" sockets or not (see Implementors Notes below).

+

The following properties are inherited from the listener socket:

+ +

Typical errors

+ +

Implementors note

+

This method returns a single perpetual stream that should only close +on fatal errors (if any). Yet, the POSIX' accept function may also +return transient errors (e.g. ECONNABORTED). The exact details differ +per operation system. For example, the Linux manual mentions:

+
+

Linux accept() passes already-pending network errors on the new +socket as an error code from accept(). This behavior differs from +other BSD socket implementations. For reliable operation the +application should detect the network errors defined for the +protocol after accept() and treat them like EAGAIN by retrying. +In the case of TCP/IP, these are ENETDOWN, EPROTO, ENOPROTOOPT, +EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH. +Source: https://man7.org/linux/man-pages/man2/accept.2.html

+
+

WASI implementations have two options to handle this:

+ +

In either case, the stream returned by this listen method remains +operational.

+

WASI requires listen to perform an implicit bind if the socket +has not already been bound. Not all platforms (notably Windows) +exhibit this behavior out of the box. On platforms that require it, +the WASI implementation can emulate this behavior by performing +the bind itself if the guest hasn't already done so.

+

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.send: func

+

Transmit data to peer.

+

The caller should close the stream when it has no more data to send +to the peer. Under normal circumstances this will cause a FIN packet +to be sent out. Closing the stream is equivalent to calling +shutdown(SHUT_WR) in POSIX.

+

This function may be called at most once and returns once the full +contents of the stream are transmitted or an error is encountered.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.receive: func

+

Read data from peer.

+

Returns a stream of data sent by the peer. The implementation +drops the stream once no more data is available. At that point, the +returned future resolves to:

+ +

receive may be called only once per socket. Subsequent calls return +a closed stream and a future resolved to err(invalid-state).

+

If the caller is not expecting to receive any more data from the peer, +they should drop the stream. Any data still in the receive queue +will be discarded. This is equivalent to calling shutdown(SHUT_RD) +in POSIX.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-local-address: func

+

Get the bound local address.

+

POSIX mentions:

+
+

If the socket has not been bound to a local name, the value +stored in the object pointed to by address is unspecified.

+
+

WASI is stricter and requires get-local-address to return +invalid-state when the socket hasn't been bound yet.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-remote-address: func

+

Get the remote address.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-is-listening: func

+

Whether the socket is in the listening state.

+

Equivalent to the SO_ACCEPTCONN socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-address-family: func

+

Whether this is a IPv4 or IPv6 socket.

+

This is the value passed to the constructor.

+

Equivalent to the SO_DOMAIN socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-listen-backlog-size: func

+

Hints the desired listen queue size. Implementations are free to +ignore this.

+

If the provided value is 0, an invalid-argument error is returned. +Any other value will never cause an error, but it might be silently +clamped and/or rounded.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-enabled: func

+

Enables or disables keepalive.

+

The keepalive behavior can be adjusted using:

+ +

Equivalent to the SO_KEEPALIVE socket option.

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-enabled: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-idle-time: func

+

Amount of time the connection has to be idle before TCP starts +sending keepalive packets.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-idle-time: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-interval: func

+

The time between keepalive packets.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPINTVL socket option.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-interval: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-keep-alive-count: func

+

The maximum amount of keepalive packets TCP should send before +aborting the connection.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the TCP_KEEPCNT socket option.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-keep-alive-count: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-hop-limit: func

+

Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.

+

If the provided value is 0, an invalid-argument error is returned.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-hop-limit: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-receive-buffer-size: func

+

Kernel buffer space reserved for sending/receiving on this socket. +Implementations usually treat this as a cap the buffer can grow to, +rather than allocating the full amount immediately.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

This is only a performance hint. The implementation may ignore it or +tweak it based on real traffic patterns. +Linux and macOS appear to behave differently depending on whether a +buffer size was explicitly set. When set, they tend to honor it; when +not set, they dynamically adjust the buffer size as the connection +progresses. This is especially noticeable when comparing the values +from before and after connection establishment.

+

Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]tcp-socket.set-receive-buffer-size: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.get-send-buffer-size: func

+
Params
+ +
Return values
+ +

[method]tcp-socket.set-send-buffer-size: func

+
Params
+ +
Return values
+ +

[static]udp-socket.create: func

+

Create a new UDP socket.

+

Similar to socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP) +in POSIX. On IPv6 sockets, IPV6_V6ONLY is enabled by default and +can't be configured otherwise.

+

Unlike POSIX, WASI sockets have no notion of a socket-level +O_NONBLOCK flag. Instead they fully rely on the Component Model's +async support.

+

References:

+ +
Params
+ +
Return values
+ +

[method]udp-socket.bind: func

+

Bind the socket to the provided IP address and port.

+

If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is +left to the implementation to decide which network interface(s) to +bind to. If the port is zero, the socket will be bound to a random +free port.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.connect: func

+

Associate this socket with a specific peer address.

+

On success, the remote-address of the socket is updated. +The local-address may be updated as well, based on the best network +path to remote-address. If the socket was not already explicitly +bound, this function will implicitly bind the socket to a random +free port.

+

When a UDP socket is "connected", the send and receive methods +are limited to communicating with that peer only:

+ +

The name "connect" was kept to align with the existing POSIX +terminology. Other than that, this function only changes the local +socket configuration and does not generate any network traffic. +The peer is not aware of this "connection".

+

This method may be called multiple times on the same socket to change +its association, but only the most recent one will be effective.

+

Typical errors

+ +

Implementors note

+

If the socket is already connected, some platforms (e.g. Linux) +require a disconnect before connecting to a different peer address.

+

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.disconnect: func

+

Dissociate this socket from its peer address.

+

After calling this method, send & receive are free to communicate +with any remote address again.

+

The POSIX equivalent of this is calling connect with an AF_UNSPEC address.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.send: func

+

Send a message on the socket to a particular peer.

+

If the socket is connected, the peer address may be left empty. In +that case this is equivalent to send in POSIX. Otherwise it is +equivalent to sendto.

+

Additionally, if the socket is connected, a remote-address argument +may be provided but then it must be identical to the address +passed to connect.

+

If the socket has not been explicitly bound, it will be +implicitly bound to a random free port.

+

Implementations may trap if the data length exceeds 64 KiB.

+

Typical errors

+ +

Implementors note

+

WASI requires send to perform an implicit bind if the socket +has not been bound. Not all platforms (notably Windows) exhibit +this behavior natively. On such platforms, the WASI implementation +should emulate it by performing the bind if the guest has not +already done so.

+

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.receive: func

+

Receive a message on the socket.

+

On success, the return value contains a tuple of the received data +and the address of the sender. Theoretical maximum length of the +data is 64 KiB. Though in practice, it will typically be less than +1500 bytes.

+

If the socket is connected, the sender address is guaranteed to +match the remote address passed to connect.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-local-address: func

+

Get the current bound address.

+

POSIX mentions:

+
+

If the socket has not been bound to a local name, the value +stored in the object pointed to by address is unspecified.

+
+

WASI is stricter and requires get-local-address to return +invalid-state when the socket hasn't been bound yet.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-remote-address: func

+

Get the address the socket is currently "connected" to.

+

Typical errors

+ +

References

+ +
Params
+ +
Return values
+ +

[method]udp-socket.get-address-family: func

+

Whether this is a IPv4 or IPv6 socket.

+

This is the value passed to the constructor.

+

Equivalent to the SO_DOMAIN socket option.

+
Params
+ +
Return values
+ +

[method]udp-socket.get-unicast-hop-limit: func

+

Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.

+

If the provided value is 0, an invalid-argument error is returned.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]udp-socket.set-unicast-hop-limit: func

+
Params
+ +
Return values
+ +

[method]udp-socket.get-receive-buffer-size: func

+

Kernel buffer space reserved for sending/receiving on this socket. +Implementations usually treat this as a cap the buffer can grow to, +rather than allocating the full amount immediately.

+

If the provided value is 0, an invalid-argument error is returned. +All other values are accepted without error, but may be +clamped or rounded. As a result, the value read back from +this setting may differ from the value that was set.

+

Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.

+

Typical errors

+ +
Params
+ +
Return values
+ +

[method]udp-socket.set-receive-buffer-size: func

+
Params
+ +
Return values
+ +

[method]udp-socket.get-send-buffer-size: func

+
Params
+ +
Return values
+ +

[method]udp-socket.set-send-buffer-size: func

+
Params
+ +
Return values
+ +

Import interface wasi:sockets/ip-name-lookup@0.3.1

+
+

Types

+

type ip-address

+

ip-address

+

+

variant error-code

+

Lookup error codes.

+
Variant Cases
+ +
+

Functions

+

resolve-addresses: func

+

Resolve an internet host name to a list of IP addresses.

+

Unicode domain names are automatically converted to ASCII using IDNA +encoding. If the input is an IP address string, the address is parsed +and returned as-is without making any external requests.

+

See the wasi-socket proposal README.md for a comparison with getaddrinfo.

+

The results are returned in connection order preference.

+

This function never succeeds with 0 results. It either fails or succeeds +with at least one address. Additionally, this function never returns +IPv4-mapped IPv6 addresses.

+

References:

+ +
Params
+ +
Return values
+ diff --git a/proposals/sockets/wit/deps.lock b/proposals/sockets/wit/deps.lock index 7e6404b9..800f564b 100644 --- a/proposals/sockets/wit/deps.lock +++ b/proposals/sockets/wit/deps.lock @@ -1,4 +1,4 @@ [clocks] path = "../../clocks/wit" -sha256 = "2d288cb781c60ae462537b39e4699de38f88072b501fc7f97d3f20984d550bcf" -sha512 = "1563eeeacbfea89e44f668b8588ef95b31feac7d9ec3bb5dad932320478b1aff1448031f44afa15ed926981855ac5bd504126389ddb7802f79c63b81b3c5ede7" +sha256 = "cee7f7ffff62be2416295a0bbdc13d822f5b4449ce37e0eb7cbdf3195156429d" +sha512 = "446835d225349f00f44b8c47fb3e6189491cfc19fdf3b394e3edd85276e3f1d7a515efb318cd11ef271c164ec54a54307110f2d0b72212a0108324f449d9b946" diff --git a/proposals/sockets/wit/types.wit b/proposals/sockets/wit/types.wit index 7beaf7f8..5cc743a6 100644 --- a/proposals/sockets/wit/types.wit +++ b/proposals/sockets/wit/types.wit @@ -1,7 +1,7 @@ @since(version = 0.3.0) interface types { @since(version = 0.3.0) - use wasi:clocks/types@0.3.0.{duration}; + use wasi:clocks/types@0.3.1.{duration}; /// Error codes. /// diff --git a/proposals/sockets/wit/world.wit b/proposals/sockets/wit/world.wit index 6c9951d1..d23a53f2 100644 --- a/proposals/sockets/wit/world.wit +++ b/proposals/sockets/wit/world.wit @@ -1,4 +1,4 @@ -package wasi:sockets@0.3.0; +package wasi:sockets@0.3.1; @since(version = 0.3.0) world imports {