t_accept(3xti_spx)


t_accept -- accept a connection request

Synopsis

#include "spx_app.h" 

int t_accept ( int spxFd, int spxFd2, struct t_call *call )

Parameters

(IN) spxFd
Passes the file descriptor of the endpoint that is receiving connection requests.

(IN) spxFd2
Passes the file descriptor of the endpoint on which the connection is to be established.

(IN) call
Passes a pointer to (or the address of) a t_call structure that the SPX server application used in its t_listen call. This structure contains the address of the remote transport endpoint, the remote endpoint's connection ID, its allocation number, and the sequence number of the connection request.

Return values

0
Successful

-1
Unsuccessful
If t_accept returns an error, t_errno may be set to one of the following.

TBADF
The specified file descriptor does not refer to a transport endpoint, or the application is illegally accepting a connection on the same endpoint on which the connection indication arrived.

TOUTSTATE
The local transport endpoint or the accepting stream (specified by the accepting fd) is not in the appropriate state for issuing t_accept.

TBADSEQ
The connection request specified by the sequence number in the call structure is invalid.

TLOOK
An asychronous event has occurred on the transport endpoint referenced by spxFd and requires immediate attention.

TSYSERR
A system error has occurred during execution of this function; check errno for possible further information.

Remarks

An SPX/SPXII server application uses the t_accept call to accept a client connection request. The SPX/SPXII server application uses t_snddis to reject the connection request.

This function works as specified in ``Programming with the X/Open Transport Interface (XTI)''.

For server applications (applications that wait for incoming connection requests), we recommend that the server application use two file descriptors. The server uses one file descriptor and socket to listen for incoming connection requests and uses another separate file descriptor and socket to accept a connection request each time a connection request arrives.

Usually the endpoint that listens for connections opens the SPXII driver and binds to a well-known socket (spxFd). Upon receiving a connection request, the SPX/SPXII server opens another file descriptor (spxFd2), binds to a dynamic socket, and issues a t_accept. When both the t_accept and the t_connect calls are successful, the client's t_connect call returns the dynamic socket number of the server. This procedure causes all client/server traffic to be on the server's dynamic socket.

A connection request can be accepted on the same fd as the listen fd (spxFd=spxFd2), but this is not recommended. Only a single connection request can be accepted if file descriptors are equal. The SPXII driver drops any further connection requests to the local transport endpoint (spxFd) because this endpoint is now in the data transfer state.

If a client's connection request timeout is short, the client may time out before the SPXII server application can issue a t_accept call. If the client connection request times out before the server application issues a t_accept call, you need either to extend the client's connection request timeout or to reduce the server's delay between the t_listen and the t_accept.

The SPXII driver detects a transmission failure of a connection request acknowledge and resends it.

If the t_accept call fails with t_errno equal to TOUTSTATE or TSYSERR, the SPXII driver marks the outstanding connection request (that the t_accept was replying to) invalid. If a TOUTSTATE or TSYSERR occurs, the SPXII server application should not retry the t_accept.

If any other errors occur, the SPXII server application can retry the t_accept.

Examples

   { 
      char          *spxDevice = "/dev/nspx2"; 
      int           spxFd; 
      int           spxFd2; 
      struct t_info spxInfo; 
      SPX2_OPTIONS  *reqOpts; 
   

if ((spxFd2 = t_open(spxDevice, O_RDWR, &spxInfo)) < 0) { t_error("t_open failed"); exit(-1); } ...

/* Bind to dynamic socket. I don't want to know what address I am ** bound to. */ ...

if ((t_bind(spxFd2, NULL, NULL)) < 0) { t_error("t_bind failed"); exit(-1); } ...

/* ** spxFd is the file descriptor representing the stream that the ** connection request arrived on. The call structure is also the ** same call structure that was returned from the t_listen when ** the connection request arrived. Some options can be set/changed ** on the t_accept call, but no confirmation will be returned. */

reqOpts = (SPX2_OPTIONS *)rcvcall->opt.buf; reqOpts->spxIILocalWindowSize = 12; reqOpts->spxIIRetryCount = 8; reqOpts->spxIIMinimumRetryDelay = 250; /* 1/4 second */ reqOpts->spxIIMaximumRetryDelta = 2000; /* 2 seconds */

if ((t_accept(spxFd, spxFd2, rcvcall)) < 0) { t_error("t_accept failed"); if (t_errno == TLOOK) { lookVal = t_look(spxFd); printLookVal(lookVal); } exit(-1); } }

State

The state after a successful connection establishment is T_DATAXFER for both the client and server. An unsuccessful t_accept call leaves the state T_IDLE.

References

t_accept(3xti), t_connect(3xti_spx), t_getstate(3xti), t_optmgmt(3xti_spx), t_listen(3xti_spx), t_open(3xti_spx)
30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.