7.4.1 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.
Table 7-2 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 Oracle Tuxedo ATMI C Function Reference.
|
flag
|
Specifies the flag settings. For a list of valid flag settings, refer to tpsend(3c) in the Oracle Tuxedo ATMI 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 Oracle Tuxedo ATMI 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 listing shows how to invoke the
tpsend()
function.
Listing 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);
}
Parent topic: Sending and Receiving Messages