9.4.4 例: 参加リソースのエラーの確認

次のリストでは、クライアントはREPORTサービスへの同期呼出し(18行目)を行います。次に、通信呼出しで戻される可能性があるエラーを調べて(19 - 34行目)、参加リソースの失敗を確認します。

参加リソースの成功/失敗の確認のリスト

001   #include <stdio.h>
002   #include "atmi.h"
003
004   main()
005   {
006   char *sbuf, *rbuf;
007   long slen, rlen;
008   if (tpinit((TPINIT *) NULL) == -1)
009       error message, exit program;
010   if (tpbegin(30, 0) == -1)
011      error message, tpterm, exit program;
012   if ((sbuf=tpalloc("STRING", NULL, 100)) == NULL)
013       error message, tpabort, tpterm, exit program;
014   if ((rbuf=tpalloc("STRING", NULL, 2000)) == NULL)
015      error message, tpfree sbuf, tpabort, tpterm, exit program;
016   (void)strcpy(sbuf, "REPORT=accrcv DBNAME=accounts");
017   slen=strlen(sbuf);
018   if (tpcall("REPORT", sbuf, slen, &rbuf, &rlen, 0) == -1) {
019       switch(tperrno) {
020       case TPESVCERR:
021            fprintf(stderr,
022                 "REPORT service's tpreturn encountered problems\n");
023            break;
024       case TPESVCFAIL:
025            fprintf(stderr,
026                  "REPORT service TPFAILED with return code of %d\n", tpurcode);
027            break;
028       case TPEOTYPE:
029            fprintf(stderr,
030                   "REPORT service's reply is not of any known data type\n");
031            break;
032       default:
033         fprintf(stderr,
034                "REPORT service failed with error %d\n", tperrno);
035            break;
036         }
037         if (tpabort(0) == -1){
038             check for errors;
039         }
040   }
041   else
042       if (tpcommit(0) == -1)
043           fprintf(stderr, "Transaction failed at commit time\n");
044   tpfree(rbuf);
045   tpfree(sbuf);
046   tpterm();
047   exit(0);
048   }