t_rcvdis(3xti_spx)


t_rcvdis -- return a disconnect indication from the remote transport endpoint

Synopsis

#include "spx_app.h" 

int t_rcvdis ( int spxFd, struct t_discon *discon )

"Parameters

(IN) spxFd
Passes the file descriptor of the local transport endpoint.

(IN) discon
Passes the address of a t_discon structure.

(OUT) discon
Receives the information about the disconnect in the t_discon structure.

Return values

0
Successful

-1
Unsuccessful
If any of the following conditions occur, a disconnect indication is generated and passed to the stream head.

In the following situations, the reason integer of the t_discon structure is set accordingly:

TLI_SPX_CONNECTION_FAILED
The remote transport endpoint fails to acknowledge any transmission. This is generated by the SPX/SPXII watchdog after failing to connect to the remote transport endpoint.

or
The SPXII driver could not reliably deliver the data or connection request. The remote transport endpoint doesn't acknowledge transmissions.

or
SPXII has tried a number of times to allocate memory and has failed.

TLI_SPX_CONNECTION_TERMINATED
No error occurred. An SPX/SPXII terminate connection packet was received from the remote transport endpoint.

Remarks

The t_rcvdis function works as specified in t_rcvdis(3xti) and ``Programming with the X/Open Transport Interface (XTI)'' with the following additions:

The t_discon structure has the following format:

   struct t_discon { 
      struct netbuf  udata; 
      int            reason; 
      int            sequence; 
   }; 
The SPXII driver does not use the udata field in the t_discon structure. SPX/SPXII doesn't support the transmission of any user data with a disconnect request.

Upon receiving a disconnect request, SPX/SPXII sets the stream to a T_IDLE state.

Because a transmission error or a disconnect indication can arrive at any moment from the remote transport endpoint, the application needs to be aware of the asynchronicity of the disconnect indication arrival.

Example 1

   /* The following code has two examples. The first example shows 
   ** how to accept a disconnect indication that you know has arrived. 
   ** The second example shows how to loop while you wait for a 
   ** disconnect indication to arrive. 
   */ 
   

{ struct t_discon *discon; ...

if((discon = (struct t_discon *)t_alloc(spxFd, T_DIS, T_ALL))==NULL) { t_error( "t_alloc of T_DIS failed"); exit(-1); discon->udata.len = 0; if(t_rcvdis(spxFd, discon) < 0) { t_free((char *)discon, T_DIS); t_error( "t_rcvdis failed"); exit(-1); }

switch( discon->reason) { case TLI_SPX_CONNECTION_TERMINATED: fprintf(stderr,"Connection terminated by remote endpoint.\n"); ...

break; case TLI_SPX_CONNECTION_FAILED: fprintf(stderr,"Connection failed.\n"); ...

break; } t_free((char *)discon, T_DIS); t_close(spxFd); }

Example 2

   /* 
   ** This example shows how to loop while you wait for a disconnect 
   ** indication to arrive. 
   */ 
   

{ int lookVal; struct t_discon *discon; ...

while(lookVal = t_look(spxFd)) { if (lookVal < 0) { t_error( "t_look failed"); exit(-1); } if (lookVal == 0) { /* Nothing there. Wait */ sleep(1); continue; } if (lookVal == T_DISCONNECT) { if((rcvdis=(struct t_discon *)t_alloc(spxFd,T_DIS,T_ALL)) == 0) { t_error( "t_alloc of T_DIS failed"); exit(-1); } rcvdis->udata.len = 0; if(t_rcvdis(spxFd, rcvdis) < 0) { t_free((char *)rcvdis, T_DIS); t_error( "t_rcvdis failed"); exit(-1); } switch( discon->reason) {

case TLI_SPX_CONNECTION_TERMINATED: fprintf(stderr,"Connection terminated by other endpoint\n"); ... break;

case TLI_SPX_CONNECTION_FAILED: fprintf(stderr,"Connection failed.\n"); ... break; }

t_free((char *)rcvdis, T_DIS); break; } if (lookVal == T_ORDREL) { fprintf(stderr, "got T_ORDREL\n"); if(t_rcvrel(spxFd) < 0) { t_error( "t_rcvrel failed"); exit(-1); } break; } else { fprintf(stderr, "Not T_DISCONNECT or T_ORDREL %d\n",lookVal); ... /* Take care of event */

continue; } } t_close(spxFd); }

State

The state after a t_rcvdis call is T_IDLE.

References

t_connect(3xti_spx), t_listen(3xti_spx), t_rcvdis(3xti), t_snddis(3xti_spx)
30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.