| 1 |
@since(version = 0.2.0) |
| 2 |
interface network { |
| 3 |
@unstable(feature = network-error-code) |
| 4 |
use wasi:io/[email protected].{error}; |
| 5 |
|
| 6 |
/// An opaque resource that represents access to (a subset of) the network. |
| 7 |
/// This enables context-based security for networking. |
| 8 |
/// There is no need for this to map 1:1 to a physical network interface. |
| 9 |
@since(version = 0.2.0) |
| 10 |
resource network; |
| 11 |
|
| 12 |
/// Error codes. |
| 13 |
/// |
| 14 |
/// In theory, every API can return any error code. |
| 15 |
/// In practice, API's typically only return the errors documented per API |
| 16 |
/// combined with a couple of errors that are always possible: |
| 17 |
/// - `unknown` |
| 18 |
/// - `access-denied` |
| 19 |
/// - `not-supported` |
| 20 |
/// - `out-of-memory` |
| 21 |
/// - `concurrency-conflict` |
| 22 |
/// |
| 23 |
/// See each individual API for what the POSIX equivalents are. They sometimes differ per API. |
| 24 |
@since(version = 0.2.0) |
| 25 |
enum error-code { |
| 26 |
/// Unknown error |
| 27 |
unknown, |
| 28 |
|
| 29 |
/// Access denied. |
| 30 |
/// |
| 31 |
/// POSIX equivalent: EACCES, EPERM |
| 32 |
access-denied, |
| 33 |
|
| 34 |
/// The operation is not supported. |
| 35 |
/// |
| 36 |
/// POSIX equivalent: EOPNOTSUPP |
| 37 |
not-supported, |
| 38 |
|
| 39 |
/// One of the arguments is invalid. |
| 40 |
/// |
| 41 |
/// POSIX equivalent: EINVAL |
| 42 |
invalid-argument, |
| 43 |
|
| 44 |
/// Not enough memory to complete the operation. |
| 45 |
/// |
| 46 |
/// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY |
| 47 |
out-of-memory, |
| 48 |
|
| 49 |
/// The operation timed out before it could finish completely. |
| 50 |
timeout, |
| 51 |
|
| 52 |
/// This operation is incompatible with another asynchronous operation that is already in progress. |
| 53 |
/// |
| 54 |
/// POSIX equivalent: EALREADY |
| 55 |
concurrency-conflict, |
| 56 |
|
| 57 |
/// Trying to finish an asynchronous operation that: |
| 58 |
/// - has not been started yet, or: |
| 59 |
/// - was already finished by a previous `finish-*` call. |
| 60 |
/// |
| 61 |
/// Note: this is scheduled to be removed when `future`s are natively supported. |
| 62 |
not-in-progress, |
| 63 |
|
| 64 |
/// The operation has been aborted because it could not be completed immediately. |
| 65 |
/// |
| 66 |
/// Note: this is scheduled to be removed when `future`s are natively supported. |
| 67 |
would-block, |
| 68 |
|
| 69 |
|
| 70 |
/// The operation is not valid in the socket's current state. |
| 71 |
invalid-state, |
| 72 |
|
| 73 |
/// A new socket resource could not be created because of a system limit. |
| 74 |
new-socket-limit, |
| 75 |
|
| 76 |
/// A bind operation failed because the provided address is not an address that the `network` can bind to. |
| 77 |
address-not-bindable, |
| 78 |
|
| 79 |
/// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. |
| 80 |
address-in-use, |
| 81 |
|
| 82 |
/// The remote address is not reachable |
| 83 |
remote-unreachable, |
| 84 |
|
| 85 |
|
| 86 |
/// The TCP connection was forcefully rejected |
| 87 |
connection-refused, |
| 88 |
|
| 89 |
/// The TCP connection was reset. |
| 90 |
connection-reset, |
| 91 |
|
| 92 |
/// A TCP connection was aborted. |
| 93 |
connection-aborted, |
| 94 |
|
| 95 |
|
| 96 |
/// The size of a datagram sent to a UDP socket exceeded the maximum |
| 97 |
/// supported size. |
| 98 |
datagram-too-large, |
| 99 |
|
| 100 |
|
| 101 |
/// Name does not exist or has no suitable associated IP addresses. |
| 102 |
name-unresolvable, |
| 103 |
|
| 104 |
/// A temporary failure in name resolution occurred. |
| 105 |
temporary-resolver-failure, |
| 106 |
|
| 107 |
/// A permanent failure in name resolution occurred. |
| 108 |
permanent-resolver-failure, |
| 109 |
} |
| 110 |
|
| 111 |
/// Attempts to extract a network-related `error-code` from the stream |
| 112 |
/// `error` provided. |
| 113 |
/// |
| 114 |
/// Stream operations which return `stream-error::last-operation-failed` |
| 115 |
/// have a payload with more information about the operation that failed. |
| 116 |
/// This payload can be passed through to this function to see if there's |
| 117 |
/// network-related information about the error to return. |
| 118 |
/// |
| 119 |
/// Note that this function is fallible because not all stream-related |
| 120 |
/// errors are network-related errors. |
| 121 |
@unstable(feature = network-error-code) |
| 122 |
network-error-code: func(err: borrow<error>) -> option<error-code>; |
| 123 |
|
| 124 |
@since(version = 0.2.0) |
| 125 |
enum ip-address-family { |
| 126 |
/// Similar to `AF_INET` in POSIX. |
| 127 |
ipv4, |
| 128 |
|
| 129 |
/// Similar to `AF_INET6` in POSIX. |
| 130 |
ipv6, |
| 131 |
} |
| 132 |
|
| 133 |
@since(version = 0.2.0) |
| 134 |
type ipv4-address = tuple<u8, u8, u8, u8>; |
| 135 |
@since(version = 0.2.0) |
| 136 |
type ipv6-address = tuple<u16, u16, u16, u16, u16, u16, u16, u16>; |
| 137 |
|
| 138 |
@since(version = 0.2.0) |
| 139 |
variant ip-address { |
| 140 |
ipv4(ipv4-address), |
| 141 |
ipv6(ipv6-address), |
| 142 |
} |
| 143 |
|
| 144 |
@since(version = 0.2.0) |
| 145 |
record ipv4-socket-address { |
| 146 |
/// sin_port |
| 147 |
port: u16, |
| 148 |
/// sin_addr |
| 149 |
address: ipv4-address, |
| 150 |
} |
| 151 |
|
| 152 |
@since(version = 0.2.0) |
| 153 |
record ipv6-socket-address { |
| 154 |
/// sin6_port |
| 155 |
port: u16, |
| 156 |
/// sin6_flowinfo |
| 157 |
flow-info: u32, |
| 158 |
/// sin6_addr |
| 159 |
address: ipv6-address, |
| 160 |
/// sin6_scope_id |
| 161 |
scope-id: u32, |
| 162 |
} |
| 163 |
|
| 164 |
@since(version = 0.2.0) |
| 165 |
variant ip-socket-address { |
| 166 |
ipv4(ipv4-socket-address), |
| 167 |
ipv6(ipv6-socket-address), |
| 168 |
} |
| 169 |
} |