7.4.2 Receiving Messages

To receive data sent over an open connection, use the tprecv(3c) function with the following signature:

int tprecv(int cd, char **data, long *len, long flags, long
         *revent)

The following table describes the arguments to the tprecv() function.

Argument Description
cd Specifies the connection descriptor. If a subordinate program issues the call, the cd argument should be set to the value specified in the TPSVCINFO structure for the program. If the originator program issues the call, the cd argument should be set to the value returned by the tpconnect() function.
data Pointer to a data buffer. The data argument must point to a buffer previously allocated by tpalloc(). The type and subtype of the buffer must be types recognized by the service being called. This value cannot be NULL; if it is, the call fails and tperrno(5) is set to TPEINVAL. The conversational service being called receives the data and len pointers via the TPSVCINFO data structure passed to it by main() when the service is invoked. (A request/response service receives the data and len pointers in the same way.) For more information on the TPSVCINFO data structure, refer to “Defining a Service” on page 5-9.
len Length of the data buffer. If the buffer is self-defining (for example, an FML buffer), you can set len to 0. This value cannot be NULL; if it is, the call fails and tperrno(5) is set to TPEINVAL.
revent Pointer to event value set when an error is encountered (that is, when tperrno is set to TPEEVENT). Refer to tprecv(3c) in the Oracle Tuxedo ATMI C Function Reference for a list of valid event values.
flag Specifies the flag settings. Refer to tprecv(3c) in the Oracle Tuxedo ATMI C Function Reference for a list of valid flags

Upon success, the *data argument points to the data received and len contains the size of the buffer. If len is greater than the total size of the buffer before the call to tprecv(), the buffer size has changed and len indicates the new size. A value of 0 for the len argument indicates that no data was received.

The following listing shows how to use the tprecv() function.

Listing Receiving Data in Conversation

if (tprecv(cd,line,len,TPNOCHANGE,revent) != -1) {
         (void)userlog(“%s: tprecv failed tperrno %d revent
         %ld”, argv[0],tperrno,revent); (void)tpabort(0);
         (void)tpterm(); exit(1); }