Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Conversational tests
0003  *
0004  * @file atmisv35.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 
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <ndebug.h>
0038 #include <atmi.h>
0039 #include <ndrstandard.h>
0040 #include <ubf.h>
0041 #include <test.fd.h>
0042 #include <string.h>
0043 
0044 void CONVSV (TPSVCINFO *p_svc)
0045 {
0046     int ret=EXSUCCEED;
0047     long revent;
0048     static double d = 55.66;
0049     int i;
0050     int cd;
0051     UBFH *p_ub = (UBFH *)p_svc->data;
0052     char tmp[128];
0053     NDRX_LOG(log_debug, "CONVSV got call");
0054 
0055     /* Just print the buffer */
0056     Bprint(p_ub);
0057 
0058     if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 6000))) /* allocate some stuff for more data to put in  */
0059     {
0060         ret=EXFAIL;
0061         goto out;
0062     }
0063 
0064     d+=1;
0065 
0066     for (i=0; i<100; i++)
0067     {
0068         sprintf(tmp, "SRV SND: %d", i);
0069         if (EXFAIL==Badd(p_ub, T_STRING_FLD, (char *)tmp, 0))
0070         {
0071             ret=EXFAIL;
0072             goto out;
0073         }
0074 
0075         if (p_svc->flags & TPSENDONLY)
0076         {
0077             NDRX_LOG(log_debug, "Doing some send!");
0078             /* Lets send some data back to client */
0079             if (EXFAIL==tpsend(p_svc->cd, (char *)p_ub, 0L, 0L, &revent))
0080             {
0081                 NDRX_LOG(log_error, "Failed to send to client!");
0082             }
0083         }
0084     
0085     /* well we will now try to connect to other server... if we are conv2 */
0086     
0087     if (strcmp(p_svc->name, "CONVSV2"))
0088     {
0089         NDRX_LOG(log_info, "Try to connect to CONVSV!!!");
0090         if (EXFAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
0091         {
0092             NDRX_LOG(log_error, "TESTERROR: connect failed!: %s",
0093                         tpstrerror(tperrno));
0094             ret=EXFAIL;
0095             goto out;
0096         }
0097     }
0098     
0099     sleep(999);
0100     }
0101 
0102     /* Now we will become as listeners, OK? */
0103     if (EXFAIL==tpsend(p_svc->cd, (char *)p_ub, 0L, TPRECVONLY, &revent))
0104     {
0105         NDRX_LOG(log_error, "Failed to send to client!");
0106         goto out;
0107     }
0108 
0109     /* now wait for messages to come in! */
0110     while (EXSUCCEED==tprecv(p_svc->cd, (char **)&p_ub, 0L, 0L, &revent))
0111     {
0112         NDRX_LOG(log_debug, "Sent MSG OK!");
0113     }
0114 
0115     /* Dump the buffer */
0116     Bfprint(p_ub, stderr);
0117 
0118     if (TPEEVENT==tperrno)
0119     {
0120         if (TPEV_SENDONLY==revent)
0121         {
0122             NDRX_LOG(log_debug, "We are senders - FINISH UP!");
0123         }
0124         else
0125         {
0126             NDRX_LOG(log_debug, "Did not get TPEV_SENDONLY!!!");
0127             ret=EXFAIL;
0128         }
0129     }
0130 
0131 out:
0132     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0133                 0L,
0134                 (char *)p_ub,
0135                 0L,
0136                 0L);
0137 }
0138 
0139 /*
0140  * Do initialization
0141  */
0142 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0143 {
0144     int ret = EXSUCCEED;
0145     NDRX_LOG(log_debug, "tpsvrinit called");
0146 
0147     if (EXSUCCEED!=tpadvertise("CONVSV", CONVSV))
0148     {
0149         NDRX_LOG(log_error, "Failed to initialize CONVSV!");
0150         ret=EXFAIL;
0151     }
0152     
0153     
0154     return ret;
0155 }
0156 
0157 /**
0158  * Do de-initialization
0159  */
0160 void NDRX_INTEGRA(tpsvrdone)(void)
0161 {
0162     NDRX_LOG(log_debug, "tpsvrdone called");
0163 }
0164 /* vim: set ts=4 sw=4 et smartindent: */