/************************************************************************************** * Copyright 1998 Compaq Computer Corporation. * Restricted Rights: Use, duplication, or disclosure by the U.S. Government * is subject to restrictions as set forth in subparagraph (c) (1) (ii) of * DFARS 252.227-7013, or in FAR 52.227-19, or in FAR 52.227-14 Alt. III, as * applicable. * This software is proprietary to and embodies the confidential technology of * Compaq Computer Corporation. Possession, use, of copying of this software * and media is authorized only pursuant to a valid written license from Compaq, * Digital or an authorized sublicensor. ***************************************************************************************/ /************************************************************************************** * APPLICATION: RTR Sample Client Application * MODULE NAME: adg_client.c * AUTHOR: Compaq Computer Corporation * DESCRIPTION: This client application initiates transactions and requests * transaction status asynchronously. It is to be used with adg_server.c, * adg_header.h, and adg_shared.c. * DATE : Oct 22, 1998 * * Modification History * 02Feb2009 Deepak/Chinmay QXCR1000780812 [] RTR 64 bit library Support on OpenVMS ***************************************************************************************/ /* adg_client.c Goes with adg_server.c To build on Unix: cc -o adg_client adg_client.c adg_shared.c -lrtr */ #include "adg_header.h" #ifdef VMS typedef __int64 rtr_sgn_64_t; #include /* QXCR1000780812 */ #endif void declare_client ( rtr_channel_t *pchannel ); FILE *fpLog; int main ( int argc, char *argv[] ) { /* * This program expects 3 parameters : * 1: client number (1 or 2) * 2: partition range * 3: messages to send */ rtr_status_t status; rtr_channel_t channel ; time_t time_val = { 0 }; message_data_t send_msg = {0}; receive_msg_t receive_msg = {0}; int txn_cnt; rtr_timout_t receive_time_out = RTR_NO_TIMOUTMS; rtr_msgsb_t msgsb; char CliLog[80]; send_msg.sequence_number = 1 ; strcpy( send_msg.text , "from Client"); /* QXCR1000780812 : The argument passed to main routine is 32 bit pointers on OpenVMS. Copying into 64 bit pointers */ #ifdef VMS rtr_sgn_64_t *tmp_argv; tmp_argv = (rtr_sgn_64_t *) _malloc32(sizeof(rtr_sgn_64_t)*argc); if(!tmp_argv) { printf("out of memory _malloc32 (%lld)", (sizeof(rtr_sgn_64_t)*argc)); exit(-1); } for (int i =0; i 0; txn_cnt--, send_msg.sequence_number++ ) { status = rtr_send_to_server( channel, RTR_NO_FLAGS , &send_msg, sizeof(send_msg), MESSAGE_DATA_MSGFMT ); check_status( "rtr_send_to_server", status ); fprintf(fpLog, "\n ************* sequence %10u *************\n", send_msg.sequence_number); time(&time_val); fprintf(fpLog, " send_to_server at: %s", ctime( &time_val)); fflush(fpLog); /* * Get the server's reply OR * an rtr_mt_rejected */ status = rtr_receive_message( &channel, RTR_NO_FLAGS, RTR_ANYCHAN, &receive_msg, sizeof(receive_msg), receive_time_out, &msgsb); check_status( "rtr_receive_message", status ); time(&time_val); switch (msgsb.msgtype) { case rtr_mt_reply: fprintf(fpLog, " reply from server at: %s", ctime( &time_val)); fprintf(fpLog, " sequence %10u from server %u\n", receive_msg.receive_data_msg.sequence_number, receive_msg.receive_data_msg.server_number); fflush(fpLog); break; case rtr_mt_rejected: fprintf(fpLog, " txn rejected at: %s", ctime( &time_val)); fprint_tid(fpLog, &msgsb.tid ); fprintf(fpLog, " status is : %d\n", status); fprintf(fpLog, " %s\n", rtr_error_text(status)); fflush(fpLog); /* Resend same sequence_number after reject */ send_msg.sequence_number--; txn_cnt++; break; default: fprintf(fpLog, " unexpected msg at: %s", ctime( &time_val)); fprint_tid(fpLog, &msgsb.tid ); fflush(fpLog); exit(EXIT_FAILURE); } if (msgsb.msgtype == rtr_mt_reply) { status = rtr_accept_tx( channel, RTR_NO_FLAGS, RTR_NO_REASON ); check_status( "rtr_accept_tx", status ); status = rtr_receive_message( &channel, RTR_NO_FLAGS, RTR_ANYCHAN, &receive_msg, sizeof(receive_msg), receive_time_out, &msgsb); check_status( "rtr_receive_message", status ); time(&time_val); switch ( msgsb.msgtype ) { case rtr_mt_accepted: fprintf(fpLog, " txn accepted at : %s", ctime( &time_val)); fprint_tid(fpLog, &msgsb.tid ); fflush(fpLog); break; case rtr_mt_rejected: fprintf(fpLog, " txn rejected at : %s", ctime( &time_val)); fprint_tid(fpLog, &msgsb.tid ); fprintf(fpLog, " status is : %d\n", receive_msg.receive_status_msg.status); fprintf(fpLog, " %s\n", rtr_error_text(receive_msg.receive_status_msg.status)); fflush(fpLog); /* Resend same sequence_number after reject */ send_msg.sequence_number--; txn_cnt++; break; default: fprintf(fpLog, " unexpected status on rtr_mt_accepted message\n"); fprint_tid(fpLog, &msgsb.tid ); fprintf(fpLog, " status is : %d\n", receive_msg.receive_status_msg.status); fprintf(fpLog, " %s\n", rtr_error_text(receive_msg.receive_status_msg.status)); fflush(fpLog); break; } } } close_channel ( channel ); return 0; } void declare_client ( rtr_channel_t *pchannel ) { rtr_status_t status; receive_msg_t receive_msg; rtr_timout_t receive_time_out = RTR_NO_TIMOUTMS; /* forever */ rtr_msgsb_t msgsb; /* Structure into which receive puts msgtype */ status = rtr_open_channel( pchannel, RTR_F_OPE_CLIENT , FACILITY_NAME, NULL, /* rpcnam */ RTR_NO_PEVTNUM, NULL, /* access */ RTR_NO_NUMSEG , RTR_NO_PKEYSEG ); check_status( "rtr_open_channel", status); status = rtr_receive_message( pchannel, RTR_NO_FLAGS, RTR_ANYCHAN, &receive_msg, sizeof(receive_msg), receive_time_out, &msgsb); check_status( "rtr_receive_message", status ); if ( msgsb.msgtype != rtr_mt_opened ) { fprintf(fpLog, " Error opening rtr channel %s : \n", FACILITY_NAME); fprintf(fpLog, "%s\n", rtr_error_text(receive_msg.receive_status_msg.status)); exit(EXIT_FAILURE); } fprintf(fpLog, " Client channel successfully opened\n"); return; }