Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Housekeeping testing
0003  *
0004  * @file atmiclt35.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 void do_thread_work ( void *ptr )
0056 {
0057 
0058     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0059     long rsplen;
0060     int i;
0061     int ret=EXSUCCEED;
0062     double d;
0063     double dv = 55.66;
0064     int cd;
0065     long revent;
0066     int received = 0;
0067     char tmp[126];
0068 
0069     
0070     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0071     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0072     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0073 
0074 
0075     if (EXFAIL==(cd=tpconnect((char *)ptr, (char *)p_ub, 0L, TPRECVONLY)))
0076     {
0077             NDRX_LOG(log_error, "TESTSV connect failed!: %s",
0078                                     tpstrerror(tperrno));
0079             ret=EXFAIL;
0080             goto out;
0081     }
0082 
0083     /* Recieve the stuff back */
0084     NDRX_LOG(log_debug, "About to tprecv!");
0085 
0086     while (EXSUCCEED==tprecv(cd, (char **)&p_ub, 0L, 0L, &revent))
0087     {
0088         received++;
0089         NDRX_LOG(log_debug, "MSG RECEIVED OK!");
0090     }
0091     
0092 
0093     /* If we have event, we would like to become recievers if so */
0094     if (TPEEVENT==tperrno)
0095     {
0096         received++;
0097         sprintf(tmp, "CLT: %d", received);
0098         
0099         Badd(p_ub, T_STRING_FLD, tmp, 0L);
0100         if (TPEV_SENDONLY==revent)
0101         {
0102             int i=0;
0103             /* Start the sending stuff now! */
0104             for (i=0; i<100 && EXSUCCEED==ret; i++)
0105             {
0106                 ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
0107             }
0108         }
0109     }
0110 
0111     /* Now give the control to the server, so that he could finish up */
0112     if (EXFAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
0113     {
0114         NDRX_LOG(log_debug, "TESTERROR: Failed to give server control!!");
0115         ret=EXFAIL;
0116         goto out;
0117     }
0118 
0119     NDRX_LOG(log_debug, "Get response from tprecv!");
0120     Bfprint(p_ub, stderr);
0121 
0122     /* Wait for return from server */
0123     ret=tprecv(cd, (char **)&p_ub, 0L, 0L, &revent);
0124     NDRX_LOG(log_error, "tprecv failed with revent=%ld", revent);
0125 
0126     if (EXFAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
0127     {
0128         NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
0129         ret=EXSUCCEED;
0130     }
0131     
0132     if (EXSUCCEED!=tpterm())
0133     {
0134         NDRX_LOG(log_error, "TESTERROR: tpterm failed with: %s", tpstrerror(tperrno));
0135         ret=EXFAIL;
0136         goto out;
0137     }
0138     
0139 out:
0140 
0141         NDRX_LOG(log_error, "Thread returns with %d", ret);
0142     
0143 }
0144 
0145 /*
0146  * Do the test call to the server
0147  */
0148 int main(int argc, char** argv) 
0149 {
0150     int j;
0151     pthread_t thread1, thread2, thread3, thread4, thread5;  /* thread variables */
0152     void *arg1 = "CONVSV";
0153     void *arg2 = "CONVSV2";
0154     void *arg3 = "CONVSV";
0155     void *arg4 = "CONVSV2";
0156     void *arg5 = "CONVSV";
0157     
0158     tpinit(NULL); /* pull off init from main thread too... */
0159     
0160     /* create threads 1 and 2 */    
0161     pthread_create (&thread1, NULL, (void *) &do_thread_work, arg1);
0162     pthread_create (&thread2, NULL, (void *) &do_thread_work, arg2);
0163     /*sleep(1);  Have some async works... WHY? */
0164     pthread_create (&thread3, NULL, (void *) &do_thread_work, arg3);
0165     pthread_create (&thread4, NULL, (void *) &do_thread_work, arg4);
0166     pthread_create (&thread5, NULL, (void *) &do_thread_work, arg5);
0167 
0168     /* Main block now waits for both threads to terminate, before it exits
0169        If main block exits, both threads exit, even if the threads have not
0170        finished their work */ 
0171     pthread_join(thread1, NULL);
0172     pthread_join(thread2, NULL);
0173     pthread_join(thread3, NULL);
0174     pthread_join(thread4, NULL);
0175     pthread_join(thread5, NULL);
0176     
0177     
0178 
0179     exit(0);
0180 }
0181 
0182 /* vim: set ts=4 sw=4 et smartindent: */