#include "spx_app.h"int t_rcvrel ( int spxFd )
spxFd
This call works as specified in ``Programming with the X/Open Transport Interface (XTI)''.
Because the other endpoint might send a T_DISCONNECT, a user should not loop waiting only for an orderly release indication.
If a loop is desirable, t_look should be used to detect T_INREL or T_DISCONNECT.
If a t_sndrel call has not been issued by the user, the user can continue to send data over the connection.
If the connection is not an SPXII connection, TNOREL is returned.
The correct procedure to orderly terminate an SPXII connection is for both endpoints to send an orderly release request when there is no more data to send. Then both continue to read data until an orderly release indication is received. At this point both endpoints are finished sending and receiving data, and the connection state is set to T_IDLE.
{ int spxFd; .../* ** Receive data loop */ while ((rcvbytes = t_rcv(spxFd,dataBuf,sizeof(dataBuf),&flags))!= -1 ) { fprintf(stderr,"received %d bytes Do something with them\n",rcvbytes); }
/* t_rcv failed. Find out why */ if (t_errno == T_LOOK) { lookVal = t_look(spxFd); switch (lookVal) { case T_ORDREL: /* ** If Orderly Release, receive it and continue */ if(t_rcvrel(spxFd) < 0) { t_error( "t_rcvrel failed"); exit(-1); } break; case T_DISCONNECT: /* ** If disconnect, exit now */ if(t_rcvdis(spxFd) < 0) { t_error( "t_rcvrel failed"); exit(-1); } exit(); default: fprintf(stderr,"t_look return %d in receive loop\n",lookVal); exit(); } } else { t_error("t_rcv failed "); exit(-1); } /* ** Send more data; then send Orderly Release request */ ...
t_close(spxFd); }
If an orderly release request has not been sent, the state will change from T_DATAXFER to T_INREL.