#include "spx_app.h"int t_accept ( int spxFd, int spxFd2, struct t_call *call )
spxFd
spxFd2
call
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.
{ 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); } }