6.95. kink/socket/UDP¶
6.95.1. type udp¶
A `udp` is a socket of a message based protocol.
Currently, UDP on only IPv4 and IPv6 are supported. The following features are not supported:
• Unix domain datagram socket
• Multicast
• IP_PKTINFO and IPV6_PKTINFO on Linux, and corresponding features on other OSes
6.95.1.1. Udp.connect(Remote ...[$config={}])¶
`connect` sets the remote address to the socket.
Config methods:
• C.on_success($success): default = {}
• C.on_error($error): default = {(:Exc) Exc.raise }
If the address is successfully set, `connect` tail-calls $success with no arg.
If an IO error occurs, `connect` tail-calls $error with an `exception`.
Preconditions
`Remote` must be a `socket_address`, whose protocol family is acceptable by the socket.
$success must be a thunk.
$error must be a function which takes an `exception`.
6.95.1.2. Udp.bind(Local ...[$config={}])¶
`bind` binds a local address to the socket.
Config methods:
• C.on_success($success): default = {}
• C.on_error($error): default = {(:Exc) Exc.raise }
If the address is successfully bound, `bind` tail-calls $success with no arg.
If an IO error occurs, `bind` tail-calls $error with an `exception`.
Preconditions
`Local` must be a `socket_address`, whose protocol family matches one of the socket.
$success must be a thunk.
$error must be a function which takes an `exception`
6.95.1.3. Udp.close(...[$config={}])¶
`close` closes the socket.
Config methods:
• C.on_success($success): default = {}
• C.on_error($error): default = {(:Exc) Exc.raise }
If the socket is closed successfully, `close` tail-calls $success with no arg.
If an IO error occurs, `close` tail-calls $error with an `exception`.
Preconditions
$success must be a thunk.
$error must be a function which takes an `exception`
6.95.1.4. Udp.receive(Max_size ...[$config={}])¶
`receive` method receives a datagram on the socket.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = {(:Exc) Exc.raise }
`Max_size` is the maximum byte count of the datagram to receive. If the datagram is longer than the specified length, it is shortened to `Max_size`.
`receive` method waits until a datagram is available, or an IO error occurs. If a datagram becomes available, `receive` tail-calls $success with a `datagram`. If an IO error occurs, `receive` tail-calls $error with an `exception`.
Preconditions
`Max_size` must be a non-negative integer `num`.
$success must be a function which takes a `datagram`.
$error must be a function which takes an `exception`.
6.95.1.5. Udp.send(Datagram ...[$config={}])¶
`send` sends a datagram to the specified destination.
Config methods:
• C.on_success($success): default = {}
• C.on_error($error): default = {(:Exc) Exc.raise }
`send` waits until write buffer is available, or an IO error occurs.
If the datagram is written to the write buffer, `send` tail-calls $success with no arg.
If an IO error occurs, `send` tail-calls $error with an `exception`.
Preconditions
`Datagram` must be a `datagram` value.
The protocol family of the remote address of `Datagram` must be accepted by the socket.
$success must be a thunk.
$error must be a function which takes an `exception`.
6.95.1.6. Udp.input¶
`input` method returns an `input` of the socket.
Closing the input will close the socket.
6.95.1.7. Udp.output¶
`output` method returns an `output` of the socket.
Closing the output will close the socket.
6.95.1.8. Udp.local_address(...[$config={}])¶
`local_address` retrieves a `socket_address` of the local address of the socket.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = {(:Exc) Exc.raise }
If the local address is available, `local_address` tail-calls $success with the `socket_address`.
If an IO error occurs, `local_address` tail-calls $error with an `exception`.
Preconditions
$success must be a function which takes a `socket_address`.
$error must be a function which takes an `exception`.
6.95.1.9. Udp.remote_address(...[$config={}])¶
`remote_address` retrieves a `socket_address` of the remote address of the socket.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = {(:Exc) Exc.raise }
If the remote address is available, `remote_address` tail-calls $success with the `socket_address`.
If an IO error occurs, `remote_address` tail-calls $error with an `exception`.
Preconditions
$success must be a function which takes a `socket_address`.
$error must be a function which takes an `exception`.
6.95.1.10. Udp.so_sndbuf¶
`so_sndbuf` returns a `ref` of a non-negative integer `num` of SO_SNDBUF option.
6.95.1.11. Udp.so_rcvbuf¶
`so_rcvbuf` return a `ref` of a non-negative integer `num` SO_RCVBUF option.
6.95.1.12. Udp.so_reuseaddr¶
`so_reuseaddr` returns a `ref` of a `bool` of SO_REUSEADDR option.
6.95.1.13. Udp.so_broadcast¶
`so_broadcast` returns a `ref` of a `bool` of SO_BROADCAST option.
6.95.2. UDP.open(...[Protocol_family=PROTOCOL_FAMILY.ipv6 $config={}])¶
`open` makes a new datagram socket.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = {(:Exc) Exc.raise }
• C.on_unsupported($unsupported): default = a function which tail-calls $error
If a socket is created, `open` tail-calls $success with the `udp` value.
If an IO error occurs, `open` tail-calls $error with an `exception`.
If `Protocol_family` is not supported by the runtime, `open` tail-calls $unsupported with no arg.
Preconditions
`Protocol_family` must be a `protocol_family` value.
$success must be a function which takes a `udp`.
$error must be a function which takes an `exception`.
$unsupported must be a thunk.
6.95.3. UDP.is?(Val)¶
`is?` method returns whether `Val` is a `udp` value.