Next: , Previous: , Up: posix   [Index]


4.33 TCP server sockets

The library (vicare posix tcp-server-sockets) implements facilities to create TCP sockets to be used by networking servers; it is build on top of (vicare posix).

The following bindings are exported by the library (vicare posix tcp-server-sockets).

Function: make-master-sock interface port max-pending-connections

Given a string interface representing a network interface to listen to and a network port number: open a master server socket, IP version 4, TCP protocol, bind it to the interface and port, enable it to listen for connections. Return the master socket descriptor.

interface must be a string representing the server interface to bind to; for example localhost. interface is used as first argument in calls to getaddrinfo, getaddrinfo.

port must be an exact integer representing the server port to listen to; for example 8081.

max-pending-connections must be a non-negative fixnum representing the maximum number of pending connections.

The returned socket is configured to linger for 1 second (SO_LINGER) and the address is configured to be reused (SO_REUSEADDR).

Whenever the returned socket becomes readable: it means that at least one incoming connection is pending.

Function: close-master-sock master-sock

Close the master socket descriptor returned by a previous call to make-master-sock.

Function: make-server-sock-and-port master-sock

Given the socket descriptor master-sock representing a master socket descriptor, already bound to an address, with a pending connection: accept the connection and configure the resulting server socket descriptor to non–blocking mode.

Return 3 values:

  1. The server socket descriptor.
  2. A Scheme input/output binary port wrapping the descriptor. Closing the Scheme port will also close the server socket.
  3. A bytevector representing the client address as struct sockaddr.
Function: close-server-port server-port

Close the Scheme port wrapping a server socket descriptor returned by a previous call to make-server-sock-and-port.


Next: , Previous: , Up: posix   [Index]