5.94. kink/socket/TCP_SERVER¶
5.94.1. type tcp_server¶
tcp_server type represents a listening socket of 1) TCP/IP, or 2) stream based Unix Domain Socket.
5.94.1.1. Serv.bind_listen(Local ...[$config_fun={}])¶
`bind_listen` binds the local address to the listening socket, and starts waiting for incoming connections.
Config methods:
• C.backlog(Backlog): default = the runtime default
• C.on_success($success): default = {}
• C.on_error($error): default = {(:Exc) Exc.raise }
`Backlog` is a preferred maximum number of pending connections. It can be adjusted by the runtime.
If the address is bound, and the listening socket starts waiting for incoming connections, `bind_listen` tail-calls $success with no arg.
If an error occurs, `bind_listen` tail-calls $error with an `exception`.
Preconditions
• `Local` must be a `socket_address` whose protocol family is acceptable by the socket.
• `Backlog` must be a positive int `num`.
• $success must be a fun which takes no arg.
• $error must be a fun which takes an `exception`.
5.94.1.2. Serv.accept(...[$config={}])¶
`accept` method accepts an incoming connection.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = {(:Exc) Exc.raise }
`accept` method waits until a connection becomes available, or an IO error occurs.
If a connection is established, `accept` tail-calls $success with a `tcp` val of the connecting socket.
If an IO error occurs, `accept` tail-calls $error with an `exception`.
Precondition
• $success must be a fun which takes a `tcp`
• $error must be a fun which takes an `exception`.
5.94.1.3. Serv.close(...[$config={}])¶
`close` closes the listening 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 fun which takes no arg
• $error must be a fun which takes an `exception`
5.94.1.4. Serv.local_address(...[$config={}])¶
`local_address` retrieves the `socket_address` of the local address of the listening socket.
Config methods:
• C.on_success($present): 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 fun which takes a `socket_address`.
• $error must be a fun which takes an `exception`.
5.94.1.5. Serv.so_reuseaddr?¶
so_reuseaddr? method returns a bool val of SO_REUSEADDR option.
Precondition: The protocol family must be ipv4 or ipv6.
5.94.1.6. Serv.set_so_reuseaddr¶
set_so_reuseaddr method turns on SO_REUSEADDR option.
Precondition: The protocol family must be ipv4 or ipv6.
5.94.1.7. Serv.unset_so_reuseaddr¶
unset_so_reuseaddr method turns off SO_REUSEADDR option.
Precondition: The protocol family must be ipv4 or ipv6.
5.94.1.8. Serv.so_rcvbuf¶
so_rcvbuf method returns the int num of SO_RCVBUF option.
5.94.1.9. Serv.set_so_rcvbuf(Buf_size)¶
set_so_rcvbuf method sets Buf_size as SO_RCVBUF option.
Precondition: Buf_size must be a non-negative int num.
5.94.2. TCP_SERVER.open(...[Protocol_family=PROTOCOL_FAMILY.ipv6 $config={}])¶
`open` method makes a new listening socket.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = {(:Exc) Exc.raise }
• C.on_unsupported($unsupported): default = a fun which calls $error
If a listening socket is created, `open` tail-calls $success with a `tcp_server` of the listening socket.
If an IO error occurs, `open` tail-calls $error with an `exception`.
If Protocol_family is not supported, `open` tail-calls $unsupported with no arg.
Preconditions
• Protocol_family must be a `protocol_family`.
• $success must be a fun which takes a `tcp_server`.
• $error must be a fun which takes an `exception`.
5.94.3. TCP_SERVER.is?(Val)¶
`is?` method returns whether `Val` is a tcp_server.