Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Basic test client
0003  *
0004  * @file convclt21.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044 /*---------------------------Externs------------------------------------*/
0045 /*---------------------------Macros-------------------------------------*/
0046 /*---------------------------Enums--------------------------------------*/
0047 /*---------------------------Typedefs-----------------------------------*/
0048 /*---------------------------Globals------------------------------------*/
0049 /*---------------------------Statics------------------------------------*/
0050 /*---------------------------Prototypes---------------------------------*/
0051 
0052 /*
0053  * Do the test call to the server
0054  */
0055 int main(int argc, char** argv) {
0056 
0057     UBFH *p_ub = NULL;
0058     int i, j;
0059     int ret=EXSUCCEED;
0060     int cd;
0061     long revent;
0062     char tmp[126];
0063 
0064     if (EXSUCCEED!=tpopen())
0065     {
0066         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0067                                             tperrno, tpstrerror(tperrno));
0068         ret=EXFAIL;
0069         goto out;
0070     }
0071 
0072     for (j=0; j<1000; j++)
0073     {
0074         p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0075         
0076         if (EXSUCCEED!=tpbegin(40, 0))
0077         {
0078             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0079                                                 tperrno, tpstrerror(tperrno));
0080             ret=EXFAIL;
0081             goto out;
0082         }
0083 
0084         if (EXFAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
0085         {
0086             NDRX_LOG(log_error, "TESTSV connect failed!: %s",
0087                                     tpstrerror(tperrno));
0088             ret=EXFAIL;
0089             goto out;
0090         }
0091 
0092         /* Receive the stuff back */
0093         NDRX_LOG(log_debug, "About to tprecv!");
0094 
0095         while (EXSUCCEED==tprecv(cd, (char **)&p_ub, 0L, 0L, &revent))
0096         {
0097             NDRX_LOG(log_info, "MSG RECEIVED OK %ld!", revent);
0098         }
0099 
0100         /* If we have event, we would like to become receivers if so */
0101         if (TPEEVENT==tperrno)
0102         {
0103             if (TPEV_SENDONLY==revent)
0104             {
0105                 int i=0;
0106                 /* Start the sending stuff now! */
0107                 for (i=0; i<10 && EXSUCCEED==ret; i++)
0108                 {
0109                     snprintf(tmp, sizeof(tmp), "CLT: %d\n", i);
0110                     Bchg(p_ub, T_STRING_FLD, 0, tmp, 0L);
0111                     ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
0112                 }
0113             }
0114         }
0115 
0116         /* Now give the control to the server, so that he could finish up */
0117         if (EXFAIL==tpsend(cd, (char *)p_ub, 0L, TPRECVONLY, &revent))
0118         {
0119             NDRX_LOG(log_debug, "Failed to give server control!!");
0120             ret=EXFAIL;
0121             goto out;
0122         }
0123 
0124         NDRX_LOG(log_debug, "Get response from tprecv!");
0125         Bfprint(p_ub, stderr);
0126 
0127         /* Wait for return from server */
0128         ret=tprecv(cd, (char **)&p_ub, 0L, 0L, &revent);
0129         NDRX_LOG(log_error, "tprecv failed with ret=%d errno=%d revent=%ld", 
0130                 ret, tperrno, revent);
0131 
0132         if (EXFAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
0133         {
0134             NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
0135             if (EXSUCCEED!=(ret=tpcommit(0)))
0136             {
0137                 NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]", 
0138                                                     ret, tperrno, tpstrerror(tperrno));
0139                 ret=EXFAIL;
0140                 goto out;
0141             }
0142             ret=EXSUCCEED;
0143         }
0144         else
0145         {
0146             if (EXSUCCEED!=(ret=tpabort(0)))
0147             {
0148                 NDRX_LOG(log_error, "TESTERROR: tpabort()==%d fail: %d:[%s]", 
0149                                                     ret, tperrno, tpstrerror(tperrno));
0150                 ret=EXFAIL;
0151                 goto out;
0152             }
0153         }
0154         /* close conv... */
0155         tpdiscon(cd);
0156         
0157         if (NULL!=p_ub)
0158         {
0159             tpfree((char *)p_ub);
0160             p_ub = NULL;
0161         }
0162     }
0163     
0164 out:
0165 
0166     if (EXSUCCEED!=tpclose())
0167     {
0168         NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]", 
0169                                             tperrno, tpstrerror(tperrno));
0170     }
0171 
0172     if (EXSUCCEED!=tpterm())
0173     {
0174         NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
0175         ret=EXFAIL;
0176     }
0177 
0178     if (NULL!=p_ub)
0179     {
0180         tpfree((char *)p_ub);
0181     }
0182 
0183     return ret;
0184 }
0185 
0186 /* vim: set ts=4 sw=4 et smartindent: */