Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Both sites max send, avoid deadlock of full sockets - server
0003  *
0004  * @file atmisv72.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 <stdio.h>
0035 #include <stdlib.h>
0036 #include <ndebug.h>
0037 #include <sys_unix.h>
0038 #include <atmi.h>
0039 #include <ndrstandard.h>
0040 #include <ubf.h>
0041 #include <test.fd.h>
0042 #include <string.h>
0043 #include <unistd.h>
0044 #include "test72.h"
0045 
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048 /*---------------------------Enums--------------------------------------*/
0049 /*---------------------------Typedefs-----------------------------------*/
0050 /*---------------------------Globals------------------------------------*/
0051 /*---------------------------Statics------------------------------------*/
0052 exprivate long M_count = 0; /**< number of calls received, 
0053                              * platform shall ensure the serialization */
0054 
0055 exprivate long M_count2 = 0;
0056 exprivate NDRX_SPIN_LOCKDECL(M_count_lock);
0057 /*---------------------------Prototypes---------------------------------*/
0058 
0059 /**
0060  * Standard service entry
0061  */
0062 void TESTSV (TPSVCINFO *p_svc)
0063 {
0064     int ret=EXSUCCEED;
0065     UBFH *p_ub = (UBFH *)p_svc->data;
0066 
0067     NDRX_LOG(log_debug, "%s got call", __func__);
0068     
0069     p_ub = (UBFH *)tprealloc((char *)p_ub, 1024);
0070 
0071     if (EXFAIL==Bchg(p_ub, T_LONG_FLD, 0, (char *)&M_count, 0))
0072     {
0073         NDRX_LOG(log_error, "TESTERROR: Failed to get T_LONG_FLD: %s", 
0074                  Bstrerror(Berror));
0075         ret=EXFAIL;
0076         goto out;
0077     }
0078     NDRX_SPIN_LOCK_V(M_count_lock);
0079     M_count++;
0080     NDRX_SPIN_UNLOCK_V(M_count_lock);
0081     /* usleep(2000); */
0082     
0083 out:
0084     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0085                 0L,
0086                 (char *)p_ub,
0087                 0L,
0088                 0L);
0089 }
0090 
0091 /**
0092  * Standard service entry
0093  */
0094 void TESTSVB (TPSVCINFO *p_svc)
0095 {
0096     int ret=EXSUCCEED;
0097     UBFH *p_ub = (UBFH *)p_svc->data;
0098 
0099     NDRX_LOG(log_debug, "%s got call", __func__);
0100     
0101     p_ub = (UBFH *)tprealloc((char *)p_ub, 1024);
0102 
0103     if (EXFAIL==Bchg(p_ub, T_LONG_FLD, 0, (char *)&M_count2, 0))
0104     {
0105         NDRX_LOG(log_error, "TESTERROR: Failed to get T_LONG_FLD: %s", 
0106                  Bstrerror(Berror));
0107         ret=EXFAIL;
0108         goto out;
0109     }
0110     NDRX_SPIN_LOCK_V(M_count_lock);
0111     M_count2++;
0112     NDRX_SPIN_UNLOCK_V(M_count_lock);
0113     /* usleep(2000); */
0114     
0115 out:
0116     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0117                 0L,
0118                 (char *)p_ub,
0119                 0L,
0120                 0L);
0121 }
0122 
0123 /**
0124  * Query number message processed...
0125  */
0126 void GETINFOS (TPSVCINFO *p_svc)
0127 {
0128     int ret=EXSUCCEED;
0129     long cnt;
0130     UBFH *p_ub = (UBFH *)p_svc->data;
0131 
0132     NDRX_LOG(log_debug, "%s got call", __func__);
0133     
0134     p_ub = (UBFH *)tprealloc((char *)p_ub, 1024);
0135     
0136     NDRX_SPIN_LOCK_V(M_count_lock);
0137     cnt = M_count;
0138     NDRX_SPIN_UNLOCK_V(M_count_lock);
0139     /* usleep(2000); */
0140 
0141     if (EXFAIL==Bchg(p_ub, T_LONG_FLD, 0, (char *)&cnt, 0))
0142     {
0143         NDRX_LOG(log_error, "TESTERROR: Failed to get T_LONG_FLD: %s", 
0144                  Bstrerror(Berror));
0145         ret=EXFAIL;
0146         goto out;
0147     }
0148     
0149 out:
0150     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0151                 0L,
0152                 (char *)p_ub,
0153                 0L,
0154                 0L);
0155 }
0156 
0157 /**
0158  * Query number message processed...
0159  */
0160 void GETINFOSB (TPSVCINFO *p_svc)
0161 {
0162     int ret=EXSUCCEED;
0163     long cnt;
0164     UBFH *p_ub = (UBFH *)p_svc->data;
0165 
0166     NDRX_LOG(log_debug, "%s got call", __func__);
0167     
0168     p_ub = (UBFH *)tprealloc((char *)p_ub, 1024);
0169     
0170     NDRX_SPIN_LOCK_V(M_count_lock);
0171     cnt = M_count2;
0172     NDRX_SPIN_UNLOCK_V(M_count_lock);
0173     /* usleep(2000); */
0174 
0175     if (EXFAIL==Bchg(p_ub, T_LONG_FLD, 0, (char *)&cnt, 0))
0176     {
0177         NDRX_LOG(log_error, "TESTERROR: Failed to get T_LONG_FLD: %s", 
0178                  Bstrerror(Berror));
0179         ret=EXFAIL;
0180         goto out;
0181     }
0182     
0183 out:
0184     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0185                 0L,
0186                 (char *)p_ub,
0187                 0L,
0188                 0L);
0189 }
0190 
0191 /**
0192  * Do initialisation
0193  */
0194 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0195 {
0196     int ret = EXSUCCEED;
0197     NDRX_LOG(log_debug, "tpsvrinit called");
0198 
0199     NDRX_SPIN_INIT_V(M_count_lock);
0200     
0201     if (EXSUCCEED!=tpadvertise("TESTSV", TESTSV))
0202     {
0203         NDRX_LOG(log_error, "Failed to initialise TESTSV!");
0204         EXFAIL_OUT(ret);
0205     }
0206     
0207     if (EXSUCCEED!=tpadvertise("GETINFOS", GETINFOS))
0208     {
0209         NDRX_LOG(log_error, "Failed to initialise GETINFOS!");
0210         EXFAIL_OUT(ret);
0211     }
0212     
0213     if (EXSUCCEED!=tpadvertise("TESTSVB", TESTSVB))
0214     {
0215         NDRX_LOG(log_error, "Failed to initialise TESTSVB!");
0216         EXFAIL_OUT(ret);
0217     }
0218     
0219     if (EXSUCCEED!=tpadvertise("GETINFOSB", GETINFOSB))
0220     {
0221         NDRX_LOG(log_error, "Failed to initialise GETINFOSB!");
0222         EXFAIL_OUT(ret);
0223     }
0224     
0225 out:
0226     return ret;
0227 }
0228 
0229 /**
0230  * Do de-initialisation
0231  */
0232 void NDRX_INTEGRA(tpsvrdone)(void)
0233 {
0234     NDRX_LOG(log_debug, "tpsvrdone called");
0235 }
0236 
0237 /* vim: set ts=4 sw=4 et smartindent: */