BEA Logo BEA Tuxedo Release 7.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   Tuxedo Doc Home   |   Programming   |   Topic List   |   Previous   |   Next   |   Contents

   Programming a BEA Tuxedo Application Using C

Sending and Receiving Messages

Once the BEA Tuxedo system establishes a conversational connection, communication between the initiator and subordinate is accomplished using send and receive calls. The process with control of the connection can send messages using the tpsend(3c) function; the process without control can receive messages using the tprecv(3c) function.

Note: Initially, the originator (that is, the client) decides which process has control using the TPSENDONLY or TPRECVONLY flag value of the tpconnect() call. TPSENDONLY specifies that control is being retained by the originator; TPRECVONLY, that control is being passed to the called service.

Sending Messages

To send a message, use the tpsend(3c) function with the following signature.

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

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

tpsend( ) Function Arguments

Argument

Description

cd

Specifies the connection descriptor returned by the tpconnect() function identifying the connection over which the data is sent.

data

Pointer to a data buffer. When establishing the connection, you can send data simultaneously by setting the data argument to point to a buffer previously allocated by tpalloc(). The type and subtype of the buffer must be types recognized by the service being called. You can set the value of data to NULL to specify that no data is to be sent.

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 server receives the data and len pointers in the same way.) For more information on the TPSVCINFO data structure, refer to Defining a Service.

len

Length of the data buffer. If the buffer is self-defining (for example, an FML buffer), you can set len to 0. If you do not specify a value for data, this argument is ignored.

revent

Pointer to event value set when an error is encountered (that is, when tperrno(5) is set to TPEEVENT). For a list of valid event values, refer to tpsend(3c) in the BEA Tuxedo C Function Reference.

flag

Specifies the flag settings. For a list of valid flag settings, refer to tpsend(3c) in the BEA Tuxedo C Function Reference.

In the event of a failure, the tpsend() function returns a value of -1 and sets tperrno(5) to the appropriate error condition. For a list of possible error codes, refer to tpsend(3c) in the BEA Tuxedo C Function Reference.

You are not required to pass control each time you issue the tpsend() function. In some applications, the process authorized to issue tpsend() calls can execute as many calls as required by the current task before turning over control to the other process. In other applications, however, the logic of the program may require the same process to maintain control of the connection throughout the life of the conversation.

The following example shows how to invoke the tpsend() function.

Sending Data in Conversational Mode


if (tpsend(cd,line,0,TPRECVONLY,revent) == -1) {
(void)userlog("%s: tpsend failed tperrno %d",
argv[0],tperrno);
(void)tpabort(0);
(void)tpterm();
exit(1);
}


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.

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 BEA Tuxedo C Function Reference for a list of valid event values.

flag

Specifies the flag settings. Refer to tprecv(3c) in the BEA Tuxedo 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 example shows how to use the tprecv() function.

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);
}