From d43dd24353ca27b739c5f819484fb35a424155c2 Mon Sep 17 00:00:00 2001 From: ricochet <974323+ricochet@users.noreply.github.com> Date: Tue, 11 Aug 2026 18:01:14 +0000 Subject: [PATCH] Release WASI v0.3.1 --- proposals/cli/command.md | 2524 ++++++++++++++++++++++ proposals/cli/imports.md | 2510 +++++++++++++++++++++ proposals/cli/wit/command.wit | 2 +- proposals/cli/wit/deps.lock | 16 +- proposals/cli/wit/imports.wit | 10 +- proposals/clocks/imports.md | 168 ++ proposals/clocks/wit/monotonic-clock.wit | 2 +- proposals/clocks/wit/system-clock.wit | 2 +- proposals/clocks/wit/timezone.wit | 2 +- proposals/clocks/wit/types.wit | 2 +- proposals/clocks/wit/world.wit | 2 +- proposals/filesystem/imports.md | 917 ++++++++ proposals/filesystem/wit/deps.lock | 4 +- proposals/filesystem/wit/preopens.wit | 2 +- proposals/filesystem/wit/types.wit | 4 +- proposals/filesystem/wit/world.wit | 2 +- proposals/http/middleware.md | 1146 ++++++++++ proposals/http/service.md | 1113 ++++++++++ proposals/http/wit/deps.lock | 20 +- proposals/http/wit/types.wit | 4 +- proposals/http/wit/worlds.wit | 12 +- proposals/random/imports.md | 109 + proposals/random/wit/insecure-seed.wit | 2 +- proposals/random/wit/insecure.wit | 2 +- proposals/random/wit/random.wit | 2 +- proposals/random/wit/world.wit | 2 +- proposals/sockets/imports.md | 1188 ++++++++++ proposals/sockets/wit/deps.lock | 4 +- proposals/sockets/wit/types.wit | 2 +- proposals/sockets/wit/world.wit | 2 +- 30 files changed, 9726 insertions(+), 51 deletions(-) create mode 100644 proposals/cli/command.md create mode 100644 proposals/cli/imports.md create mode 100644 proposals/clocks/imports.md create mode 100644 proposals/filesystem/imports.md create mode 100644 proposals/http/middleware.md create mode 100644 proposals/http/service.md create mode 100644 proposals/random/imports.md create mode 100644 proposals/sockets/imports.md diff --git a/proposals/cli/command.md b/proposals/cli/command.md new file mode 100644 index 000000000..006b06fdb --- /dev/null +++ b/proposals/cli/command.md @@ -0,0 +1,2524 @@ +
wasi:cli/environment@0.3.1wasi:cli/exit@0.3.1wasi:cli/types@0.3.1wasi:cli/stdin@0.3.1wasi:cli/stdout@0.3.1wasi:cli/stderr@0.3.1wasi:cli/terminal-input@0.3.1wasi:cli/terminal-output@0.3.1wasi:cli/terminal-stdin@0.3.1wasi:cli/terminal-stdout@0.3.1wasi:cli/terminal-stderr@0.3.1wasi:clocks/types@0.3.1wasi:clocks/monotonic-clock@0.3.1wasi:clocks/system-clock@0.3.1wasi:clocks/timezone@0.3.1wasi:filesystem/types@0.3.1wasi:filesystem/preopens@0.3.1wasi:sockets/types@0.3.1wasi:sockets/ip-name-lookup@0.3.1wasi:random/random@0.3.1wasi:random/insecure@0.3.1wasi:random/insecure-seed@0.3.1wasi:cli/run@0.3.1get-environment: funcGet 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.
+get-arguments: funcGet the POSIX-style arguments to the program.
+get-initial-cwd: funcReturn a path that programs should use as their initial current working
+directory, interpreting . as shorthand for this.
exit: funcExit the current instance and any linked instances.
+exit-with-code: funcExit 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.
+enum error-codeInput/output error +
Invalid or incomplete multibyte or wide character +
Broken pipe +
type error-code+
read-via-stream: funcReturn 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.
+u8>, future<result<_, error-code>>)type error-code+
write-via-stream: funcWrite 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.
+error-code>>type error-code+
write-via-stream: funcWrite 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.
+error-code>>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.
+resource terminal-inputThe input side of a terminal.
+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.
+resource terminal-outputThe output side of a terminal.
+An interface providing an optional terminal-input for stdin as a
+link-time authority.
type terminal-input+
get-terminal-stdin: funcIf stdin is connected to a terminal, return a terminal-input handle
+allowing further interaction with it.
terminal-input>>An interface providing an optional terminal-output for stdout as a
+link-time authority.
type terminal-output+
get-terminal-stdout: funcIf stdout is connected to a terminal, return a terminal-output handle
+allowing further interaction with it.
terminal-output>>An interface providing an optional terminal-output for stderr as a
+link-time authority.
type terminal-output+
get-terminal-stderr: funcIf stderr is connected to a terminal, return a terminal-output handle
+allowing further interaction with it.
terminal-output>>This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
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.
+type duration+
type marku64
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. +
now: funcRead 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.
markget-resolution: funcQuery the resolution of the clock. Returns the duration of time +corresponding to a clock tick.
+durationwait-until: funcWait until the specified mark has occurred.
+when: markwait-for: funcWait for the specified duration to elapse.
+how-long: durationWASI 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.
+type duration+
record instantAn "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
now: funcRead 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.
+instantget-resolution: funcQuery the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.
+durationtype instant+
iana-id: funcReturn 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.
+utc-offset: funcThe 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.
+when: instantto-debug-string: funcReturns 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.
+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.
+type instant+
type filesizeu64
File size or length of a region within a file. +
variant descriptor-typeThe type of a filesystem object referenced by a descriptor.
+Note: This was called filetype in earlier versions of WASI.
The descriptor refers to a block device inode. +
The descriptor refers to a character device inode. +
The descriptor refers to a directory inode. +
The descriptor refers to a named pipe. +
The file refers to a symbolic link inode. +
The descriptor refers to a regular file inode. +
The descriptor refers to a socket. +
The type of the descriptor or file is different from any of the +other types specified. +
flags descriptor-flagsDescriptor flags.
+Note: This was called fdflags in earlier versions of WASI.
Read mode: Data can be read. +
Write mode: Data can be written to. +
Request that writes be performed according to synchronized I/O file +integrity completion. The data stored in the file and the file's +metadata are synchronized. This is similar to `O_SYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Request that writes be performed according to synchronized I/O data +integrity completion. Only the data stored in the file is +synchronized. This is similar to `O_DSYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Requests that reads be performed at the same level of integrity +requested for writes. This is similar to `O_RSYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Mutating directories mode: Directory contents may be mutated. +
When this flag is unset on a descriptor, operations using the
+descriptor which would create, rename, delete, modify the data or
+metadata of filesystem objects, or obtain another handle which
+would permit any of those, shall fail with error-code::read-only if
+they would otherwise succeed.
This may only be set on directories.
+flags path-flagsFlags determining the method of how paths are resolved.
+flags open-flagsOpen flags used by open-at.
Create file if it does not exist, similar to `O_CREAT` in POSIX. +
Fail if not a directory, similar to `O_DIRECTORY` in POSIX. +
Fail if file already exists, similar to `O_EXCL` in POSIX. +
Truncate file to size 0, similar to `O_TRUNC` in POSIX. +
type link-countu64
Number of hard links to an inode. +
record descriptor-statFile attributes.
+Note: This was called filestat in earlier versions of WASI.
type: descriptor-type
File type. +
Number of hard links to the file. +
size: filesize
For regular files, the file size in bytes. For symbolic links, the +length in bytes of the pathname contained in the symbolic link. +
data-access-timestamp: option<instant>
Last data access timestamp. +
If the option is none, the platform doesn't maintain an access
+timestamp for this file.
data-modification-timestamp: option<instant>
Last data modification timestamp. +
If the option is none, the platform doesn't maintain a
+modification timestamp for this file.
status-change-timestamp: option<instant>
Last file status-change timestamp. +
If the option is none, the platform doesn't maintain a
+status-change timestamp for this file.
variant new-timestampWhen setting a timestamp, this gives the value to set it to.
+Leave the timestamp set to its previous value. +
Set the timestamp to the current time of the system clock associated +with the filesystem. +
timestamp: instant
Set the timestamp to the given value. +
record directory-entryA directory entry.
+type: descriptor-type
The type of the file referred to by this directory entry. +
The name of the object. +
variant error-codeError 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.
Permission denied, similar to `EACCES` in POSIX. +
Connection already in progress, similar to `EALREADY` in POSIX. +
Bad descriptor, similar to `EBADF` in POSIX. +
Device or resource busy, similar to `EBUSY` in POSIX. +
Resource deadlock would occur, similar to `EDEADLK` in POSIX. +
Storage quota exceeded, similar to `EDQUOT` in POSIX. +
File exists, similar to `EEXIST` in POSIX. +
File too large, similar to `EFBIG` in POSIX. +
Illegal byte sequence, similar to `EILSEQ` in POSIX. +
Operation in progress, similar to `EINPROGRESS` in POSIX. +
Interrupted function, similar to `EINTR` in POSIX. +
Invalid argument, similar to `EINVAL` in POSIX. +
I/O error, similar to `EIO` in POSIX. +
Is a directory, similar to `EISDIR` in POSIX. +
Too many levels of symbolic links, similar to `ELOOP` in POSIX. +
Too many links, similar to `EMLINK` in POSIX. +
Message too large, similar to `EMSGSIZE` in POSIX. +
Filename too long, similar to `ENAMETOOLONG` in POSIX. +
No such device, similar to `ENODEV` in POSIX. +
No such file or directory, similar to `ENOENT` in POSIX. +
No locks available, similar to `ENOLCK` in POSIX. +
Not enough space, similar to `ENOMEM` in POSIX. +
No space left on device, similar to `ENOSPC` in POSIX. +
Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. +
Directory not empty, similar to `ENOTEMPTY` in POSIX. +
State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. +
Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. +
Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. +
No such device or address, similar to `ENXIO` in POSIX. +
Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. +
Operation not permitted, similar to `EPERM` in POSIX. +
Broken pipe, similar to `EPIPE` in POSIX. +
Read-only file system, similar to `EROFS` in POSIX. +
Invalid seek, similar to `ESPIPE` in POSIX. +
Text file busy, similar to `ETXTBSY` in POSIX. +
Cross-device link, similar to `EXDEV` in POSIX. +
A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
enum adviceFile or memory access pattern advisory information.
+The application has no advice to give on its behavior with respect +to the specified data. +
The application expects to access the specified data sequentially +from lower offsets to higher offsets. +
The application expects to access the specified data in a random +order. +
The application expects to access the specified data in the near +future. +
The application expects that it will not access the specified data +in the near future. +
The application expects to access the specified data once and then +not reuse it thereafter. +
record metadata-hash-valueA 128-bit hash value, split into parts because wasm doesn't have a +128-bit integer type.
+64 bits of a 128-bit hash value. +
Another 64 bits of a 128-bit hash value. +
resource descriptor[method]descriptor.read-via-stream: funcReturn 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.
self: borrow<descriptor>offset: filesizeu8>, future<result<_, error-code>>)[method]descriptor.write-via-stream: funcReturn 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.
self: borrow<descriptor>data: stream<u8>offset: filesizeerror-code>>[method]descriptor.append-via-stream: funcReturn 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.
self: borrow<descriptor>data: stream<u8>error-code>>[method]descriptor.advise: funcProvide file advisory information on a descriptor.
+This is similar to posix_fadvise in POSIX.
self: borrow<descriptor>offset: filesizelength: filesizeadvice: adviceerror-code>[method]descriptor.sync-data: funcSynchronize 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.
self: borrow<descriptor>error-code>[method]descriptor.get-flags: funcGet 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.
self: borrow<descriptor>descriptor-flags, error-code>[method]descriptor.get-type: funcGet 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.
self: borrow<descriptor>descriptor-type, error-code>[method]descriptor.set-size: funcAdjust 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.
self: borrow<descriptor>size: filesizeerror-code>[method]descriptor.set-times: funcAdjust 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.
self: borrow<descriptor>data-access-timestamp: new-timestampdata-modification-timestamp: new-timestamperror-code>[method]descriptor.read-directory: funcRead 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.
+self: borrow<descriptor>directory-entry>, future<result<_, error-code>>)[method]descriptor.sync: funcSynchronize 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.
self: borrow<descriptor>error-code>[method]descriptor.create-directory-at: funcCreate a directory.
+Note: This is similar to mkdirat in POSIX.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.stat: funcReturn 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.
self: borrow<descriptor>descriptor-stat, error-code>[method]descriptor.stat-at: funcReturn 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.
self: borrow<descriptor>path-flags: path-flagspath: stringdescriptor-stat, error-code>[method]descriptor.set-times-at: funcAdjust 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.
self: borrow<descriptor>path-flags: path-flagspath: stringdata-access-timestamp: new-timestampdata-modification-timestamp: new-timestamperror-code>[method]descriptor.link-at: funcCreate 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.
self: borrow<descriptor>old-path-flags: path-flagsold-path: stringnew-descriptor: borrow<descriptor>new-path: stringerror-code>[method]descriptor.open-at: funcOpen 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.
self: borrow<descriptor>path-flags: path-flagspath: stringopen-flags: open-flagsflags: descriptor-flagsdescriptor>, error-code>[method]descriptor.readlink-at: funcRead 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.
self: borrow<descriptor>path: stringstring, error-code>[method]descriptor.remove-directory-at: funcRemove 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.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.rename-at: funcRename a filesystem object.
+Note: This is similar to renameat in POSIX.
self: borrow<descriptor>old-path: stringnew-descriptor: borrow<descriptor>new-path: stringerror-code>[method]descriptor.symlink-at: funcCreate 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.
self: borrow<descriptor>old-path: stringnew-path: stringerror-code>[method]descriptor.unlink-file-at: funcUnlink 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.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.is-same-object: funcTest 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.
self: borrow<descriptor>other: borrow<descriptor>[method]descriptor.metadata-hash: funcReturn 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.
+self: borrow<descriptor>metadata-hash-value, error-code>[method]descriptor.metadata-hash-at: funcReturn 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.
self: borrow<descriptor>path-flags: path-flagspath: stringmetadata-hash-value, error-code>type descriptor+
get-directories: funcReturn the set of preopened directories, and their paths.
+descriptor>, string)>type duration+
variant error-codeError 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:
+otheraccess-deniednot-supportedout-of-memorySee each individual API for what the POSIX equivalents are. They sometimes differ per API.
+Access denied. +
POSIX equivalent: EACCES, EPERM
+The operation is not supported. +
POSIX equivalent: EOPNOTSUPP, ENOPROTOOPT, EPFNOSUPPORT, EPROTONOSUPPORT, ESOCKTNOSUPPORT
+One of the arguments is invalid. +
POSIX equivalent: EINVAL, EDESTADDRREQ, EAFNOSUPPORT
+Not enough memory to complete the operation. +
POSIX equivalent: ENOMEM, ENOBUFS
+The operation timed out before it could finish completely. +
POSIX equivalent: ETIMEDOUT
+The operation is not valid in the socket's current state. +
The local address is not available. +
POSIX equivalent: EADDRNOTAVAIL
+A bind operation failed because the provided address is already in +use or because there are no ephemeral ports available. +
POSIX equivalent: EADDRINUSE
+The remote address is not reachable. +
POSIX equivalent: EHOSTUNREACH, EHOSTDOWN, ENETDOWN, ENETUNREACH, ENONET
+The connection was forcefully rejected. +
POSIX equivalent: ECONNREFUSED
+A write failed because the connection was broken. +
POSIX equivalent: EPIPE
+The connection was reset. +
POSIX equivalent: ECONNRESET
+The connection was aborted. +
POSIX equivalent: ECONNABORTED
+The size of a datagram sent to a UDP socket exceeded the maximum +supported size. +
POSIX equivalent: EMSGSIZE
+A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
enum ip-address-familytuple ipv4-addresstuple ipv6-addressvariant ip-addressipv4: ipv4-addressipv6: ipv6-addressrecord ipv4-socket-addresssin_port +
address: ipv4-address
sin_addr +
record ipv6-socket-addresssin6_port +
sin6_flowinfo +
address: ipv6-address
sin6_addr +
sin6_scope_id +
variant ip-socket-addressipv4: ipv4-socket-addressipv6: ipv6-socket-addressresource tcp-socketA TCP socket resource.
+The socket can be in one of the following states:
+unboundbound (See note below)listeningconnectingconnectedclosed
+See https://github.com/WebAssembly/WASI/blob/main/proposals/sockets/TcpSocketOperationalSemantics-0.3.0.md
+for more information.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:
tcp-socket
+handle is dropped.listen behaves similarly.tcp-socket::listen are independent and do
+not keep the listening socket alive.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[static]tcp-socket.create: funcCreate 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.
not-supported: The address-family is not supported. (EAFNOSUPPORT)address-family: ip-address-familytcp-socket>, error-code>[method]tcp-socket.bind: funcBind 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.
+invalid-argument: The local-address has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-argument: local-address is not a unicast address. (EINVAL)invalid-argument: local-address is an IPv4-mapped IPv6 address. (EINVAL)invalid-state: The socket is already bound. (EINVAL)address-in-use: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use: Address is already in use. (EADDRINUSE)address-not-bindable: local-address is not an address that can be bound to. (EADDRNOTAVAIL)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.
+self: borrow<tcp-socket>local-address: ip-socket-addresserror-code>[method]tcp-socket.connect: funcConnect 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.
invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: remote-address is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)invalid-argument: remote-address is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EADDRNOTAVAIL on Windows)invalid-argument: The port in remote-address is set to 0. (EADDRNOTAVAIL on Windows)invalid-state: The socket is already in the connecting state. (EALREADY)invalid-state: The socket is already in the connected state. (EISCONN)invalid-state: The socket is already in the listening state. (EOPNOTSUPP, EINVAL on Windows)timeout: Connection timed out. (ETIMEDOUT)connection-refused: The connection was forcefully rejected. (ECONNREFUSED)connection-reset: The connection was reset. (ECONNRESET)connection-aborted: The connection was aborted. (ECONNABORTED)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)self: borrow<tcp-socket>remote-address: ip-socket-addresserror-code>[method]tcp-socket.listen: funcStart 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:
+address-familykeep-alive-enabledkeep-alive-idle-timekeep-alive-intervalkeep-alive-counthop-limitreceive-buffer-sizesend-buffer-sizeinvalid-state: The socket is already in the connected state. (EISCONN, EINVAL on BSD)invalid-state: The socket is already in the listening state.address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)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:
+accept. Guest code never gets to see these failures. Or:tcp-socket resource that exposes the error when
+attempting to send or receive on it. Guest code then sees these
+failures as regular I/O errors.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.
self: borrow<tcp-socket>tcp-socket>>, error-code>[method]tcp-socket.send: funcTransmit 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.
+invalid-state: The socket is not in the connected state. (ENOTCONN)invalid-state: send has already been called on this socket.connection-broken: The connection is not writable anymore. (EPIPE, ECONNABORTED on Windows)connection-reset: The connection was reset. (ECONNRESET)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)self: borrow<tcp-socket>data: stream<u8>error-code>>[method]tcp-socket.receive: funcRead 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:
ok after a graceful shutdown from the peer (i.e. a FIN packet), orerr if the socket was closed abnormally.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.
invalid-state: The socket is not in the connected state. (ENOTCONN)invalid-state: receive has already been called on this socket.connection-reset: The connection was reset. (ECONNRESET)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)self: borrow<tcp-socket>u8>, future<result<_, error-code>>)[method]tcp-socket.get-local-address: funcGet 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
+addressis unspecified.
WASI is stricter and requires get-local-address to return
+invalid-state when the socket hasn't been bound yet.
invalid-state: The socket is not bound to any local address.self: borrow<tcp-socket>ip-socket-address, error-code>[method]tcp-socket.get-remote-address: funcGet the remote address.
+invalid-state: The socket is not connected to a remote address. (ENOTCONN)self: borrow<tcp-socket>ip-socket-address, error-code>[method]tcp-socket.get-is-listening: funcWhether the socket is in the listening state.
Equivalent to the SO_ACCEPTCONN socket option.
+self: borrow<tcp-socket>[method]tcp-socket.get-address-family: funcWhether this is a IPv4 or IPv6 socket.
+This is the value passed to the constructor.
+Equivalent to the SO_DOMAIN socket option.
+self: borrow<tcp-socket>[method]tcp-socket.set-listen-backlog-size: funcHints 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.
not-supported: (set) The platform does not support changing the backlog size after the initial listen.invalid-argument: (set) The provided value was 0.invalid-state: (set) The socket is in the connecting or connected state.self: borrow<tcp-socket>value: u64error-code>[method]tcp-socket.get-keep-alive-enabled: funcEnables or disables keepalive.
+The keepalive behavior can be adjusted using:
+keep-alive-idle-timekeep-alive-intervalkeep-alive-count
+These properties can be configured while keep-alive-enabled is
+false, but only come into effect when keep-alive-enabled is true.Equivalent to the SO_KEEPALIVE socket option.
+self: borrow<tcp-socket>bool, error-code>[method]tcp-socket.set-keep-alive-enabled: funcself: borrow<tcp-socket>value: boolerror-code>[method]tcp-socket.get-keep-alive-idle-time: funcAmount 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)
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>duration, error-code>[method]tcp-socket.set-keep-alive-idle-time: funcself: borrow<tcp-socket>value: durationerror-code>[method]tcp-socket.get-keep-alive-interval: funcThe 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>duration, error-code>[method]tcp-socket.set-keep-alive-interval: funcself: borrow<tcp-socket>value: durationerror-code>[method]tcp-socket.get-keep-alive-count: funcThe 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>u32, error-code>[method]tcp-socket.set-keep-alive-count: funcself: borrow<tcp-socket>value: u32error-code>[method]tcp-socket.get-hop-limit: funcEquivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
+If the provided value is 0, an invalid-argument error is returned.
invalid-argument: (set) The TTL value must be 1 or higher.self: borrow<tcp-socket>u8, error-code>[method]tcp-socket.set-hop-limit: funcself: borrow<tcp-socket>value: u8error-code>[method]tcp-socket.get-receive-buffer-size: funcKernel 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>u64, error-code>[method]tcp-socket.set-receive-buffer-size: funcself: borrow<tcp-socket>value: u64error-code>[method]tcp-socket.get-send-buffer-size: funcself: borrow<tcp-socket>u64, error-code>[method]tcp-socket.set-send-buffer-size: funcself: borrow<tcp-socket>value: u64error-code>[static]udp-socket.create: funcCreate 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.
address-family: ip-address-familyudp-socket>, error-code>[method]udp-socket.bind: funcBind 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.
invalid-argument: The local-address has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-state: The socket is already bound. (EINVAL)address-in-use: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use: Address is already in use. (EADDRINUSE)address-not-bindable: local-address is not an address that can be bound to. (EADDRNOTAVAIL)self: borrow<udp-socket>local-address: ip-socket-addresserror-code>[method]udp-socket.connect: funcAssociate 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:
send can only be used to send to this destination.receive will only return datagrams sent from the provided remote-address.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.
+invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)If the socket is already connected, some platforms (e.g. Linux) +require a disconnect before connecting to a different peer address.
+self: borrow<udp-socket>remote-address: ip-socket-addresserror-code>[method]udp-socket.disconnect: funcDissociate 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.
invalid-state: The socket is not connected.self: borrow<udp-socket>error-code>[method]udp-socket.send: funcSend 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.
invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The socket is in "connected" mode and remote-address is some value that does not match the address passed to connect. (EISCONN)invalid-argument: The socket is not "connected" and no value for remote-address was provided. (EDESTADDRREQ)remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)connection-refused: The connection was refused. (ECONNREFUSED)datagram-too-large: The datagram is too large. (EMSGSIZE)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)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.
self: borrow<udp-socket>data: list<u8>remote-address: option<ip-socket-address>error-code>[method]udp-socket.receive: funcReceive 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.
invalid-state: The socket has not been bound yet.remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)connection-refused: The connection was refused. (ECONNREFUSED)self: borrow<udp-socket>u8>, ip-socket-address), error-code>[method]udp-socket.get-local-address: funcGet 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
+addressis unspecified.
WASI is stricter and requires get-local-address to return
+invalid-state when the socket hasn't been bound yet.
invalid-state: The socket is not bound to any local address.self: borrow<udp-socket>ip-socket-address, error-code>[method]udp-socket.get-remote-address: funcGet the address the socket is currently "connected" to.
+invalid-state: The socket is not "connected" to a specific remote address. (ENOTCONN)self: borrow<udp-socket>ip-socket-address, error-code>[method]udp-socket.get-address-family: funcWhether this is a IPv4 or IPv6 socket.
+This is the value passed to the constructor.
+Equivalent to the SO_DOMAIN socket option.
+self: borrow<udp-socket>[method]udp-socket.get-unicast-hop-limit: funcEquivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
+If the provided value is 0, an invalid-argument error is returned.
invalid-argument: (set) The TTL value must be 1 or higher.self: borrow<udp-socket>u8, error-code>[method]udp-socket.set-unicast-hop-limit: funcself: borrow<udp-socket>value: u8error-code>[method]udp-socket.get-receive-buffer-size: funcKernel 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.
+invalid-argument: (set) The provided value was 0.self: borrow<udp-socket>u64, error-code>[method]udp-socket.set-receive-buffer-size: funcself: borrow<udp-socket>value: u64error-code>[method]udp-socket.get-send-buffer-size: funcself: borrow<udp-socket>u64, error-code>[method]udp-socket.set-send-buffer-size: funcself: borrow<udp-socket>value: u64error-code>type ip-address+
variant error-codeLookup error codes.
+Access denied. +
POSIX equivalent: EACCES, EPERM
+`name` is a syntactically invalid domain name or IP address. +
POSIX equivalent: EINVAL
+Name does not exist or has no suitable associated IP addresses. +
POSIX equivalent: EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY
+A temporary failure in name resolution occurred. +
POSIX equivalent: EAI_AGAIN
+A permanent failure in name resolution occurred. +
POSIX equivalent: EAI_FAIL
+A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
resolve-addresses: funcResolve 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.
+ip-address>, error-code>WASI Random is a random data API.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-random-bytes: funcReturn 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.
+get-random-u64: funcReturn 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.
The insecure interface for insecure pseudo-random numbers.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-random-bytes: funcReturn 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.
get-insecure-random-u64: funcReturn 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.
The insecure-seed interface for seeding hash-map DoS resistance.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-seed: funcReturn 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.
+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.
+run: funcRun the program.
+wasi:cli/environment@0.3.1wasi:cli/exit@0.3.1wasi:cli/types@0.3.1wasi:cli/stdin@0.3.1wasi:cli/stdout@0.3.1wasi:cli/stderr@0.3.1wasi:cli/terminal-input@0.3.1wasi:cli/terminal-output@0.3.1wasi:cli/terminal-stdin@0.3.1wasi:cli/terminal-stdout@0.3.1wasi:cli/terminal-stderr@0.3.1wasi:clocks/types@0.3.1wasi:clocks/monotonic-clock@0.3.1wasi:clocks/system-clock@0.3.1wasi:clocks/timezone@0.3.1wasi:filesystem/types@0.3.1wasi:filesystem/preopens@0.3.1wasi:sockets/types@0.3.1wasi:sockets/ip-name-lookup@0.3.1wasi:random/random@0.3.1wasi:random/insecure@0.3.1wasi:random/insecure-seed@0.3.1get-environment: funcGet 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.
+get-arguments: funcGet the POSIX-style arguments to the program.
+get-initial-cwd: funcReturn a path that programs should use as their initial current working
+directory, interpreting . as shorthand for this.
exit: funcExit the current instance and any linked instances.
+exit-with-code: funcExit 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.
+enum error-codeInput/output error +
Invalid or incomplete multibyte or wide character +
Broken pipe +
type error-code+
read-via-stream: funcReturn 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.
+u8>, future<result<_, error-code>>)type error-code+
write-via-stream: funcWrite 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.
+error-code>>type error-code+
write-via-stream: funcWrite 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.
+error-code>>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.
+resource terminal-inputThe input side of a terminal.
+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.
+resource terminal-outputThe output side of a terminal.
+An interface providing an optional terminal-input for stdin as a
+link-time authority.
type terminal-input+
get-terminal-stdin: funcIf stdin is connected to a terminal, return a terminal-input handle
+allowing further interaction with it.
terminal-input>>An interface providing an optional terminal-output for stdout as a
+link-time authority.
type terminal-output+
get-terminal-stdout: funcIf stdout is connected to a terminal, return a terminal-output handle
+allowing further interaction with it.
terminal-output>>An interface providing an optional terminal-output for stderr as a
+link-time authority.
type terminal-output+
get-terminal-stderr: funcIf stderr is connected to a terminal, return a terminal-output handle
+allowing further interaction with it.
terminal-output>>This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
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.
+type duration+
type marku64
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. +
now: funcRead 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.
markget-resolution: funcQuery the resolution of the clock. Returns the duration of time +corresponding to a clock tick.
+durationwait-until: funcWait until the specified mark has occurred.
+when: markwait-for: funcWait for the specified duration to elapse.
+how-long: durationWASI 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.
+type duration+
record instantAn "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
now: funcRead 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.
+instantget-resolution: funcQuery the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.
+durationtype instant+
iana-id: funcReturn 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.
+utc-offset: funcThe 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.
+when: instantto-debug-string: funcReturns 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.
+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.
+type instant+
type filesizeu64
File size or length of a region within a file. +
variant descriptor-typeThe type of a filesystem object referenced by a descriptor.
+Note: This was called filetype in earlier versions of WASI.
The descriptor refers to a block device inode. +
The descriptor refers to a character device inode. +
The descriptor refers to a directory inode. +
The descriptor refers to a named pipe. +
The file refers to a symbolic link inode. +
The descriptor refers to a regular file inode. +
The descriptor refers to a socket. +
The type of the descriptor or file is different from any of the +other types specified. +
flags descriptor-flagsDescriptor flags.
+Note: This was called fdflags in earlier versions of WASI.
Read mode: Data can be read. +
Write mode: Data can be written to. +
Request that writes be performed according to synchronized I/O file +integrity completion. The data stored in the file and the file's +metadata are synchronized. This is similar to `O_SYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Request that writes be performed according to synchronized I/O data +integrity completion. Only the data stored in the file is +synchronized. This is similar to `O_DSYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Requests that reads be performed at the same level of integrity +requested for writes. This is similar to `O_RSYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Mutating directories mode: Directory contents may be mutated. +
When this flag is unset on a descriptor, operations using the
+descriptor which would create, rename, delete, modify the data or
+metadata of filesystem objects, or obtain another handle which
+would permit any of those, shall fail with error-code::read-only if
+they would otherwise succeed.
This may only be set on directories.
+flags path-flagsFlags determining the method of how paths are resolved.
+flags open-flagsOpen flags used by open-at.
Create file if it does not exist, similar to `O_CREAT` in POSIX. +
Fail if not a directory, similar to `O_DIRECTORY` in POSIX. +
Fail if file already exists, similar to `O_EXCL` in POSIX. +
Truncate file to size 0, similar to `O_TRUNC` in POSIX. +
type link-countu64
Number of hard links to an inode. +
record descriptor-statFile attributes.
+Note: This was called filestat in earlier versions of WASI.
type: descriptor-type
File type. +
Number of hard links to the file. +
size: filesize
For regular files, the file size in bytes. For symbolic links, the +length in bytes of the pathname contained in the symbolic link. +
data-access-timestamp: option<instant>
Last data access timestamp. +
If the option is none, the platform doesn't maintain an access
+timestamp for this file.
data-modification-timestamp: option<instant>
Last data modification timestamp. +
If the option is none, the platform doesn't maintain a
+modification timestamp for this file.
status-change-timestamp: option<instant>
Last file status-change timestamp. +
If the option is none, the platform doesn't maintain a
+status-change timestamp for this file.
variant new-timestampWhen setting a timestamp, this gives the value to set it to.
+Leave the timestamp set to its previous value. +
Set the timestamp to the current time of the system clock associated +with the filesystem. +
timestamp: instant
Set the timestamp to the given value. +
record directory-entryA directory entry.
+type: descriptor-type
The type of the file referred to by this directory entry. +
The name of the object. +
variant error-codeError 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.
Permission denied, similar to `EACCES` in POSIX. +
Connection already in progress, similar to `EALREADY` in POSIX. +
Bad descriptor, similar to `EBADF` in POSIX. +
Device or resource busy, similar to `EBUSY` in POSIX. +
Resource deadlock would occur, similar to `EDEADLK` in POSIX. +
Storage quota exceeded, similar to `EDQUOT` in POSIX. +
File exists, similar to `EEXIST` in POSIX. +
File too large, similar to `EFBIG` in POSIX. +
Illegal byte sequence, similar to `EILSEQ` in POSIX. +
Operation in progress, similar to `EINPROGRESS` in POSIX. +
Interrupted function, similar to `EINTR` in POSIX. +
Invalid argument, similar to `EINVAL` in POSIX. +
I/O error, similar to `EIO` in POSIX. +
Is a directory, similar to `EISDIR` in POSIX. +
Too many levels of symbolic links, similar to `ELOOP` in POSIX. +
Too many links, similar to `EMLINK` in POSIX. +
Message too large, similar to `EMSGSIZE` in POSIX. +
Filename too long, similar to `ENAMETOOLONG` in POSIX. +
No such device, similar to `ENODEV` in POSIX. +
No such file or directory, similar to `ENOENT` in POSIX. +
No locks available, similar to `ENOLCK` in POSIX. +
Not enough space, similar to `ENOMEM` in POSIX. +
No space left on device, similar to `ENOSPC` in POSIX. +
Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. +
Directory not empty, similar to `ENOTEMPTY` in POSIX. +
State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. +
Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. +
Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. +
No such device or address, similar to `ENXIO` in POSIX. +
Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. +
Operation not permitted, similar to `EPERM` in POSIX. +
Broken pipe, similar to `EPIPE` in POSIX. +
Read-only file system, similar to `EROFS` in POSIX. +
Invalid seek, similar to `ESPIPE` in POSIX. +
Text file busy, similar to `ETXTBSY` in POSIX. +
Cross-device link, similar to `EXDEV` in POSIX. +
A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
enum adviceFile or memory access pattern advisory information.
+The application has no advice to give on its behavior with respect +to the specified data. +
The application expects to access the specified data sequentially +from lower offsets to higher offsets. +
The application expects to access the specified data in a random +order. +
The application expects to access the specified data in the near +future. +
The application expects that it will not access the specified data +in the near future. +
The application expects to access the specified data once and then +not reuse it thereafter. +
record metadata-hash-valueA 128-bit hash value, split into parts because wasm doesn't have a +128-bit integer type.
+64 bits of a 128-bit hash value. +
Another 64 bits of a 128-bit hash value. +
resource descriptor[method]descriptor.read-via-stream: funcReturn 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.
self: borrow<descriptor>offset: filesizeu8>, future<result<_, error-code>>)[method]descriptor.write-via-stream: funcReturn 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.
self: borrow<descriptor>data: stream<u8>offset: filesizeerror-code>>[method]descriptor.append-via-stream: funcReturn 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.
self: borrow<descriptor>data: stream<u8>error-code>>[method]descriptor.advise: funcProvide file advisory information on a descriptor.
+This is similar to posix_fadvise in POSIX.
self: borrow<descriptor>offset: filesizelength: filesizeadvice: adviceerror-code>[method]descriptor.sync-data: funcSynchronize 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.
self: borrow<descriptor>error-code>[method]descriptor.get-flags: funcGet 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.
self: borrow<descriptor>descriptor-flags, error-code>[method]descriptor.get-type: funcGet 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.
self: borrow<descriptor>descriptor-type, error-code>[method]descriptor.set-size: funcAdjust 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.
self: borrow<descriptor>size: filesizeerror-code>[method]descriptor.set-times: funcAdjust 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.
self: borrow<descriptor>data-access-timestamp: new-timestampdata-modification-timestamp: new-timestamperror-code>[method]descriptor.read-directory: funcRead 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.
+self: borrow<descriptor>directory-entry>, future<result<_, error-code>>)[method]descriptor.sync: funcSynchronize 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.
self: borrow<descriptor>error-code>[method]descriptor.create-directory-at: funcCreate a directory.
+Note: This is similar to mkdirat in POSIX.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.stat: funcReturn 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.
self: borrow<descriptor>descriptor-stat, error-code>[method]descriptor.stat-at: funcReturn 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.
self: borrow<descriptor>path-flags: path-flagspath: stringdescriptor-stat, error-code>[method]descriptor.set-times-at: funcAdjust 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.
self: borrow<descriptor>path-flags: path-flagspath: stringdata-access-timestamp: new-timestampdata-modification-timestamp: new-timestamperror-code>[method]descriptor.link-at: funcCreate 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.
self: borrow<descriptor>old-path-flags: path-flagsold-path: stringnew-descriptor: borrow<descriptor>new-path: stringerror-code>[method]descriptor.open-at: funcOpen 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.
self: borrow<descriptor>path-flags: path-flagspath: stringopen-flags: open-flagsflags: descriptor-flagsdescriptor>, error-code>[method]descriptor.readlink-at: funcRead 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.
self: borrow<descriptor>path: stringstring, error-code>[method]descriptor.remove-directory-at: funcRemove 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.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.rename-at: funcRename a filesystem object.
+Note: This is similar to renameat in POSIX.
self: borrow<descriptor>old-path: stringnew-descriptor: borrow<descriptor>new-path: stringerror-code>[method]descriptor.symlink-at: funcCreate 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.
self: borrow<descriptor>old-path: stringnew-path: stringerror-code>[method]descriptor.unlink-file-at: funcUnlink 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.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.is-same-object: funcTest 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.
self: borrow<descriptor>other: borrow<descriptor>[method]descriptor.metadata-hash: funcReturn 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.
+self: borrow<descriptor>metadata-hash-value, error-code>[method]descriptor.metadata-hash-at: funcReturn 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.
self: borrow<descriptor>path-flags: path-flagspath: stringmetadata-hash-value, error-code>type descriptor+
get-directories: funcReturn the set of preopened directories, and their paths.
+descriptor>, string)>type duration+
variant error-codeError 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:
+otheraccess-deniednot-supportedout-of-memorySee each individual API for what the POSIX equivalents are. They sometimes differ per API.
+Access denied. +
POSIX equivalent: EACCES, EPERM
+The operation is not supported. +
POSIX equivalent: EOPNOTSUPP, ENOPROTOOPT, EPFNOSUPPORT, EPROTONOSUPPORT, ESOCKTNOSUPPORT
+One of the arguments is invalid. +
POSIX equivalent: EINVAL, EDESTADDRREQ, EAFNOSUPPORT
+Not enough memory to complete the operation. +
POSIX equivalent: ENOMEM, ENOBUFS
+The operation timed out before it could finish completely. +
POSIX equivalent: ETIMEDOUT
+The operation is not valid in the socket's current state. +
The local address is not available. +
POSIX equivalent: EADDRNOTAVAIL
+A bind operation failed because the provided address is already in +use or because there are no ephemeral ports available. +
POSIX equivalent: EADDRINUSE
+The remote address is not reachable. +
POSIX equivalent: EHOSTUNREACH, EHOSTDOWN, ENETDOWN, ENETUNREACH, ENONET
+The connection was forcefully rejected. +
POSIX equivalent: ECONNREFUSED
+A write failed because the connection was broken. +
POSIX equivalent: EPIPE
+The connection was reset. +
POSIX equivalent: ECONNRESET
+The connection was aborted. +
POSIX equivalent: ECONNABORTED
+The size of a datagram sent to a UDP socket exceeded the maximum +supported size. +
POSIX equivalent: EMSGSIZE
+A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
enum ip-address-familytuple ipv4-addresstuple ipv6-addressvariant ip-addressipv4: ipv4-addressipv6: ipv6-addressrecord ipv4-socket-addresssin_port +
address: ipv4-address
sin_addr +
record ipv6-socket-addresssin6_port +
sin6_flowinfo +
address: ipv6-address
sin6_addr +
sin6_scope_id +
variant ip-socket-addressipv4: ipv4-socket-addressipv6: ipv6-socket-addressresource tcp-socketA TCP socket resource.
+The socket can be in one of the following states:
+unboundbound (See note below)listeningconnectingconnectedclosed
+See https://github.com/WebAssembly/WASI/blob/main/proposals/sockets/TcpSocketOperationalSemantics-0.3.0.md
+for more information.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:
tcp-socket
+handle is dropped.listen behaves similarly.tcp-socket::listen are independent and do
+not keep the listening socket alive.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[static]tcp-socket.create: funcCreate 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.
not-supported: The address-family is not supported. (EAFNOSUPPORT)address-family: ip-address-familytcp-socket>, error-code>[method]tcp-socket.bind: funcBind 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.
+invalid-argument: The local-address has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-argument: local-address is not a unicast address. (EINVAL)invalid-argument: local-address is an IPv4-mapped IPv6 address. (EINVAL)invalid-state: The socket is already bound. (EINVAL)address-in-use: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use: Address is already in use. (EADDRINUSE)address-not-bindable: local-address is not an address that can be bound to. (EADDRNOTAVAIL)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.
+self: borrow<tcp-socket>local-address: ip-socket-addresserror-code>[method]tcp-socket.connect: funcConnect 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.
invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: remote-address is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)invalid-argument: remote-address is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EADDRNOTAVAIL on Windows)invalid-argument: The port in remote-address is set to 0. (EADDRNOTAVAIL on Windows)invalid-state: The socket is already in the connecting state. (EALREADY)invalid-state: The socket is already in the connected state. (EISCONN)invalid-state: The socket is already in the listening state. (EOPNOTSUPP, EINVAL on Windows)timeout: Connection timed out. (ETIMEDOUT)connection-refused: The connection was forcefully rejected. (ECONNREFUSED)connection-reset: The connection was reset. (ECONNRESET)connection-aborted: The connection was aborted. (ECONNABORTED)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)self: borrow<tcp-socket>remote-address: ip-socket-addresserror-code>[method]tcp-socket.listen: funcStart 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:
+address-familykeep-alive-enabledkeep-alive-idle-timekeep-alive-intervalkeep-alive-counthop-limitreceive-buffer-sizesend-buffer-sizeinvalid-state: The socket is already in the connected state. (EISCONN, EINVAL on BSD)invalid-state: The socket is already in the listening state.address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)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:
+accept. Guest code never gets to see these failures. Or:tcp-socket resource that exposes the error when
+attempting to send or receive on it. Guest code then sees these
+failures as regular I/O errors.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.
self: borrow<tcp-socket>tcp-socket>>, error-code>[method]tcp-socket.send: funcTransmit 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.
+invalid-state: The socket is not in the connected state. (ENOTCONN)invalid-state: send has already been called on this socket.connection-broken: The connection is not writable anymore. (EPIPE, ECONNABORTED on Windows)connection-reset: The connection was reset. (ECONNRESET)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)self: borrow<tcp-socket>data: stream<u8>error-code>>[method]tcp-socket.receive: funcRead 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:
ok after a graceful shutdown from the peer (i.e. a FIN packet), orerr if the socket was closed abnormally.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.
invalid-state: The socket is not in the connected state. (ENOTCONN)invalid-state: receive has already been called on this socket.connection-reset: The connection was reset. (ECONNRESET)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)self: borrow<tcp-socket>u8>, future<result<_, error-code>>)[method]tcp-socket.get-local-address: funcGet 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
+addressis unspecified.
WASI is stricter and requires get-local-address to return
+invalid-state when the socket hasn't been bound yet.
invalid-state: The socket is not bound to any local address.self: borrow<tcp-socket>ip-socket-address, error-code>[method]tcp-socket.get-remote-address: funcGet the remote address.
+invalid-state: The socket is not connected to a remote address. (ENOTCONN)self: borrow<tcp-socket>ip-socket-address, error-code>[method]tcp-socket.get-is-listening: funcWhether the socket is in the listening state.
Equivalent to the SO_ACCEPTCONN socket option.
+self: borrow<tcp-socket>[method]tcp-socket.get-address-family: funcWhether this is a IPv4 or IPv6 socket.
+This is the value passed to the constructor.
+Equivalent to the SO_DOMAIN socket option.
+self: borrow<tcp-socket>[method]tcp-socket.set-listen-backlog-size: funcHints 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.
not-supported: (set) The platform does not support changing the backlog size after the initial listen.invalid-argument: (set) The provided value was 0.invalid-state: (set) The socket is in the connecting or connected state.self: borrow<tcp-socket>value: u64error-code>[method]tcp-socket.get-keep-alive-enabled: funcEnables or disables keepalive.
+The keepalive behavior can be adjusted using:
+keep-alive-idle-timekeep-alive-intervalkeep-alive-count
+These properties can be configured while keep-alive-enabled is
+false, but only come into effect when keep-alive-enabled is true.Equivalent to the SO_KEEPALIVE socket option.
+self: borrow<tcp-socket>bool, error-code>[method]tcp-socket.set-keep-alive-enabled: funcself: borrow<tcp-socket>value: boolerror-code>[method]tcp-socket.get-keep-alive-idle-time: funcAmount 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)
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>duration, error-code>[method]tcp-socket.set-keep-alive-idle-time: funcself: borrow<tcp-socket>value: durationerror-code>[method]tcp-socket.get-keep-alive-interval: funcThe 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>duration, error-code>[method]tcp-socket.set-keep-alive-interval: funcself: borrow<tcp-socket>value: durationerror-code>[method]tcp-socket.get-keep-alive-count: funcThe 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>u32, error-code>[method]tcp-socket.set-keep-alive-count: funcself: borrow<tcp-socket>value: u32error-code>[method]tcp-socket.get-hop-limit: funcEquivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
+If the provided value is 0, an invalid-argument error is returned.
invalid-argument: (set) The TTL value must be 1 or higher.self: borrow<tcp-socket>u8, error-code>[method]tcp-socket.set-hop-limit: funcself: borrow<tcp-socket>value: u8error-code>[method]tcp-socket.get-receive-buffer-size: funcKernel 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>u64, error-code>[method]tcp-socket.set-receive-buffer-size: funcself: borrow<tcp-socket>value: u64error-code>[method]tcp-socket.get-send-buffer-size: funcself: borrow<tcp-socket>u64, error-code>[method]tcp-socket.set-send-buffer-size: funcself: borrow<tcp-socket>value: u64error-code>[static]udp-socket.create: funcCreate 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.
address-family: ip-address-familyudp-socket>, error-code>[method]udp-socket.bind: funcBind 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.
invalid-argument: The local-address has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-state: The socket is already bound. (EINVAL)address-in-use: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use: Address is already in use. (EADDRINUSE)address-not-bindable: local-address is not an address that can be bound to. (EADDRNOTAVAIL)self: borrow<udp-socket>local-address: ip-socket-addresserror-code>[method]udp-socket.connect: funcAssociate 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:
send can only be used to send to this destination.receive will only return datagrams sent from the provided remote-address.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.
+invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)If the socket is already connected, some platforms (e.g. Linux) +require a disconnect before connecting to a different peer address.
+self: borrow<udp-socket>remote-address: ip-socket-addresserror-code>[method]udp-socket.disconnect: funcDissociate 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.
invalid-state: The socket is not connected.self: borrow<udp-socket>error-code>[method]udp-socket.send: funcSend 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.
invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The socket is in "connected" mode and remote-address is some value that does not match the address passed to connect. (EISCONN)invalid-argument: The socket is not "connected" and no value for remote-address was provided. (EDESTADDRREQ)remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)connection-refused: The connection was refused. (ECONNREFUSED)datagram-too-large: The datagram is too large. (EMSGSIZE)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)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.
self: borrow<udp-socket>data: list<u8>remote-address: option<ip-socket-address>error-code>[method]udp-socket.receive: funcReceive 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.
invalid-state: The socket has not been bound yet.remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)connection-refused: The connection was refused. (ECONNREFUSED)self: borrow<udp-socket>u8>, ip-socket-address), error-code>[method]udp-socket.get-local-address: funcGet 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
+addressis unspecified.
WASI is stricter and requires get-local-address to return
+invalid-state when the socket hasn't been bound yet.
invalid-state: The socket is not bound to any local address.self: borrow<udp-socket>ip-socket-address, error-code>[method]udp-socket.get-remote-address: funcGet the address the socket is currently "connected" to.
+invalid-state: The socket is not "connected" to a specific remote address. (ENOTCONN)self: borrow<udp-socket>ip-socket-address, error-code>[method]udp-socket.get-address-family: funcWhether this is a IPv4 or IPv6 socket.
+This is the value passed to the constructor.
+Equivalent to the SO_DOMAIN socket option.
+self: borrow<udp-socket>[method]udp-socket.get-unicast-hop-limit: funcEquivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
+If the provided value is 0, an invalid-argument error is returned.
invalid-argument: (set) The TTL value must be 1 or higher.self: borrow<udp-socket>u8, error-code>[method]udp-socket.set-unicast-hop-limit: funcself: borrow<udp-socket>value: u8error-code>[method]udp-socket.get-receive-buffer-size: funcKernel 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.
+invalid-argument: (set) The provided value was 0.self: borrow<udp-socket>u64, error-code>[method]udp-socket.set-receive-buffer-size: funcself: borrow<udp-socket>value: u64error-code>[method]udp-socket.get-send-buffer-size: funcself: borrow<udp-socket>u64, error-code>[method]udp-socket.set-send-buffer-size: funcself: borrow<udp-socket>value: u64error-code>type ip-address+
variant error-codeLookup error codes.
+Access denied. +
POSIX equivalent: EACCES, EPERM
+`name` is a syntactically invalid domain name or IP address. +
POSIX equivalent: EINVAL
+Name does not exist or has no suitable associated IP addresses. +
POSIX equivalent: EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY
+A temporary failure in name resolution occurred. +
POSIX equivalent: EAI_AGAIN
+A permanent failure in name resolution occurred. +
POSIX equivalent: EAI_FAIL
+A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
resolve-addresses: funcResolve 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.
+ip-address>, error-code>WASI Random is a random data API.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-random-bytes: funcReturn 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.
+get-random-u64: funcReturn 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.
The insecure interface for insecure pseudo-random numbers.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-random-bytes: funcReturn 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.
get-insecure-random-u64: funcReturn 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.
The insecure-seed interface for seeding hash-map DoS resistance.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-seed: funcReturn 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.
+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.
+wasi:clocks/types@0.3.1wasi:clocks/monotonic-clock@0.3.1wasi:clocks/system-clock@0.3.1wasi:clocks/timezone@0.3.1This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
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.
+type duration+
type marku64
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. +
now: funcRead 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.
markget-resolution: funcQuery the resolution of the clock. Returns the duration of time +corresponding to a clock tick.
+durationwait-until: funcWait until the specified mark has occurred.
+when: markwait-for: funcWait for the specified duration to elapse.
+how-long: durationWASI 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.
+type duration+
record instantAn "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
now: funcRead 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.
+instantget-resolution: funcQuery the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.
+durationtype instant+
iana-id: funcReturn 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.
+utc-offset: funcThe 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.
+when: instantto-debug-string: funcReturns 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.
+wasi:clocks/types@0.3.1wasi:clocks/system-clock@0.3.1wasi:filesystem/types@0.3.1wasi:filesystem/preopens@0.3.1This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
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.
+type duration+
record instantAn "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
now: funcRead 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.
+instantget-resolution: funcQuery the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.
+durationWASI 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.
+type instant+
type filesizeu64
File size or length of a region within a file. +
variant descriptor-typeThe type of a filesystem object referenced by a descriptor.
+Note: This was called filetype in earlier versions of WASI.
The descriptor refers to a block device inode. +
The descriptor refers to a character device inode. +
The descriptor refers to a directory inode. +
The descriptor refers to a named pipe. +
The file refers to a symbolic link inode. +
The descriptor refers to a regular file inode. +
The descriptor refers to a socket. +
The type of the descriptor or file is different from any of the +other types specified. +
flags descriptor-flagsDescriptor flags.
+Note: This was called fdflags in earlier versions of WASI.
Read mode: Data can be read. +
Write mode: Data can be written to. +
Request that writes be performed according to synchronized I/O file +integrity completion. The data stored in the file and the file's +metadata are synchronized. This is similar to `O_SYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Request that writes be performed according to synchronized I/O data +integrity completion. Only the data stored in the file is +synchronized. This is similar to `O_DSYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Requests that reads be performed at the same level of integrity +requested for writes. This is similar to `O_RSYNC` in POSIX. +
The precise semantics of this operation have not yet been defined for +WASI. At this time, it should be interpreted as a request, and not a +requirement.
+Mutating directories mode: Directory contents may be mutated. +
When this flag is unset on a descriptor, operations using the
+descriptor which would create, rename, delete, modify the data or
+metadata of filesystem objects, or obtain another handle which
+would permit any of those, shall fail with error-code::read-only if
+they would otherwise succeed.
This may only be set on directories.
+flags path-flagsFlags determining the method of how paths are resolved.
+flags open-flagsOpen flags used by open-at.
Create file if it does not exist, similar to `O_CREAT` in POSIX. +
Fail if not a directory, similar to `O_DIRECTORY` in POSIX. +
Fail if file already exists, similar to `O_EXCL` in POSIX. +
Truncate file to size 0, similar to `O_TRUNC` in POSIX. +
type link-countu64
Number of hard links to an inode. +
record descriptor-statFile attributes.
+Note: This was called filestat in earlier versions of WASI.
type: descriptor-type
File type. +
Number of hard links to the file. +
size: filesize
For regular files, the file size in bytes. For symbolic links, the +length in bytes of the pathname contained in the symbolic link. +
data-access-timestamp: option<instant>
Last data access timestamp. +
If the option is none, the platform doesn't maintain an access
+timestamp for this file.
data-modification-timestamp: option<instant>
Last data modification timestamp. +
If the option is none, the platform doesn't maintain a
+modification timestamp for this file.
status-change-timestamp: option<instant>
Last file status-change timestamp. +
If the option is none, the platform doesn't maintain a
+status-change timestamp for this file.
variant new-timestampWhen setting a timestamp, this gives the value to set it to.
+Leave the timestamp set to its previous value. +
Set the timestamp to the current time of the system clock associated +with the filesystem. +
timestamp: instant
Set the timestamp to the given value. +
record directory-entryA directory entry.
+type: descriptor-type
The type of the file referred to by this directory entry. +
The name of the object. +
variant error-codeError 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.
Permission denied, similar to `EACCES` in POSIX. +
Connection already in progress, similar to `EALREADY` in POSIX. +
Bad descriptor, similar to `EBADF` in POSIX. +
Device or resource busy, similar to `EBUSY` in POSIX. +
Resource deadlock would occur, similar to `EDEADLK` in POSIX. +
Storage quota exceeded, similar to `EDQUOT` in POSIX. +
File exists, similar to `EEXIST` in POSIX. +
File too large, similar to `EFBIG` in POSIX. +
Illegal byte sequence, similar to `EILSEQ` in POSIX. +
Operation in progress, similar to `EINPROGRESS` in POSIX. +
Interrupted function, similar to `EINTR` in POSIX. +
Invalid argument, similar to `EINVAL` in POSIX. +
I/O error, similar to `EIO` in POSIX. +
Is a directory, similar to `EISDIR` in POSIX. +
Too many levels of symbolic links, similar to `ELOOP` in POSIX. +
Too many links, similar to `EMLINK` in POSIX. +
Message too large, similar to `EMSGSIZE` in POSIX. +
Filename too long, similar to `ENAMETOOLONG` in POSIX. +
No such device, similar to `ENODEV` in POSIX. +
No such file or directory, similar to `ENOENT` in POSIX. +
No locks available, similar to `ENOLCK` in POSIX. +
Not enough space, similar to `ENOMEM` in POSIX. +
No space left on device, similar to `ENOSPC` in POSIX. +
Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. +
Directory not empty, similar to `ENOTEMPTY` in POSIX. +
State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. +
Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. +
Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. +
No such device or address, similar to `ENXIO` in POSIX. +
Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. +
Operation not permitted, similar to `EPERM` in POSIX. +
Broken pipe, similar to `EPIPE` in POSIX. +
Read-only file system, similar to `EROFS` in POSIX. +
Invalid seek, similar to `ESPIPE` in POSIX. +
Text file busy, similar to `ETXTBSY` in POSIX. +
Cross-device link, similar to `EXDEV` in POSIX. +
A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
enum adviceFile or memory access pattern advisory information.
+The application has no advice to give on its behavior with respect +to the specified data. +
The application expects to access the specified data sequentially +from lower offsets to higher offsets. +
The application expects to access the specified data in a random +order. +
The application expects to access the specified data in the near +future. +
The application expects that it will not access the specified data +in the near future. +
The application expects to access the specified data once and then +not reuse it thereafter. +
record metadata-hash-valueA 128-bit hash value, split into parts because wasm doesn't have a +128-bit integer type.
+64 bits of a 128-bit hash value. +
Another 64 bits of a 128-bit hash value. +
resource descriptor[method]descriptor.read-via-stream: funcReturn 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.
self: borrow<descriptor>offset: filesizeu8>, future<result<_, error-code>>)[method]descriptor.write-via-stream: funcReturn 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.
self: borrow<descriptor>data: stream<u8>offset: filesizeerror-code>>[method]descriptor.append-via-stream: funcReturn 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.
self: borrow<descriptor>data: stream<u8>error-code>>[method]descriptor.advise: funcProvide file advisory information on a descriptor.
+This is similar to posix_fadvise in POSIX.
self: borrow<descriptor>offset: filesizelength: filesizeadvice: adviceerror-code>[method]descriptor.sync-data: funcSynchronize 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.
self: borrow<descriptor>error-code>[method]descriptor.get-flags: funcGet 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.
self: borrow<descriptor>descriptor-flags, error-code>[method]descriptor.get-type: funcGet 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.
self: borrow<descriptor>descriptor-type, error-code>[method]descriptor.set-size: funcAdjust 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.
self: borrow<descriptor>size: filesizeerror-code>[method]descriptor.set-times: funcAdjust 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.
self: borrow<descriptor>data-access-timestamp: new-timestampdata-modification-timestamp: new-timestamperror-code>[method]descriptor.read-directory: funcRead 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.
+self: borrow<descriptor>directory-entry>, future<result<_, error-code>>)[method]descriptor.sync: funcSynchronize 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.
self: borrow<descriptor>error-code>[method]descriptor.create-directory-at: funcCreate a directory.
+Note: This is similar to mkdirat in POSIX.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.stat: funcReturn 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.
self: borrow<descriptor>descriptor-stat, error-code>[method]descriptor.stat-at: funcReturn 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.
self: borrow<descriptor>path-flags: path-flagspath: stringdescriptor-stat, error-code>[method]descriptor.set-times-at: funcAdjust 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.
self: borrow<descriptor>path-flags: path-flagspath: stringdata-access-timestamp: new-timestampdata-modification-timestamp: new-timestamperror-code>[method]descriptor.link-at: funcCreate 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.
self: borrow<descriptor>old-path-flags: path-flagsold-path: stringnew-descriptor: borrow<descriptor>new-path: stringerror-code>[method]descriptor.open-at: funcOpen 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.
self: borrow<descriptor>path-flags: path-flagspath: stringopen-flags: open-flagsflags: descriptor-flagsdescriptor>, error-code>[method]descriptor.readlink-at: funcRead 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.
self: borrow<descriptor>path: stringstring, error-code>[method]descriptor.remove-directory-at: funcRemove 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.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.rename-at: funcRename a filesystem object.
+Note: This is similar to renameat in POSIX.
self: borrow<descriptor>old-path: stringnew-descriptor: borrow<descriptor>new-path: stringerror-code>[method]descriptor.symlink-at: funcCreate 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.
self: borrow<descriptor>old-path: stringnew-path: stringerror-code>[method]descriptor.unlink-file-at: funcUnlink 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.
self: borrow<descriptor>path: stringerror-code>[method]descriptor.is-same-object: funcTest 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.
self: borrow<descriptor>other: borrow<descriptor>[method]descriptor.metadata-hash: funcReturn 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.
+self: borrow<descriptor>metadata-hash-value, error-code>[method]descriptor.metadata-hash-at: funcReturn 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.
self: borrow<descriptor>path-flags: path-flagspath: stringmetadata-hash-value, error-code>type descriptor+
get-directories: funcReturn the set of preopened directories, and their paths.
+descriptor>, string)>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.
wasi:clocks/types@0.3.1wasi:http/types@0.3.1wasi:http/handler@0.3.1wasi:cli/types@0.3.1wasi:cli/stdout@0.3.1wasi:cli/stderr@0.3.1wasi:cli/stdin@0.3.1wasi:http/client@0.3.1wasi:clocks/monotonic-clock@0.3.1wasi:clocks/system-clock@0.3.1wasi:clocks/timezone@0.3.1wasi:random/random@0.3.1wasi:random/insecure@0.3.1wasi:random/insecure-seed@0.3.1wasi:http/handler@0.3.1This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
This interface defines all of the types and methods for implementing HTTP +Requests and Responses, as well as their headers, trailers, and bodies.
+type duration+
variant methodThis type corresponds to HTTP standard Methods.
+variant schemeThis type corresponds to HTTP standard Related Schemes.
+record DNS-error-payloadDefines the case payload type for DNS-error above:
record TLS-alert-received-payloadDefines the case payload type for TLS-alert-received above:
record field-size-payloadDefines the case payload type for HTTP-response-{header,trailer}-size above:
field-name: option<string>field-size: option<u32>variant error-codeThese 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
+DNS-timeoutDNS-error: DNS-error-payloaddestination-not-founddestination-unavailabledestination-IP-prohibiteddestination-IP-unroutableconnection-refusedconnection-terminatedconnection-timeoutconnection-read-timeoutconnection-write-timeoutconnection-limit-reachedTLS-protocol-errorTLS-certificate-errorTLS-alert-received: TLS-alert-received-payloadHTTP-request-deniedHTTP-request-length-requiredHTTP-request-body-size: option<u64>HTTP-request-method-invalidHTTP-request-URI-invalidHTTP-request-URI-too-longHTTP-request-header-section-size: option<u32>HTTP-request-header-size: option<field-size-payload>HTTP-request-trailer-section-size: option<u32>HTTP-request-trailer-size: field-size-payloadHTTP-response-incompleteHTTP-response-header-section-size: option<u32>HTTP-response-header-size: field-size-payloadHTTP-response-body-size: option<u64>HTTP-response-trailer-section-size: option<u32>HTTP-response-trailer-size: field-size-payloadHTTP-response-transfer-coding: option<string>HTTP-response-content-coding: option<string>HTTP-response-timeoutHTTP-upgrade-failedHTTP-protocol-errorloop-detectedconfiguration-errorinternal-error: option<string>This is a catch-all error for anything that doesn't fit cleanly into a +more specific case. It also includes an optional string for an +unstructured description of the error. Users should not depend on the +string for diagnosing errors, as it's not required to be consistent +between implementations. +
variant header-errorThis type enumerates the different kinds of errors that may occur when
+setting or appending to a fields resource.
This error indicates that a `field-name` or `field-value` was +syntactically invalid when used with an operation that sets headers in a +`fields`. +
This error indicates that a forbidden `field-name` was used when trying +to set a header in a `fields`. +
This error indicates that the operation on the `fields` was not +permitted because the fields are immutable. +
This error indicates that the operation would exceed an +implementation-defined limit on field sizes. This may apply to +an individual `field-value`, a single `field-name` plus all its +values, or the total aggregate size of all fields. +
This is a catch-all error for anything that doesn't fit cleanly into a +more specific case. Implementations can use this to extend the error +type without breaking existing code. It also includes an optional +string for an unstructured description of the error. Users should not +depend on the string for diagnosing errors, as it's not required to be +consistent between implementations. +
variant request-options-errorThis type enumerates the different kinds of errors that may occur when
+setting fields of a request-options resource.
Indicates the specified field is not supported by this implementation. +
Indicates that the operation on the `request-options` was not permitted +because it is immutable. +
This is a catch-all error for anything that doesn't fit cleanly into a +more specific case. Implementations can use this to extend the error +type without breaking existing code. It also includes an optional +string for an unstructured description of the error. Users should not +depend on the string for diagnosing errors, as it's not required to be +consistent between implementations. +
type field-namestring
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-valueField 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 fieldsThis 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 headersHeaders is an alias for Fields. +
type trailersTrailers is an alias for Fields. +
resource requestRepresents an HTTP Request.
+resource request-optionsParameters 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-codeu16
This type corresponds to the HTTP standard Status Code. +
resource response[constructor]fields: funcConstruct an empty HTTP Fields.
+The resulting fields is mutable.
fields>[static]fields.from-list: funcConstruct 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.
+entries: list<(field-name, field-value)>fields>, header-error>[method]fields.get: funcGet 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.
self: borrow<fields>name: field-namefield-value>[method]fields.has: funcReturns true when the name is present in this fields. If the name is
+syntactically invalid, false is returned.
self: borrow<fields>name: field-name[method]fields.set: funcSet 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.
self: borrow<fields>name: field-namevalue: list<field-value>header-error>[method]fields.delete: funcDelete all values for a name. Does nothing if no values for the name +exist.
+Fails with header-error.immutable if the fields are immutable.
self: borrow<fields>name: field-nameheader-error>[method]fields.get-and-delete: funcDelete 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.
self: borrow<fields>name: field-namefield-value>, header-error>[method]fields.append: funcAppend 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.
self: borrow<fields>name: field-namevalue: field-valueheader-error>[method]fields.copy-all: funcRetrieve 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.
+self: borrow<fields>field-name, field-value)>[method]fields.clone: funcMake 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.
self: borrow<fields>fields>[static]request.new: funcConstruct 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.
+headers: own<headers>contents: option<stream<u8>>trailers: future<result<option<own<trailers>>, error-code>>options: option<own<request-options>>request>, future<result<_, error-code>>)[method]request.get-method: funcGet the Method for the Request.
+self: borrow<request>method[method]request.set-method: funcSet the Method for the Request. Fails if the string present in a
+method.other argument is not a syntactically valid method.
[method]request.get-path-with-query: funcGet the combination of the HTTP Path and Query for the Request. When
+none, this represents an empty Path and empty Query.
self: borrow<request>[method]request.set-path-with-query: funcSet 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.
self: borrow<request>path-with-query: option<string>[method]request.get-scheme: funcGet the HTTP Related Scheme for the Request. When none, the
+implementation may choose an appropriate default scheme.
self: borrow<request>scheme>[method]request.set-scheme: funcSet 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.
[method]request.get-authority: funcGet 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.
self: borrow<request>[method]request.set-authority: funcSet 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.
self: borrow<request>authority: option<string>[method]request.get-options: funcGet 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.
self: borrow<request>request-options>>[method]request.get-headers: funcGet the headers associated with the Request.
+The returned headers resource is immutable: set, append, and
+delete operations will fail with header-error.immutable.
self: borrow<request>headers>[static]request.consume-body: funcGet 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.
this: own<request>res: future<result<_, error-code>>u8>, future<result<option<own<trailers>>, error-code>>)[constructor]request-options: funcConstruct a default request-options value.
request-options>[method]request-options.get-connect-timeout: funcThe timeout for the initial connect to the HTTP Server.
+self: borrow<request-options>duration>[method]request-options.set-connect-timeout: funcSet 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.
+self: borrow<request-options>duration: option<duration>request-options-error>[method]request-options.get-first-byte-timeout: funcThe timeout for receiving the first byte of the Response body.
+self: borrow<request-options>duration>[method]request-options.set-first-byte-timeout: funcSet 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.
+self: borrow<request-options>duration: option<duration>request-options-error>[method]request-options.get-between-bytes-timeout: funcThe timeout for receiving subsequent chunks of bytes in the Response +body stream.
+self: borrow<request-options>duration>[method]request-options.set-between-bytes-timeout: funcSet 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.
+self: borrow<request-options>duration: option<duration>request-options-error>[method]request-options.clone: funcMake a deep copy of the request-options.
+The resulting request-options is mutable.
self: borrow<request-options>request-options>[static]response.new: funcConstruct 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.
+headers: own<headers>contents: option<stream<u8>>trailers: future<result<option<own<trailers>>, error-code>>response>, future<result<_, error-code>>)[method]response.get-status-code: funcGet the HTTP Status Code for the Response.
+self: borrow<response>status-code[method]response.set-status-code: funcSet the HTTP Status Code for the Response. Fails if the status-code +given is not a valid http status code.
+self: borrow<response>status-code: status-code[method]response.get-headers: funcGet the headers associated with the Response.
+The returned headers resource is immutable: set, append, and
+delete operations will fail with header-error.immutable.
self: borrow<response>headers>[static]response.consume-body: funcGet 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.
this: own<response>res: future<result<_, error-code>>u8>, future<result<option<own<trailers>>, error-code>>)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.
type request+
type response+
type error-code+
handle: funcThis function may be called with either an incoming request read from the +network or a request synthesized or forwarded by another component.
+response>, error-code>enum error-codeInput/output error +
Invalid or incomplete multibyte or wide character +
Broken pipe +
type error-code+
write-via-stream: funcWrite 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.
+error-code>>type error-code+
write-via-stream: funcWrite 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.
+error-code>>type error-code+
read-via-stream: funcReturn 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.
+u8>, future<result<_, error-code>>)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.
type request+
type response+
type error-code+
send: funcThis function may be used to either send an outgoing request over the +network or to forward it to another component.
+response>, error-code>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.
+type duration+
type marku64
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. +
now: funcRead 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.
markget-resolution: funcQuery the resolution of the clock. Returns the duration of time +corresponding to a clock tick.
+durationwait-until: funcWait until the specified mark has occurred.
+when: markwait-for: funcWait for the specified duration to elapse.
+how-long: durationWASI 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.
+type duration+
record instantAn "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
now: funcRead 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.
+instantget-resolution: funcQuery the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.
+durationtype instant+
iana-id: funcReturn 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.
+utc-offset: funcThe 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.
+when: instantto-debug-string: funcReturns 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.
+WASI Random is a random data API.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-random-bytes: funcReturn 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.
+get-random-u64: funcReturn 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.
The insecure interface for insecure pseudo-random numbers.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-random-bytes: funcReturn 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.
get-insecure-random-u64: funcReturn 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.
The insecure-seed interface for seeding hash-map DoS resistance.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-seed: funcReturn 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.
+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.
+type request+
type response+
type error-code+
handle: funcThis function may be called with either an incoming request read from the +network or a request synthesized or forwarded by another component.
+response>, error-code>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.
wasi:cli/types@0.3.1wasi:cli/stdout@0.3.1wasi:cli/stderr@0.3.1wasi:cli/stdin@0.3.1wasi:clocks/types@0.3.1wasi:http/types@0.3.1wasi:http/client@0.3.1wasi:clocks/monotonic-clock@0.3.1wasi:clocks/system-clock@0.3.1wasi:clocks/timezone@0.3.1wasi:random/random@0.3.1wasi:random/insecure@0.3.1wasi:random/insecure-seed@0.3.1wasi:http/handler@0.3.1enum error-codeInput/output error +
Invalid or incomplete multibyte or wide character +
Broken pipe +
type error-code+
write-via-stream: funcWrite 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.
+error-code>>type error-code+
write-via-stream: funcWrite 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.
+error-code>>type error-code+
read-via-stream: funcReturn 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.
+u8>, future<result<_, error-code>>)This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
This interface defines all of the types and methods for implementing HTTP +Requests and Responses, as well as their headers, trailers, and bodies.
+type duration+
variant methodThis type corresponds to HTTP standard Methods.
+variant schemeThis type corresponds to HTTP standard Related Schemes.
+record DNS-error-payloadDefines the case payload type for DNS-error above:
record TLS-alert-received-payloadDefines the case payload type for TLS-alert-received above:
record field-size-payloadDefines the case payload type for HTTP-response-{header,trailer}-size above:
field-name: option<string>field-size: option<u32>variant error-codeThese 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
+DNS-timeoutDNS-error: DNS-error-payloaddestination-not-founddestination-unavailabledestination-IP-prohibiteddestination-IP-unroutableconnection-refusedconnection-terminatedconnection-timeoutconnection-read-timeoutconnection-write-timeoutconnection-limit-reachedTLS-protocol-errorTLS-certificate-errorTLS-alert-received: TLS-alert-received-payloadHTTP-request-deniedHTTP-request-length-requiredHTTP-request-body-size: option<u64>HTTP-request-method-invalidHTTP-request-URI-invalidHTTP-request-URI-too-longHTTP-request-header-section-size: option<u32>HTTP-request-header-size: option<field-size-payload>HTTP-request-trailer-section-size: option<u32>HTTP-request-trailer-size: field-size-payloadHTTP-response-incompleteHTTP-response-header-section-size: option<u32>HTTP-response-header-size: field-size-payloadHTTP-response-body-size: option<u64>HTTP-response-trailer-section-size: option<u32>HTTP-response-trailer-size: field-size-payloadHTTP-response-transfer-coding: option<string>HTTP-response-content-coding: option<string>HTTP-response-timeoutHTTP-upgrade-failedHTTP-protocol-errorloop-detectedconfiguration-errorinternal-error: option<string>This is a catch-all error for anything that doesn't fit cleanly into a +more specific case. It also includes an optional string for an +unstructured description of the error. Users should not depend on the +string for diagnosing errors, as it's not required to be consistent +between implementations. +
variant header-errorThis type enumerates the different kinds of errors that may occur when
+setting or appending to a fields resource.
This error indicates that a `field-name` or `field-value` was +syntactically invalid when used with an operation that sets headers in a +`fields`. +
This error indicates that a forbidden `field-name` was used when trying +to set a header in a `fields`. +
This error indicates that the operation on the `fields` was not +permitted because the fields are immutable. +
This error indicates that the operation would exceed an +implementation-defined limit on field sizes. This may apply to +an individual `field-value`, a single `field-name` plus all its +values, or the total aggregate size of all fields. +
This is a catch-all error for anything that doesn't fit cleanly into a +more specific case. Implementations can use this to extend the error +type without breaking existing code. It also includes an optional +string for an unstructured description of the error. Users should not +depend on the string for diagnosing errors, as it's not required to be +consistent between implementations. +
variant request-options-errorThis type enumerates the different kinds of errors that may occur when
+setting fields of a request-options resource.
Indicates the specified field is not supported by this implementation. +
Indicates that the operation on the `request-options` was not permitted +because it is immutable. +
This is a catch-all error for anything that doesn't fit cleanly into a +more specific case. Implementations can use this to extend the error +type without breaking existing code. It also includes an optional +string for an unstructured description of the error. Users should not +depend on the string for diagnosing errors, as it's not required to be +consistent between implementations. +
type field-namestring
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-valueField 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 fieldsThis 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 headersHeaders is an alias for Fields. +
type trailersTrailers is an alias for Fields. +
resource requestRepresents an HTTP Request.
+resource request-optionsParameters 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-codeu16
This type corresponds to the HTTP standard Status Code. +
resource response[constructor]fields: funcConstruct an empty HTTP Fields.
+The resulting fields is mutable.
fields>[static]fields.from-list: funcConstruct 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.
+entries: list<(field-name, field-value)>fields>, header-error>[method]fields.get: funcGet 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.
self: borrow<fields>name: field-namefield-value>[method]fields.has: funcReturns true when the name is present in this fields. If the name is
+syntactically invalid, false is returned.
self: borrow<fields>name: field-name[method]fields.set: funcSet 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.
self: borrow<fields>name: field-namevalue: list<field-value>header-error>[method]fields.delete: funcDelete all values for a name. Does nothing if no values for the name +exist.
+Fails with header-error.immutable if the fields are immutable.
self: borrow<fields>name: field-nameheader-error>[method]fields.get-and-delete: funcDelete 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.
self: borrow<fields>name: field-namefield-value>, header-error>[method]fields.append: funcAppend 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.
self: borrow<fields>name: field-namevalue: field-valueheader-error>[method]fields.copy-all: funcRetrieve 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.
+self: borrow<fields>field-name, field-value)>[method]fields.clone: funcMake 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.
self: borrow<fields>fields>[static]request.new: funcConstruct 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.
+headers: own<headers>contents: option<stream<u8>>trailers: future<result<option<own<trailers>>, error-code>>options: option<own<request-options>>request>, future<result<_, error-code>>)[method]request.get-method: funcGet the Method for the Request.
+self: borrow<request>method[method]request.set-method: funcSet the Method for the Request. Fails if the string present in a
+method.other argument is not a syntactically valid method.
[method]request.get-path-with-query: funcGet the combination of the HTTP Path and Query for the Request. When
+none, this represents an empty Path and empty Query.
self: borrow<request>[method]request.set-path-with-query: funcSet 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.
self: borrow<request>path-with-query: option<string>[method]request.get-scheme: funcGet the HTTP Related Scheme for the Request. When none, the
+implementation may choose an appropriate default scheme.
self: borrow<request>scheme>[method]request.set-scheme: funcSet 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.
[method]request.get-authority: funcGet 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.
self: borrow<request>[method]request.set-authority: funcSet 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.
self: borrow<request>authority: option<string>[method]request.get-options: funcGet 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.
self: borrow<request>request-options>>[method]request.get-headers: funcGet the headers associated with the Request.
+The returned headers resource is immutable: set, append, and
+delete operations will fail with header-error.immutable.
self: borrow<request>headers>[static]request.consume-body: funcGet 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.
this: own<request>res: future<result<_, error-code>>u8>, future<result<option<own<trailers>>, error-code>>)[constructor]request-options: funcConstruct a default request-options value.
request-options>[method]request-options.get-connect-timeout: funcThe timeout for the initial connect to the HTTP Server.
+self: borrow<request-options>duration>[method]request-options.set-connect-timeout: funcSet 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.
+self: borrow<request-options>duration: option<duration>request-options-error>[method]request-options.get-first-byte-timeout: funcThe timeout for receiving the first byte of the Response body.
+self: borrow<request-options>duration>[method]request-options.set-first-byte-timeout: funcSet 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.
+self: borrow<request-options>duration: option<duration>request-options-error>[method]request-options.get-between-bytes-timeout: funcThe timeout for receiving subsequent chunks of bytes in the Response +body stream.
+self: borrow<request-options>duration>[method]request-options.set-between-bytes-timeout: funcSet 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.
+self: borrow<request-options>duration: option<duration>request-options-error>[method]request-options.clone: funcMake a deep copy of the request-options.
+The resulting request-options is mutable.
self: borrow<request-options>request-options>[static]response.new: funcConstruct 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.
+headers: own<headers>contents: option<stream<u8>>trailers: future<result<option<own<trailers>>, error-code>>response>, future<result<_, error-code>>)[method]response.get-status-code: funcGet the HTTP Status Code for the Response.
+self: borrow<response>status-code[method]response.set-status-code: funcSet the HTTP Status Code for the Response. Fails if the status-code +given is not a valid http status code.
+self: borrow<response>status-code: status-code[method]response.get-headers: funcGet the headers associated with the Response.
+The returned headers resource is immutable: set, append, and
+delete operations will fail with header-error.immutable.
self: borrow<response>headers>[static]response.consume-body: funcGet 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.
this: own<response>res: future<result<_, error-code>>u8>, future<result<option<own<trailers>>, error-code>>)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.
type request+
type response+
type error-code+
send: funcThis function may be used to either send an outgoing request over the +network or to forward it to another component.
+response>, error-code>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.
+type duration+
type marku64
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. +
now: funcRead 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.
markget-resolution: funcQuery the resolution of the clock. Returns the duration of time +corresponding to a clock tick.
+durationwait-until: funcWait until the specified mark has occurred.
+when: markwait-for: funcWait for the specified duration to elapse.
+how-long: durationWASI 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.
+type duration+
record instantAn "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
now: funcRead 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.
+instantget-resolution: funcQuery the resolution of the clock. Returns the smallest duration of time +that the implementation permits distinguishing.
+durationtype instant+
iana-id: funcReturn 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.
+utc-offset: funcThe 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.
+when: instantto-debug-string: funcReturns 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.
+WASI Random is a random data API.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-random-bytes: funcReturn 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.
+get-random-u64: funcReturn 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.
The insecure interface for insecure pseudo-random numbers.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-random-bytes: funcReturn 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.
get-insecure-random-u64: funcReturn 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.
The insecure-seed interface for seeding hash-map DoS resistance.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-seed: funcReturn 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.
+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.
+type request+
type response+
type error-code+
handle: funcThis function may be called with either an incoming request read from the +network or a request synthesized or forwarded by another component.
+response>, error-code>wasi:random/random@0.3.1wasi:random/insecure@0.3.1wasi:random/insecure-seed@0.3.1WASI Random is a random data API.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-random-bytes: funcReturn 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.
+get-random-u64: funcReturn 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.
The insecure interface for insecure pseudo-random numbers.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-random-bytes: funcReturn 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.
get-insecure-random-u64: funcReturn 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.
The insecure-seed interface for seeding hash-map DoS resistance.
+It is intended to be portable at least between Unix-family platforms and +Windows.
+get-insecure-seed: funcReturn 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.
+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.
+wasi:clocks/types@0.3.1wasi:sockets/types@0.3.1wasi:sockets/ip-name-lookup@0.3.1This interface common types used throughout wasi:clocks.
+type durationu64
A duration of time, in nanoseconds. +
type duration+
variant error-codeError 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:
+otheraccess-deniednot-supportedout-of-memorySee each individual API for what the POSIX equivalents are. They sometimes differ per API.
+Access denied. +
POSIX equivalent: EACCES, EPERM
+The operation is not supported. +
POSIX equivalent: EOPNOTSUPP, ENOPROTOOPT, EPFNOSUPPORT, EPROTONOSUPPORT, ESOCKTNOSUPPORT
+One of the arguments is invalid. +
POSIX equivalent: EINVAL, EDESTADDRREQ, EAFNOSUPPORT
+Not enough memory to complete the operation. +
POSIX equivalent: ENOMEM, ENOBUFS
+The operation timed out before it could finish completely. +
POSIX equivalent: ETIMEDOUT
+The operation is not valid in the socket's current state. +
The local address is not available. +
POSIX equivalent: EADDRNOTAVAIL
+A bind operation failed because the provided address is already in +use or because there are no ephemeral ports available. +
POSIX equivalent: EADDRINUSE
+The remote address is not reachable. +
POSIX equivalent: EHOSTUNREACH, EHOSTDOWN, ENETDOWN, ENETUNREACH, ENONET
+The connection was forcefully rejected. +
POSIX equivalent: ECONNREFUSED
+A write failed because the connection was broken. +
POSIX equivalent: EPIPE
+The connection was reset. +
POSIX equivalent: ECONNRESET
+The connection was aborted. +
POSIX equivalent: ECONNABORTED
+The size of a datagram sent to a UDP socket exceeded the maximum +supported size. +
POSIX equivalent: EMSGSIZE
+A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
enum ip-address-familytuple ipv4-addresstuple ipv6-addressvariant ip-addressipv4: ipv4-addressipv6: ipv6-addressrecord ipv4-socket-addresssin_port +
address: ipv4-address
sin_addr +
record ipv6-socket-addresssin6_port +
sin6_flowinfo +
address: ipv6-address
sin6_addr +
sin6_scope_id +
variant ip-socket-addressipv4: ipv4-socket-addressipv6: ipv6-socket-addressresource tcp-socketA TCP socket resource.
+The socket can be in one of the following states:
+unboundbound (See note below)listeningconnectingconnectedclosed
+See https://github.com/WebAssembly/WASI/blob/main/proposals/sockets/TcpSocketOperationalSemantics-0.3.0.md
+for more information.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:
tcp-socket
+handle is dropped.listen behaves similarly.tcp-socket::listen are independent and do
+not keep the listening socket alive.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[static]tcp-socket.create: funcCreate 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.
not-supported: The address-family is not supported. (EAFNOSUPPORT)address-family: ip-address-familytcp-socket>, error-code>[method]tcp-socket.bind: funcBind 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.
+invalid-argument: The local-address has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-argument: local-address is not a unicast address. (EINVAL)invalid-argument: local-address is an IPv4-mapped IPv6 address. (EINVAL)invalid-state: The socket is already bound. (EINVAL)address-in-use: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use: Address is already in use. (EADDRINUSE)address-not-bindable: local-address is not an address that can be bound to. (EADDRNOTAVAIL)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.
+self: borrow<tcp-socket>local-address: ip-socket-addresserror-code>[method]tcp-socket.connect: funcConnect 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.
invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: remote-address is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)invalid-argument: remote-address is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EADDRNOTAVAIL on Windows)invalid-argument: The port in remote-address is set to 0. (EADDRNOTAVAIL on Windows)invalid-state: The socket is already in the connecting state. (EALREADY)invalid-state: The socket is already in the connected state. (EISCONN)invalid-state: The socket is already in the listening state. (EOPNOTSUPP, EINVAL on Windows)timeout: Connection timed out. (ETIMEDOUT)connection-refused: The connection was forcefully rejected. (ECONNREFUSED)connection-reset: The connection was reset. (ECONNRESET)connection-aborted: The connection was aborted. (ECONNABORTED)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)self: borrow<tcp-socket>remote-address: ip-socket-addresserror-code>[method]tcp-socket.listen: funcStart 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:
+address-familykeep-alive-enabledkeep-alive-idle-timekeep-alive-intervalkeep-alive-counthop-limitreceive-buffer-sizesend-buffer-sizeinvalid-state: The socket is already in the connected state. (EISCONN, EINVAL on BSD)invalid-state: The socket is already in the listening state.address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)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:
+accept. Guest code never gets to see these failures. Or:tcp-socket resource that exposes the error when
+attempting to send or receive on it. Guest code then sees these
+failures as regular I/O errors.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.
self: borrow<tcp-socket>tcp-socket>>, error-code>[method]tcp-socket.send: funcTransmit 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.
+invalid-state: The socket is not in the connected state. (ENOTCONN)invalid-state: send has already been called on this socket.connection-broken: The connection is not writable anymore. (EPIPE, ECONNABORTED on Windows)connection-reset: The connection was reset. (ECONNRESET)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)self: borrow<tcp-socket>data: stream<u8>error-code>>[method]tcp-socket.receive: funcRead 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:
ok after a graceful shutdown from the peer (i.e. a FIN packet), orerr if the socket was closed abnormally.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.
invalid-state: The socket is not in the connected state. (ENOTCONN)invalid-state: receive has already been called on this socket.connection-reset: The connection was reset. (ECONNRESET)remote-unreachable: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)self: borrow<tcp-socket>u8>, future<result<_, error-code>>)[method]tcp-socket.get-local-address: funcGet 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
+addressis unspecified.
WASI is stricter and requires get-local-address to return
+invalid-state when the socket hasn't been bound yet.
invalid-state: The socket is not bound to any local address.self: borrow<tcp-socket>ip-socket-address, error-code>[method]tcp-socket.get-remote-address: funcGet the remote address.
+invalid-state: The socket is not connected to a remote address. (ENOTCONN)self: borrow<tcp-socket>ip-socket-address, error-code>[method]tcp-socket.get-is-listening: funcWhether the socket is in the listening state.
Equivalent to the SO_ACCEPTCONN socket option.
+self: borrow<tcp-socket>[method]tcp-socket.get-address-family: funcWhether this is a IPv4 or IPv6 socket.
+This is the value passed to the constructor.
+Equivalent to the SO_DOMAIN socket option.
+self: borrow<tcp-socket>[method]tcp-socket.set-listen-backlog-size: funcHints 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.
not-supported: (set) The platform does not support changing the backlog size after the initial listen.invalid-argument: (set) The provided value was 0.invalid-state: (set) The socket is in the connecting or connected state.self: borrow<tcp-socket>value: u64error-code>[method]tcp-socket.get-keep-alive-enabled: funcEnables or disables keepalive.
+The keepalive behavior can be adjusted using:
+keep-alive-idle-timekeep-alive-intervalkeep-alive-count
+These properties can be configured while keep-alive-enabled is
+false, but only come into effect when keep-alive-enabled is true.Equivalent to the SO_KEEPALIVE socket option.
+self: borrow<tcp-socket>bool, error-code>[method]tcp-socket.set-keep-alive-enabled: funcself: borrow<tcp-socket>value: boolerror-code>[method]tcp-socket.get-keep-alive-idle-time: funcAmount 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)
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>duration, error-code>[method]tcp-socket.set-keep-alive-idle-time: funcself: borrow<tcp-socket>value: durationerror-code>[method]tcp-socket.get-keep-alive-interval: funcThe 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>duration, error-code>[method]tcp-socket.set-keep-alive-interval: funcself: borrow<tcp-socket>value: durationerror-code>[method]tcp-socket.get-keep-alive-count: funcThe 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>u32, error-code>[method]tcp-socket.set-keep-alive-count: funcself: borrow<tcp-socket>value: u32error-code>[method]tcp-socket.get-hop-limit: funcEquivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
+If the provided value is 0, an invalid-argument error is returned.
invalid-argument: (set) The TTL value must be 1 or higher.self: borrow<tcp-socket>u8, error-code>[method]tcp-socket.set-hop-limit: funcself: borrow<tcp-socket>value: u8error-code>[method]tcp-socket.get-receive-buffer-size: funcKernel 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.
+invalid-argument: (set) The provided value was 0.self: borrow<tcp-socket>u64, error-code>[method]tcp-socket.set-receive-buffer-size: funcself: borrow<tcp-socket>value: u64error-code>[method]tcp-socket.get-send-buffer-size: funcself: borrow<tcp-socket>u64, error-code>[method]tcp-socket.set-send-buffer-size: funcself: borrow<tcp-socket>value: u64error-code>[static]udp-socket.create: funcCreate 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.
address-family: ip-address-familyudp-socket>, error-code>[method]udp-socket.bind: funcBind 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.
invalid-argument: The local-address has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-state: The socket is already bound. (EINVAL)address-in-use: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use: Address is already in use. (EADDRINUSE)address-not-bindable: local-address is not an address that can be bound to. (EADDRNOTAVAIL)self: borrow<udp-socket>local-address: ip-socket-addresserror-code>[method]udp-socket.connect: funcAssociate 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:
send can only be used to send to this destination.receive will only return datagrams sent from the provided remote-address.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.
+invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)If the socket is already connected, some platforms (e.g. Linux) +require a disconnect before connecting to a different peer address.
+self: borrow<udp-socket>remote-address: ip-socket-addresserror-code>[method]udp-socket.disconnect: funcDissociate 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.
invalid-state: The socket is not connected.self: borrow<udp-socket>error-code>[method]udp-socket.send: funcSend 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.
invalid-argument: The remote-address has the wrong address family. (EAFNOSUPPORT)invalid-argument: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)invalid-argument: The socket is in "connected" mode and remote-address is some value that does not match the address passed to connect. (EISCONN)invalid-argument: The socket is not "connected" and no value for remote-address was provided. (EDESTADDRREQ)remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)connection-refused: The connection was refused. (ECONNREFUSED)datagram-too-large: The datagram is too large. (EMSGSIZE)address-in-use: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)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.
self: borrow<udp-socket>data: list<u8>remote-address: option<ip-socket-address>error-code>[method]udp-socket.receive: funcReceive 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.
invalid-state: The socket has not been bound yet.remote-unreachable: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)connection-refused: The connection was refused. (ECONNREFUSED)self: borrow<udp-socket>u8>, ip-socket-address), error-code>[method]udp-socket.get-local-address: funcGet 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
+addressis unspecified.
WASI is stricter and requires get-local-address to return
+invalid-state when the socket hasn't been bound yet.
invalid-state: The socket is not bound to any local address.self: borrow<udp-socket>ip-socket-address, error-code>[method]udp-socket.get-remote-address: funcGet the address the socket is currently "connected" to.
+invalid-state: The socket is not "connected" to a specific remote address. (ENOTCONN)self: borrow<udp-socket>ip-socket-address, error-code>[method]udp-socket.get-address-family: funcWhether this is a IPv4 or IPv6 socket.
+This is the value passed to the constructor.
+Equivalent to the SO_DOMAIN socket option.
+self: borrow<udp-socket>[method]udp-socket.get-unicast-hop-limit: funcEquivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
+If the provided value is 0, an invalid-argument error is returned.
invalid-argument: (set) The TTL value must be 1 or higher.self: borrow<udp-socket>u8, error-code>[method]udp-socket.set-unicast-hop-limit: funcself: borrow<udp-socket>value: u8error-code>[method]udp-socket.get-receive-buffer-size: funcKernel 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.
+invalid-argument: (set) The provided value was 0.self: borrow<udp-socket>u64, error-code>[method]udp-socket.set-receive-buffer-size: funcself: borrow<udp-socket>value: u64error-code>[method]udp-socket.get-send-buffer-size: funcself: borrow<udp-socket>u64, error-code>[method]udp-socket.set-send-buffer-size: funcself: borrow<udp-socket>value: u64error-code>type ip-address+
variant error-codeLookup error codes.
+Access denied. +
POSIX equivalent: EACCES, EPERM
+`name` is a syntactically invalid domain name or IP address. +
POSIX equivalent: EINVAL
+Name does not exist or has no suitable associated IP addresses. +
POSIX equivalent: EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY
+A temporary failure in name resolution occurred. +
POSIX equivalent: EAI_AGAIN
+A permanent failure in name resolution occurred. +
POSIX equivalent: EAI_FAIL
+A catch-all for errors not captured by the existing variants. +Implementations can use this to extend the error type without +breaking existing code. +
resolve-addresses: funcResolve 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.
+ip-address>, error-code>