sock_open()
Create an endpoint for communication.
Description
The sock_open()
function creates an endpoint for communication and returns a file descriptor that refers to that endpoint. The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process.
Syntax
;;; Note: This is similar to `socket` in POSIX using PF_INET
;;;
;;; for the process.
;;; call will be the lowest-numbered file descriptor not currently open
;;; tor that refers to that endpoint. The file descriptor returned by a successful
;;; creates an endpoint for communication and returns a file descriptor
;;;
;;; Create an endpoint for communication.
(@interface func (export "sock_open")
;;; Address family
(param $af $address_family)
;;; Socket type, either datagram or stream
(param $socktype $sock_type)
;;; Socket protocol
(param $sock_proto $sock_proto)
;;; The file descriptor of the socket that has been opened.
(result $error (expected $fd (error $errno)))
)
Parameters
ctx
: A mutable reference to the function environment.af
: The address family of the socket.ty
: The socket type, either datagram or stream.pt
: The socket protocol.ro_sock
: A WebAssembly pointer to a memory location where the file descriptor of the opened socket will be stored.
Return Value
The function returns an Errno
value indicating the outcome of the operation. If the operation is successful, Errno::Success
is returned. If an error occurs, an appropriate Errno
value is returned.
Notes
- The
sock_open()
function creates an endpoint for communication. - The endpoint is created using the specified address family (
af
), socket type (ty
), and socket protocol (pt
). - The file descriptor returned by the function refers to the opened socket endpoint.
- The file descriptor will be the lowest-numbered file descriptor not currently open for the process.
- The function
sock_open()
is similar to thesocket
function in POSIX, using thePF_INET
address family. - The behavior and limitations of the
sock_open()
function may vary depending on the specific runtime environment and underlying networking implementation. It is important to consult the documentation or specifications of the specific environment to understand its behavior in that context.
Address Family Values
Type | Value | Description |
---|---|---|
AF_UNSPEC | 0 | Unspecified placeholder |
AF_INET | 1 | Represents a IPv4 address family, and will require a sockaddr_in when binding |
AF_INET6 | 2 | Represents a IPv6 address family, and will require a sockaddr_in6 when binding |
AF_LOCAL | 3 | Internal socket used for communicating within the same system for IPC calls, this will require a sockaddr_un when binding |
Please refer to this file (opens in a new tab) in the case the value you are looking for isn't here
Socket Type Values
Type | Value | Description |
---|---|---|
SOCK_STREAM | 1 | TCP Socket |
SOCK_DGRAM | 2 | UDP Socket |
SOCK_CLOEXEC | 0x00002000 | This is a flag that can be combined with other socket types using the bitwise OR operator | |
Please refer to this file (opens in a new tab) in the case the value you are looking for isn't here