Fuxedo logotperrno()

the ATMI error indicator

Synopsis

#include <atmi.h>

int tperrno;  // a macro wrapping thread-local storage

Description

Every ATMI call reports failure through tperrno: on a -1 or NULL return it holds one of the TPE* error codes (TPEINVAL, TPENOENT, TPETIME, TPESVCFAIL, ... documented per function). A successful call does not reset it, so the value is meaningful only immediately after a failure; each thread holds its own. Render the code with tpstrerror(). The FML32 calls use their own indicator, Ferror32.

Notes

Code that checks tperrno unconditionally after every call is a bug in the making: on success it reports the outcome of an earlier, unrelated failure. The convention is if (call() == -1) switch (tperrno), nothing more.

Example

Full source: docs/api/examples/session.c (build and run with make -C docs/api/examples check TUXDIR=<install>); the lines documenting tperrno() are highlighted.

// tpinit()/tpterm() example: explicit session control. A regular
// client can skip both; the first ATMI call joins the application with
// defaults and the detach happens at process exit.

#include <stdio.h>
#include <string.h>
#include <atmi.h>

int main(int argc, char **argv) {
  const char *input = argc > 1 ? argv[1] : "hello";

  // NULL joins with defaults; a TPINIT carries usrname, cltname,
  // passwd, grpname, and identification data for apps that require it
  if (tpinit((TPINIT *)NULL) == -1) {
    // tperrno holds the code of the last failed ATMI call; a
    // successful call does not reset it, so read it right after the
    // failure
    int code = tperrno;
    // tpstrerror renders a tperrno code as text
    fprintf(stderr, "tpinit failed: %s (%d)\n", tpstrerror(code), code);
    return 1;
  }

  char *req = tpalloc("STRING", NULL, strlen(input) + 1);
  char *rsp = tpalloc("STRING", NULL, strlen(input) + 1);
  long rlen = 0;
  int rc = 0;
  if (req == NULL || rsp == NULL) {
    fprintf(stderr, "tpalloc failed: tperrno=%d\n", tperrno);
    rc = 1;
  } else {
    strcpy(req, input);
    if (tpcall("TOUPPER", req, 0, &rsp, &rlen, 0) == -1) {
      fprintf(stderr, "tpcall failed: tperrno=%d\n", tperrno);
      rc = 1;
    } else {
      printf("%s -> %s\n", req, rsp);
    }
  }
  tpfree(req);
  tpfree(rsp);

  tpterm();
  return rc;
}

See also: tpstrerror, Ferror32.

fuxedo: supported. Cross-checked against Oracle Tuxedo 12.2.2 and 22.1 with the API hardening suite.