Debian Codegraph @

vendor/wit-component/tests/interfaces/wasi-http/deps/sockets/network.wit

raw
1
2 interface network {
3 /// An opaque resource that represents access to (a subset of) the network.
4 /// This enables context-based security for networking.
5 /// There is no need for this to map 1:1 to a physical network interface.
6 resource network;
7
8 /// Error codes.
9 ///
10 /// In theory, every API can return any error code.
11 /// In practice, API's typically only return the errors documented per API
12 /// combined with a couple of errors that are always possible:
13 /// - `unknown`
14 /// - `access-denied`
15 /// - `not-supported`
16 /// - `out-of-memory`
17 /// - `concurrency-conflict`
18 ///
19 /// See each individual API for what the POSIX equivalents are. They sometimes differ per API.
20 enum error-code {
21 // ### GENERAL ERRORS ###
22
23 /// Unknown error
24 unknown,
25
26 /// Access denied.
27 ///
28 /// POSIX equivalent: EACCES, EPERM
29 access-denied,
30
31 /// The operation is not supported.
32 ///
33 /// POSIX equivalent: EOPNOTSUPP
34 not-supported,
35
36 /// One of the arguments is invalid.
37 ///
38 /// POSIX equivalent: EINVAL
39 invalid-argument,
40
41 /// Not enough memory to complete the operation.
42 ///
43 /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY
44 out-of-memory,
45
46 /// The operation timed out before it could finish completely.
47 timeout,
48
49 /// This operation is incompatible with another asynchronous operation that is already in progress.
50 ///
51 /// POSIX equivalent: EALREADY
52 concurrency-conflict,
53
54 /// Trying to finish an asynchronous operation that:
55 /// - has not been started yet, or:
56 /// - was already finished by a previous `finish-*` call.
57 ///
58 /// Note: this is scheduled to be removed when `future`s are natively supported.
59 not-in-progress,
60
61 /// The operation has been aborted because it could not be completed immediately.
62 ///
63 /// Note: this is scheduled to be removed when `future`s are natively supported.
64 would-block,
65
66
67
68 // ### TCP & UDP SOCKET ERRORS ###
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 // ### TCP SOCKET ERRORS ###
87
88 /// The connection was forcefully rejected
89 connection-refused,
90
91 /// The connection was reset.
92 connection-reset,
93
94 /// A connection was aborted.
95 connection-aborted,
96
97
98 // ### UDP SOCKET ERRORS ###
99 datagram-too-large,
100
101
102 // ### NAME LOOKUP ERRORS ###
103
104 /// Name does not exist or has no suitable associated IP addresses.
105 name-unresolvable,
106
107 /// A temporary failure in name resolution occurred.
108 temporary-resolver-failure,
109
110 /// A permanent failure in name resolution occurred.
111 permanent-resolver-failure,
112 }
113
114 enum ip-address-family {
115 /// Similar to `AF_INET` in POSIX.
116 ipv4,
117
118 /// Similar to `AF_INET6` in POSIX.
119 ipv6,
120 }
121
122 type ipv4-address = tuple<u8, u8, u8, u8>;
123 type ipv6-address = tuple<u16, u16, u16, u16, u16, u16, u16, u16>;
124
125 variant ip-address {
126 ipv4(ipv4-address),
127 ipv6(ipv6-address),
128 }
129
130 record ipv4-socket-address {
131 port: u16, // sin_port
132 address: ipv4-address, // sin_addr
133 }
134
135 record ipv6-socket-address {
136 port: u16, // sin6_port
137 flow-info: u32, // sin6_flowinfo
138 address: ipv6-address, // sin6_addr
139 scope-id: u32, // sin6_scope_id
140 }
141
142 variant ip-socket-address {
143 ipv4(ipv4-socket-address),
144 ipv6(ipv6-socket-address),
145 }
146
147 }