File: tcp-create-socket.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 (30 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download | duplicates (9)
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
@since(version = 0.2.0)
interface tcp-create-socket {
    @since(version = 0.2.0)
    use network.{network, error-code, ip-address-family};
    @since(version = 0.2.0)
    use tcp.{tcp-socket};

    /// Create a new TCP socket.
    ///
    /// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX.
    /// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise.
    ///
    /// This function does not require a network capability handle. This is considered to be safe because
    /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect`
    /// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
    ///
    /// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
    ///
    /// # Typical errors
    /// - `not-supported`:     The specified `address-family` is not supported. (EAFNOSUPPORT)
    /// - `new-socket-limit`:  The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
    ///
    /// # References
    /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
    /// - <https://man7.org/linux/man-pages/man2/socket.2.html>
    /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw>
    /// - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2>
    @since(version = 0.2.0)
    create-tcp-socket: func(address-family: ip-address-family) -> result<tcp-socket, error-code>;
}