Пример #1
0
int main(int argc, char *argv[])
{
       char *sendbuf, *rcvbuf;
       long sendlen, rcvlen;
       char svcname[16];
       int ret;

       if(argc != 3) {
              (void) fprintf(stderr, "arg:clientpetri servname sendbuf");
              exit(1);
       }

       /* 作为tuxedo客户端连入tuxedo System */

       if (tpinit((TPINIT *) NULL) == -1) {
              (void) fprintf(stderr, "Tpinit failed ");
              exit(1);
       }

       sendlen = strlen(argv[2]);
       /* 使用tpalloc申请string类型buffer作为请求和应答buffer */
       if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
              (void) fprintf(stderr,"Error allocating send buffer ");
              tpterm();
              exit(1);
       }

       if((rcvbuf = (char *) tpalloc("STRING", NULL, 1024*2)) == NULL) {
              (void) fprintf(stderr,"Error allocating receive buffer ");
              tpfree(sendbuf);
              tpterm();
              exit(1);
       }
       (void) strcpy(svcname, argv[1]);	       
       (void) strcpy(sendbuf, argv[2]);

       /* 同步调用服务 */
       ret = tpcall(svcname, (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
       if(ret == -1) {
              (void) fprintf(stderr, "Can't send request to service ");
              (void) fprintf(stderr, "Tperrno = %d ", tperrno);
              tpfree(sendbuf);
              tpfree(rcvbuf);
              tpterm();
              exit(1);
       }

       (void) fprintf(stdout, "Returned string is: %s ", rcvbuf);
       /* 使用tpfree释放申请的请求和应答buffer空间 */
       tpfree(sendbuf);
       tpfree(rcvbuf);
       /* 使用tpterm离开tuxedo System */
       tpterm();
       return(0);
}
Пример #2
0
/*************************************
 *  功能: 程序注销                   *
 *  参数: 无                         * 
 *  返回值:                         *
 *          =0   成功                *
 *          <0   失败                *       
**************************************/
int csllogout()
{
	if (tpterm()==-1)
		return(0-TuxedoErrNo[tperrno].ierrno);
	else
		return 0;
}
Пример #3
0
int
main(int argc, char* argv[])
{
	DB *dbp3;
	DBT key, data;
	TPINIT *initBuf;
        FBFR *replyBuf;
	long replyLen;
	int ch, ret, i;
	char *target;
	char *home = HOME;
	u_int32_t flags = DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN |
	  DB_INIT_LOCK | DB_CREATE | DB_THREAD | DB_RECOVER | DB_REGISTER;
	u_int32_t dbflags = DB_CREATE | DB_THREAD;

	progname = argv[0];

	initBuf = NULL;
        ret = 0;
        replyBuf = NULL;
        replyLen = 1024;

	while ((ch = getopt(argc, argv, "v")) != EOF)
		switch (ch) {
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (verbose)
		printf("%s: called\n", progname);

	if (tpinit((TPINIT *)NULL) == -1)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpinit() OK\n", progname);

	/* Create the DB environment. */
	if ((ret = db_env_create(&dbenv, 0)) != 0 ||
	    (ret = dbenv->open(dbenv, home, flags, 0)) != 0) {
		fprintf(stderr,
		    "%s: %s: %s\n", progname, home, db_strerror(ret));
		goto err;
	}
	dbenv->set_errfile(dbenv, stderr);
	if (verbose)
		printf("%s: opened %s OK\n", progname, home);

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

        /* Allocate reply buffer. */
	if ((replyBuf = (FBFR*)tpalloc("FML32", NULL, replyLen)) 
	    == NULL) 
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"FML32\"), reply buffer OK\n", 
		    progname);
	for (i = 0; i < 2; i++) {
        	if (tpbegin(10L, 0L) == -1)
			goto tuxedo_err;
		if (verbose)
			printf("%s: tpbegin() OK\n", progname);

		if (tpcall("TestTxn1", NULL, 0L, (char **)&replyBuf, 
		    &replyLen, TPSIGRSTRT) == -1) 
			goto tuxedo_err;

        	/* This call will timeout. */
        	tpcall("TestTxn2", NULL, 0L, (char **)&replyBuf, &replyLen, 
            	    TPSIGRSTRT);
        	if (tperrno != TPETIME)
	        	goto tuxedo_err;

		if (i == 0) {
			if (tpabort(0L) == -1)
				goto tuxedo_err;
			if (verbose)
				printf("%s: tpabort() OK\n", progname);
		} else {
		  	/* Commit will fail due to the time out. */
			tpcommit(0L);
			if (tperrno != TPEABORT)
				goto tuxedo_err;
			if (verbose)
				printf("%s: tpcommit() OK\n", progname);
		}


		ret = check_data(dbenv, TABLE1, dbenv, TABLE2, progname);
	}

	if (0) {
tuxedo_err:	fprintf(stderr, "%s: TUXEDO ERROR: %s (code %d)\n",
		    progname, tpstrerror(tperrno), tperrno);
		goto err;
	}
	if (0) {
err:		ret = EXIT_FAILURE;
	}

	if (replyBuf != NULL)
		tpfree((char *)replyBuf);
	if (dbenv != NULL)
		(void)dbenv->close(dbenv, 0);

	tpterm();
	if (verbose)
		printf("%s: tpterm() OK\n", progname);

 	if (verbose && ret == 0)
		printf("%s: test passed.\n", progname);
	else if (verbose)
 		printf("%s: test failed.\n", progname);
	return (ret);
}
Пример #4
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int i;
    int ret=SUCCEED;
    double d;
    double dv = 55.66;
    int cd;
    long revent;
    int received = 0;
    char tmp[126];

    
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);


    if (FAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
    {
            NDRX_LOG(log_error, "TESTSV connect failed!: %s",
                                    tpstrerror(tperrno));
            ret=FAIL;
            goto out;
    }

    /* Recieve the stuff back */
    NDRX_LOG(log_debug, "About to tprecv!");

    while (SUCCEED==tprecv(cd, (char **)&p_ub, 0L, 0L, &revent))
    {
        received++;
        NDRX_LOG(log_debug, "MSG RECEIVED OK!");
    }
    

    /* If we have event, we would like to become recievers if so */
    if (TPEEVENT==tperrno)
    {
        received++;
        sprintf(tmp, "CLT: %d", received);
        
        Badd(p_ub, T_STRING_FLD, tmp, 0L);
        if (TPEV_SENDONLY==revent)
        {
            int i=0;
            /* Start the sending stuff now! */
            for (i=0; i<100 && SUCCEED==ret; i++)
            {
                ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
            }
        }
    }

    /* Now give the control to the server, so that he could finish up */
    if (FAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
    {
        NDRX_LOG(log_debug, "Failed to give server control!!");
        ret=FAIL;
        goto out;
    }

    NDRX_LOG(log_debug, "Get response from tprecv!");
    Bfprint(p_ub, stderr);

    /* Wait for return from server */
    ret=tprecv(cd, (char **)&p_ub, 0L, 0L, &revent);
    NDRX_LOG(log_error, "tprecv failed with revent=%ld", revent);

    if (FAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
    {
        NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
        ret=SUCCEED;
    }
    
    if (SUCCEED!=tpterm())
    {
        NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
        ret=FAIL;
        goto out;
    }
    
out:
    return ret;
}
  void TLPoroPlasticityResidMass<EvalT, Traits>::
  evaluateFields(typename Traits::EvalData workset)
  {
    bool print = false;
    //if (typeid(ScalarT) == typeid(RealType)) print = true;

    typedef Intrepid::FunctionSpaceTools FST;
    typedef Intrepid::RealSpaceTools<ScalarT> RST;

    // Use previous time step for Backward Euler Integration
    Albany::MDArray porePressureold
      = (*workset.stateArrayPtr)[porePressureName];

    Albany::MDArray Jold;
    if (haveMechanics) {
      Jold = (*workset.stateArrayPtr)[JName];
    } 

    // Pore-fluid diffusion coupling.
    for (std::size_t cell=0; cell < workset.numCells; ++cell) {
      for (std::size_t node=0; node < numNodes; ++node) {
        TResidual(cell,node)=0.0;
        for (std::size_t qp=0; qp < numQPs; ++qp) {

          // Volumetric Constraint Term
          if (haveMechanics)  {
            TResidual(cell,node) -= biotCoefficient(cell, qp)
              * (std::log(J(cell,qp)/Jold(cell,qp)))
              * wBF(cell, node, qp) ;
          }

          // Pore-fluid Resistance Term
          TResidual(cell,node) -=  ( porePressure(cell,qp)-porePressureold(cell, qp) )
            / biotModulus(cell, qp)*wBF(cell, node, qp);

        }
      }
    }
    // Pore-Fluid Diffusion Term

    ScalarT dt = deltaTime(0);

    if (haveMechanics) {
      RST::inverse(F_inv, defgrad);
      RST::transpose(F_invT, F_inv);
      FST::scalarMultiplyDataData<ScalarT>(JF_invT, J, F_invT);
      FST::scalarMultiplyDataData<ScalarT>(KJF_invT, kcPermeability, JF_invT);
      FST::tensorMultiplyDataData<ScalarT>(Kref, F_inv, KJF_invT);
      FST::tensorMultiplyDataData<ScalarT> (flux, Kref, TGrad); // flux_i = k I_ij p_j
    } else {
      FST::scalarMultiplyDataData<ScalarT> (flux, kcPermeability, TGrad); // flux_i = kc p_i
    }

    for (std::size_t cell=0; cell < workset.numCells; ++cell){
      for (std::size_t qp=0; qp < numQPs; ++qp) {
        for (std::size_t dim=0; dim <numDims; ++dim){
          fluxdt(cell, qp, dim) = -flux(cell,qp,dim)*dt;
        }
      }
    }
    FST::integrate<ScalarT>(TResidual, fluxdt,
                            wGradBF, Intrepid::COMP_CPP, true); // "true" sums into

    //---------------------------------------------------------------------------//
    // Stabilization Term

    for (std::size_t cell=0; cell < workset.numCells; ++cell){

      porePbar = 0.0;
      vol = 0.0;
      for (std::size_t qp=0; qp < numQPs; ++qp) {
        porePbar += weights(cell,qp)
          * (porePressure(cell,qp)-porePressureold(cell, qp) );
        vol  += weights(cell,qp);
      }
      porePbar /= vol;
      for (std::size_t qp=0; qp < numQPs; ++qp) {
        pterm(cell,qp) = porePbar;
      }

      for (std::size_t node=0; node < numNodes; ++node) {
        trialPbar = 0.0;
        for (std::size_t qp=0; qp < numQPs; ++qp) {
          trialPbar += wBF(cell,node,qp);
        }
        trialPbar /= vol;
        for (std::size_t qp=0; qp < numQPs; ++qp) {
          tpterm(cell,node,qp) = trialPbar;
        }

      }

    }
    ScalarT temp(0);

    for (std::size_t cell=0; cell < workset.numCells; ++cell) {

      for (std::size_t node=0; node < numNodes; ++node) {
        for (std::size_t qp=0; qp < numQPs; ++qp) {

          temp = 3.0 - 12.0*kcPermeability(cell,qp)*dt
            /(elementLength(cell,qp)*elementLength(cell,qp));

          //if ((temp > 0) & stabParameter(cell,qp) > 0) {
          if ((temp > 0) & stab_param_ > 0) {

            TResidual(cell,node) -= 
              ( porePressure(cell,qp)-porePressureold(cell, qp) )
              //* stabParameter(cell, qp)
              * stab_param_
              * std::abs(temp) // should be 1 but use 0.5 for safety
              * (0.5 + 0.5*std::tanh( (temp-1)/kcPermeability(cell,qp)  ))
              / biotModulus(cell, qp)
              * ( wBF(cell, node, qp)
                // -tpterm(cell,node,qp)
                );
            TResidual(cell,node) += pterm(cell,qp)
              //* stabParameter(cell, qp)
              * stab_param_
              * std::abs(temp) // should be 1 but use 0.5 for safety
              * (0.5 + 0.5*std::tanh( (temp-1)/kcPermeability(cell,qp)  ))
              / biotModulus(cell, qp)
              * ( wBF(cell, node, qp) );
          }
        }
      }
    }
  }
Пример #6
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int ret=SUCCEED;
    char buf[128]={EOS};
    
    if (0==strcmp(argv[1], "DOADV"))
    {
        if (FAIL == tpcall("DOADV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
        {
            NDRX_LOG(log_error, "TESTERROR: DOADV failed: %s", tpstrerror(tperrno));
            ret=FAIL;
            goto out;
        }
    }
    else if (0==strcmp(argv[1], "UNADV"))
    {
        if (FAIL == tpcall("UNADV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
        {
            NDRX_LOG(log_error, "TESTERROR: UNADV failed: %s", tpstrerror(tperrno));
            ret=FAIL;
            goto out;
        }
    }
    else if (0==strcmp(argv[1], "TEST"))
    {
        if (FAIL == tpcall("TESTSVFN", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
        {
            NDRX_LOG(log_error, "TESTSVFN failed: %s", tpstrerror(tperrno));
            ret=FAIL;
            goto out;
        }
        /* Verify the data */
        if (FAIL==Bget(p_ub, T_STRING_FLD, 0, (char *)buf, 0))
        {
            NDRX_LOG(log_debug, "Failed to get T_STRING_FLD[0]");
            ret=FAIL;
            goto out;
        }
        else if (0!=strcmp(buf, "THIS IS TEST - OK!"))
        {
            NDRX_LOG(log_debug, "Call test failed");
            ret=FAIL;
            goto out;
        }
    }
    else
    {
        NDRX_LOG(log_error, "ERROR: Invalid command, valid ones are: DOADV, UNADV, TEST");
                
        ret=FAIL;
        goto out;
    }

out:
    /* Terminate the session */
    tpterm();

    return ret;
}
Пример #7
0
int
main(int argc, char* argv[])
{
	DB *dbp2;
	DBT key, data;
	FBFR *buf, *replyBuf;
	HDbRec rec;
	TPINIT *initBuf;
        DB_ENV *dbenv2, *dbenv1;
	long len, replyLen, seqNo;
	int ch, cnt, cnt_abort, cnt_commit, cnt_server1, i, ret;
	char *target;
	char *home = HOME;
	u_int32_t flags = DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN |
	  DB_INIT_LOCK | DB_CREATE | DB_RECOVER | DB_REGISTER;
	u_int32_t dbflags = DB_CREATE;

	progname = argv[0];

	dbenv2 = dbenv1  = NULL;
	dbp2 = NULL;
	buf = replyBuf = NULL;
	initBuf = NULL;
	cnt = 1000;
	cnt_abort = cnt_commit = cnt_server1 = 0;

	while ((ch = getopt(argc, argv, "n:v")) != EOF)
		switch (ch) {
		case 'n':
			cnt = atoi(optarg);
			break;
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (verbose)
		printf("%s: called\n", progname);

	/* Seed random number generator. */
	srand((u_int)(time(NULL) | getpid()));

	if (tpinit((TPINIT *)NULL) == -1)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpinit() OK\n", progname);

	/* Allocate init buffer */
	if ((initBuf = (TPINIT *)tpalloc("TPINIT", NULL, TPINITNEED(0))) == 0)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"TPINIT\") OK\n", progname);

	/* Create the DB environment. */
	if ((ret = db_env_create(&dbenv2, 0)) != 0 ||
	    (ret = dbenv2->open(dbenv2, home, flags, 0)) != 0) {
		fprintf(stderr,
		    "%s: %s: %s\n", progname, home, db_strerror(ret));
		goto err;
	}
	dbenv2->set_errfile(dbenv2, stderr);
	if (verbose)
		printf("%s: opened %s OK\n", progname, home);

	/* 
	 * Open table #2 -- Data is inserted into table 1 using XA
	 * transactions, and inserted into table 2 using regular transactions.
	 */
	if ((ret = db_create(&dbp2, dbenv2, 0)) != 0 ||
	    (ret = dbp2->open(dbp2,
	    NULL, TABLE2, NULL, DB_BTREE, dbflags, 0660)) != 0) {
		fprintf(stderr,
		    "%s: %s %s\n", progname, TABLE2, db_strerror(ret));
		goto err;
	}
	if (verbose)
		printf("%s: opened %s OK\n", progname, TABLE2);

	/* Allocate send buffer. */
	len = Fneeded(1, 3 * sizeof(long));
	if ((buf = (FBFR*)tpalloc("FML32", NULL, len)) == 0)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"FML32\"), send buffer OK\n", progname);

	/* Allocate reply buffer. */
	replyLen = 1024;
	if ((replyBuf = (FBFR*)tpalloc("FML32", NULL, replyLen)) == NULL)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"FML32\"), reply buffer OK\n", progname);

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));
	for (rec.SeqNo = 1, i = 0; i < cnt; ++i, ++rec.SeqNo) {
		GetTime(&rec.Ts);

		if (Fchg(buf, SEQ_NO, 0, (char *)&rec.SeqNo, 0) == -1)
			goto tuxedo_fml_err;
		if (verbose)
			printf("%s: Fchg(), sequence number OK\n", progname);
		if (Fchg(buf, TS_SEC, 0, (char *)&rec.Ts.Sec, 0) == -1)
			goto tuxedo_fml_err;
		if (verbose)
			printf("%s: Fchg(), seconds OK\n", progname);
		if (Fchg(buf, TS_USEC, 0, (char *)&rec.Ts.Usec, 0) == -1)
			goto tuxedo_fml_err;
		if (verbose)
			printf("%s: Fchg(), microseconds OK\n", progname);

		if (tpbegin(60L, 0L) == -1)
			goto tuxedo_err;
		if (verbose)
			printf("%s: tpbegin() OK\n", progname);

		/* Randomly send half of our requests to each server. */
		if (rand() % 2 > 0) {
			++cnt_server1;
			target = "TestTxn1";
		} else
			target = "TestTxn2";
		if (tpcall(target, (char *)buf,
		    0L, (char **)&replyBuf, &replyLen, TPSIGRSTRT) == -1)
			goto tuxedo_err;
		/* Commit for a return value of 0, otherwise abort. */
		if (tpurcode == 0) {
			++cnt_commit;
			if (verbose)
				printf("%s: txn success\n", progname);

			if (tpcommit(0L) == -1)
				goto abort;
			if (verbose)
				printf("%s: tpcommit() OK\n", progname);

			/*
			 * Store a copy of the key/data pair into table #2
			 * on success, we'll compare table #1 and table #2
			 * after the run finishes.
			 */
			seqNo = rec.SeqNo;
			key.data = &seqNo;
			key.size = sizeof(seqNo);
			data.data = &seqNo;
			data.size = sizeof(seqNo);
			if ((ret =
			    dbp2->put(dbp2, NULL, &key, &data, 0)) != 0) {
				fprintf(stderr, "%s: DB->put: %s %s\n",
				    progname, TABLE2, db_strerror(ret));
				goto err;
			}
		} else {
 abort:			++cnt_abort;
			if (verbose)
				printf("%s: txn failure\n", progname);

			if (tpabort(0L) == -1)
				goto tuxedo_err;
			if (verbose)
				printf("%s: tpabort() OK\n", progname);
		}
	}

	printf("%s: %d requests: %d committed, %d aborted\n",
	    progname, cnt, cnt_commit, cnt_abort);
	printf("%s: %d sent to server #1, %d sent to server #2\n",
	    progname, cnt_server1, cnt - cnt_server1);

	/* Check that database 1 and database 2 are identical. */
	if (dbp2 != NULL)
		(void)dbp2->close(dbp2, 0);
	dbp2 = NULL;
	if ((ret = db_env_create(&dbenv1, 0)) != 0 ||
	    (ret = dbenv1->open(dbenv1, "../data", flags, 0)) != 0) 
		goto err;
	ret = check_data(dbenv1, TABLE1, dbenv2, TABLE2, progname);

	if (0) {
tuxedo_err:	fprintf(stderr, "%s: TUXEDO ERROR: %s (code %d)\n",
		    progname, tpstrerror(tperrno), tperrno);
		goto err;
	}
	if (0) {
tuxedo_fml_err:	fprintf(stderr, "%s: FML ERROR: %s (code %d)\n",
		    progname, Fstrerror(Ferror), Ferror);
	}
	if (0) {
err:		ret = EXIT_FAILURE;
	}

	if (replyBuf != NULL)
		tpfree((char *)replyBuf);
	if (buf != NULL)
		tpfree((char *)buf);
	if (initBuf != NULL)
		tpfree((char *)initBuf);
	if (dbp2 != NULL)
		(void)dbp2->close(dbp2, 0);
	if (dbenv1 != NULL)
		(void)dbenv1->close(dbenv1, 0);
	if (dbenv2 != NULL)
		(void)dbenv2->close(dbenv2, 0);

	tpterm();
	if (verbose)
		printf("%s: tpterm() OK\n", progname);

	return (ret);
}
Пример #8
0
void GenericTuxedoClient::disconnect(void)
{
	if (connected) tpterm();
}