File: network.wit

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (153 lines) | stat: -rw-r--r-- 4,449 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
@since(version = 0.2.0)
interface network {
    /// An opaque resource that represents access to (a subset of) the network.
    /// This enables context-based security for networking.
    /// There is no need for this to map 1:1 to a physical network interface.
    @since(version = 0.2.0)
    resource network;

    /// Error codes.
    ///
    /// In theory, every API can return any error code.
    /// In practice, API's typically only return the errors documented per API
    /// combined with a couple of errors that are always possible:
    /// - `unknown`
    /// - `access-denied`
    /// - `not-supported`
    /// - `out-of-memory`
    /// - `concurrency-conflict`
    ///
    /// See each individual API for what the POSIX equivalents are. They sometimes differ per API.
    @since(version = 0.2.0)
    enum error-code {
        /// Unknown error
        unknown,

        /// Access denied.
        ///
        /// POSIX equivalent: EACCES, EPERM
        access-denied,

        /// The operation is not supported.
        ///
        /// POSIX equivalent: EOPNOTSUPP
        not-supported,

        /// One of the arguments is invalid.
        ///
        /// POSIX equivalent: EINVAL
        invalid-argument,

        /// Not enough memory to complete the operation.
        ///
        /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY
        out-of-memory,

        /// The operation timed out before it could finish completely.
        timeout,

        /// This operation is incompatible with another asynchronous operation that is already in progress.
        ///
        /// POSIX equivalent: EALREADY
        concurrency-conflict,

        /// Trying to finish an asynchronous operation that:
        /// - has not been started yet, or:
        /// - was already finished by a previous `finish-*` call.
        ///
        /// Note: this is scheduled to be removed when `future`s are natively supported.
        not-in-progress,

        /// The operation has been aborted because it could not be completed immediately.
        ///
        /// Note: this is scheduled to be removed when `future`s are natively supported.
        would-block,


        /// The operation is not valid in the socket's current state.
        invalid-state,

        /// A new socket resource could not be created because of a system limit.
        new-socket-limit,

        /// A bind operation failed because the provided address is not an address that the `network` can bind to.
        address-not-bindable,

        /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available.
        address-in-use,

        /// The remote address is not reachable
        remote-unreachable,


        /// The TCP connection was forcefully rejected
        connection-refused,

        /// The TCP connection was reset.
        connection-reset,

        /// A TCP connection was aborted.
        connection-aborted,


        /// The size of a datagram sent to a UDP socket exceeded the maximum
        /// supported size.
        datagram-too-large,


        /// Name does not exist or has no suitable associated IP addresses.
        name-unresolvable,

        /// A temporary failure in name resolution occurred.
        temporary-resolver-failure,

        /// A permanent failure in name resolution occurred.
        permanent-resolver-failure,
    }

    @since(version = 0.2.0)
    enum ip-address-family {
        /// Similar to `AF_INET` in POSIX.
        ipv4,

        /// Similar to `AF_INET6` in POSIX.
        ipv6,
    }

    @since(version = 0.2.0)
    type ipv4-address = tuple<u8, u8, u8, u8>;
    @since(version = 0.2.0)
    type ipv6-address = tuple<u16, u16, u16, u16, u16, u16, u16, u16>;

    @since(version = 0.2.0)
    variant ip-address {
        ipv4(ipv4-address),
        ipv6(ipv6-address),
    }

    @since(version = 0.2.0)
    record ipv4-socket-address {
        /// sin_port
        port: u16,
        /// sin_addr
        address: ipv4-address,
    }

    @since(version = 0.2.0)
    record ipv6-socket-address {
        /// sin6_port
        port: u16,
        /// sin6_flowinfo
        flow-info: u32,
        /// sin6_addr
        address: ipv6-address,
        /// sin6_scope_id
        scope-id: u32,
    }

    @since(version = 0.2.0)
    variant ip-socket-address {
        ipv4(ipv4-socket-address),
        ipv6(ipv6-socket-address),
    }
}