#include
#include "atmi.h" /* TUXEDO 头文件*/
#if defined(__STDC__) || defined(__cplusplus)
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
char *sendbuf, *rcvbuf;
long sendlen, rcvlen;
int ret;
if(argc != 2) {
(void) fprintf(stderr, "Usage: simpcl string ");
exit(1);
}
/* 作为tuxedo客户端连入tuxedo System */
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed ");
exit(1);
}
sendlen = strlen(argv[1]);
/* 使用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, sendlen+1)) == NULL) {
(void) fprintf(stderr,"Error allocating receive buffer ");
tpfree(sendbuf);
tpterm();
exit(1);
}
(void) strcpy(sendbuf, argv[1]);
/* 同步调用TOUPPER服务 */
ret = tpcall("TOUPPER", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
if(ret == -1) {
(void) fprintf(stderr, "Can't send request to service TOUPPER ");
(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);
}
|