RSC/MP 7.2 Programming Manual
Application Development
HP NonStop Remote Server Call (RSC/MP) Programming Manual—522360-004
6-14
TMF Code Example
/****************************************************************************
Automatic TMF transaction control with a single-request transaction
****************************************************************************/
/* Create options structure, set for automatic transaction BEGIN and END */
RscCreateOptions ( &ulOptions );
RscSetOption ( ulOptions, "TMF_OPTION", NULL, RSC_BEGIN_END_TRANS );
RscSetOption ( ulOptions, "SUCCESS_LO", NULL, 0 );
RscSetOption ( ulOptions, "SUCCESS_HI", NULL, 100 );
/* Send the request to the server */
uReplySize = sizeof ( sReply );
rc = RscWriteRead ( ulOptions, ulConnect, ulSession, "$XYZ", RSC_IO_WAITED,
&sRequest, sizeof ( sRequest ), &sReply, &uReplySize );
/* If the transaction was not automatically ended, end it explicitly now */
if ( rc == RSC_TRANSACTION_NOT_ENDED )
{
nServerCode = RscSwapShort ( sReply.nRetcode );
if ( nServerCode == 999 )
RscEndTransaction ( ulConnect, ulSession );
else
RscAbortTransaction ( ulConnect, ulSession );
}
RscDestroyOptions ( ulOptions );
/****************************************************************************
Automatic TMF transaction control with a multiple-request transaction
****************************************************************************/
/* Create options structure, set up for automatic transaction BEGIN */
RscCreateOptions ( &ulOptions );
RscSetOption ( ulOptions, "TMF_OPTION", NULL, RSC_BEGIN_TRANS );
/* Send first request to a server */
uReplySize = sizeof ( sReply );
rc = RscWriteRead ( ulOptions, ulConnect, ulSession, "$ABC", RSC_IO_WAITED,
&sRequest, sizeof ( sRequest ), &sReply, &uReplySize );
/* For this server request we will consider any non-zero return as a failure
and abort the transaction without issuing the second request. */
nServerCode = RscSwapShort ( sReply.nRetcode );
if ( nServerCode != 0 )
RscAbortTransaction ( ulConnect, ulSession );
else
{
/* Set up to continue the transaction in progress; send second request */
RscSetOption ( ulOptions, "TMF_OPTION", NULL, 0 );
uReplySize = sizeof ( sReply );
rc = RscWriteRead ( ulOptions, ulConnect, ulSession, "$ABC", RSC_IO_WAITED,
&sRequest, sizeof ( sRequest ), &sReply, &uReplySize );
/* Set up to end the transaction with the next request */
RscSetOption ( ulOptions, "TMF_OPTION", NULL, RSC_END_TRANS );
RscSetOption ( ulOptions, "SUCCESS_LO", NULL, 0 );
RscSetOption ( ulOptions, "SUCCESS_HI", NULL, 100 );