All Manuals > LispWorks® User Guide and Reference Manual > 32 The COMM Package

accept-tcp-connections-creating-async-io-states Function


Starts accepting TCP connections to a port within a wait-state-collection.




accept-tcp-connections-creating-async-io-states collection service connection-function &key init-function init-timeout backlog address nodelay keepalive ipv6 reuseport create-state name queue-output handle-name user-info ssl-ctx ssl-side ctx-configure-callback ssl-configure-callback handshake-timeout ssl-error-callback => accepting-handle

An integer, a string or nil.
A function designator.
nil or a function designator.
nil or a non-negative real number.
nil or a positive integer.
An integer, an ipv6-address object, a string or nil.
A generalized boolean.
A generalized boolean.
The keyword :any, nil, t or the keyword :both.
A boolean. Note: not supported on all platforms.
A boolean.
A Lisp object.
A boolean.
A Lisp object.
A Lisp object.
A symbol, a foreign pointer or a server ssl-abstract-context.
One of the keywords :client, :server or :both.
A function designator or nil. The default value is nil.
A function designator or nil. The default value is nil.
A real or nil (the default).
A function designator.
An accepting-handle object.

The function accept-tcp-connections-creating-async-io-states starts accepting TCP connections to the port service within the wait-state-collection collection.

service is interpreted as described in 25.3 Specifying the target for connecting and binding a socket.

Each time a connection is made, connection-function is called with two arguments: accepting-handle and (by default) a new async-io-state for the connected socket. The function typically calls async-io-state-read-buffer, async-io-state-write-buffer or async-io-state-read-with-checking to start performing I/O. The keyword :create-state can be used to tell accept-tcp-connections-creating-async-io-states not to create the state and instead pass the socket itself. This is useful when you want to do the I/O "somewhere else", either by creating a socket-stream and using ordinary read/write functions on it, or using a different wait-state-collection. The default value of create-state is t.

If init-function is non-nil, it is called after the listening socket has been bound to the service. init-function should take one argument: socket. socket is the socket used by the server, which can be used to determine the bound port number by calling get-socket-address.

If the port number specified by service is already in use, then accept-tcp-connections-creating-async-io-states periodically tries to bind to the port number for up to 1 minute (or init-timeout seconds if this is non-nil).

queue-output controls what happens if you try to perform a write operation on any of the states that accept-tcp-connections-creating-async-io-states creates while another write operation is in progress on the same state. When queue-output is nil, such an operation will cause an error. When queue-output is non-nil, the second write operation is queued and actually executed later. The default value of queue-output is nil.

The result accepting-handle is an object of type accepting-handle, which is the same object that will be passed to connection-function. It can be used to stop accepting and closing the socket by close-accepting-handle, and also retrieving the socket.

handle-name and user-info are stored in the accepting-handle object. user-info is not touched in any way by the system, and it is intended for you to pass information to connection-function. handle-name is used when printing the handle, but is not accessed otherwise.

When ssl-ctx is non-nil, accept-tcp-connections-creating-async-io-states always creates an async-io-state (ignoring create-state), and attaches SSL to it. ssl-side, ssl-ctx, ctx-configure-callback, ssl-configure-callback and handshake-timeout are interpreted as described in 25.8.6 Keyword arguments for use with SSL.

ssl-error-callback defaults to error. It is called when there is any error while attaching SSL to the new socket. Such errors can be either the result of an error in the configuration functions, or (more commonly) an error during the SSL handshake. ssl-error-callback is called from the thread of the wait-state-collection that was passed to accept-tcp-connections-creating-async-io-states. The socket is discarded before Sssl-error-callback is called.

For details of backlog, address, nodelay, keepalive, ipv6 and reuseport, see start-up-server.

The default value of nodelay is t.

The default value of ipv6 is :any.

The default value of name is a string "Listening".


accept-tcp-connections-creating-async-io-states binds the socket synchronously, that is when it returns successfully the socket is already bound. However, it already started accepting connections. If you need to access the socket after binding and before starting to accept connections, then do this in init-function.

When create-state is nil, the socket handle that connection-function receives can be use in a socket-stream, async-io-state or in FLI functions using the native TCP socket interface. If the socket handle is stored in a socket-stream or an async-io-state, it is closed automatically when the object is closed (by close or close-async-io-state), otherwise you need to close it by calling close-socket-handle when you have finished with it.

See also

25.7.2 The Async-I/O-State API
25 TCP and UDP socket communication and SSL

LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:26