Fuxedo logotpterm()

leave an application

Synopsis

#include <atmi.h>

int tpterm(void);

Description

tpterm() detaches the process from the application, releasing the access slot and any outstanding resources. Call it when the process is done with the application; exiting without tpterm() leaves the attachment to be reaped by the bulletin board.

Errors (tperrno)

CodeDescription
TPESYSTEMPlatform failure while detaching.

Example

Full source: docs/api/examples/session.c (build and run with make -C docs/api/examples check TUXDIR=<install>); the lines documenting tpterm() 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: tpinit.

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