t_snd(3xti_spx)


t_snd -- send data over a transport connection

Synopsis

#include "spx_app.h" 

int t_snd ( int spxFd, char *buf, unsigned int nbytes, int flags )

Parameters

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

(IN) buf
Passes the address of the buffer that contains the data to be sent.

(IN) nbytes
Passes the actual number of bytes to be sent.

(IN) flags
Passes a flag (T_MORE) that indicates whether there is more data to send. (SPX/SPXII does not support the T_EXPEDITED flag.)

Return values

>= 0
Successful. Returns the number of bytes accepted by SPX/SPXII

-1
Unsuccessful
If the remote transport endpoint has gone away or fails to acknowledge the transmitted data, the SPXII driver generates a disconnect indication and changes the state of the local transport endpoint to T_IDLE.

Following the TLI specification, any t_snd issued in the T_IDLE state is dropped by the SPXII driver. From the SPX/SPXII user's point of view, this indication is noticed only if that user issues some call other than t_snd.

The SPX/SPXII user should check the return code in the disconnect indication to make sure it is TLI_SPX_CONNECTION_TERMINATED.

The following errors can occur during the send request. These errors lock the stream and disable the local transport endpoint. Only errno is set to the following value (t_errno is not affected):

EPROTO
The data request was issued from a state other than T_DATAXFER. This transport endpoint is no longer valid and must be closed.

or
The size of the data request header or data portion of the message received by SPXII was invalid (too small or too large). This transport endpoint is no longer valid and must be closed.

Remarks

The t_snd function works as specified in ``Programming with the X/Open Transport Interface (XTI)''. All data is sent on a first-come, first-served basis.

During the period of the connection, SPX/SPXII uses the most recent round-trip delay multiplied by 1.5 as the timeout for the next retransmission.

The T_MORE flag is supported by SPX/SPXII.

SPXII breaks any large send requests into a series of maximum packets for the given connection.

Example

   /* 
   ** SpxII will partition large messages into appropriately 
   ** sized packets. 
   */ 
   

#define TRANS_BUFFER_SIZE 4096 int flags; int bytesRead; unsigned char readBuffer[TRANS_BUFFER_SIZE]; char *someFileString = "someFileName"; FILE *fp;

/* Open the file to send */ if ((fp=fopen(someFileString, "r+b")) == NULL) { perror("open failed "); ... }

/* While there is data in the file, tell the remote endpoint that ** there is still data for this transmission */ flags = T_MORE; while (!feof(fp)) { bytesRead=fread(readBuffer, 1, TRANS_BUFFER_SIZE, fp); /* ** spxFd2 is the local endpoint that has been bound and ** connected to a server */ if (t_snd(spxFd2, readBuffer, bytesRead, flags)<0) { t_error( "t_snd failed "); ... } ... }

/* Check that we haven't been cut off by remote end. NOTICE that the ** return code is greater than zero if we received a disconnect ** indication. */

if (t_rcvdis(spxFd2, &disconnectInfo)>=0) { printf( "remote endpoint aborted connection \n"); ... } /* Send one byte with the T_MORE flag turned off to indicate EOF */ flags = 0; if (t_snd(spxFd2, readBuffer, 1, flags)<0) { t_error( "t_snd failed "); ... }

State

The t_snd call is allowed only in the T_DATAXFER state. If any errors occur, the state moves to T_IDLE.

References

t_open(3xti_spx), t_rcv(3xti_spx), t_snd(3xti)
30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.