#include "spx_app.h"int t_rcvdis ( int spxFd, struct t_discon *discon )
spxFd
discon
discon
In the following situations, the reason integer of the t_discon structure is set accordingly:
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.
/* 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); }
/* ** 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); }