Network Interface Guide

Asynchronous Connection-Mode Service

For connection-mode service, an application can arrange for not only the data transfer, but for the establishment of the connection itself to be done asynchronously. The sequence of operations depends on whether the process is attempting to connect to another process or is awaiting connection attempts.

Asynchronously Establishing a Connection

A process can attempt a connection and asynchronously complete the connection. The process first creates the connecting endpoint, and, using fcntl(2), configures the endpoint for non-blocking operation. As with connectionless data transfers, the endpoint can also be configured for asynchronous notification upon completion of the connection and subsequent data transfers. The connecting process then uses the t_connect(3NSL) function to initiate setting up the transfer. Then the t_rcvconnect(3NSL) function is used to confirm the establishment of the connection.

Asynchronous Use of a Connection

To asynchronously await connections, a process first establishes a non-blocking endpoint bound to a service address. When either the result of poll(2) or an asynchronous notification indicates that a connection request has arrived, the process can get the connection request by using the t_listen(3NSL) function. To accept the connection, the process uses the t_accept(3NSL) function. The responding endpoint must be separately configured for asynchronous data transfers.

The following example illustrates how to request a connection asynchronously.

#include <tiuser.h>
int             fd;
struct t_call   *call;

	fd = .../* establish a non-blocking endpoint */

	call = (struct t_call *) t_alloc(fd, T_CALL, T_ADDR);
	.../* initialize call structure */
	t_connect(fd, call, call);

	/* connection request is now proceeding asynchronously */

	.../* receive indication that connection has been accepted */
	t_rcvconnect(fd, &call);

The following example illustrates listening for connections asynchronously.

#include <tiuser.h>
int             fd, res_fd;
struct t_call   call;

	fd = ... /* establish non-blocking endpoint */

	.../*receive indication that connection request has arrived
	call = (struct t_call *) t_alloc(fd, T_CALL, T_ALL);
	t_listen(fd, &call);

	.../* determine whether or not to accept connection */
	res_fd = ... /* establish non-blocking endpoint for response
	t_accept(fd, res_fd, call);