Table of Contents
This chapter describes the functions available in Tmax. For more information about error codes, refer to "Tmax Application Development Guide".
The gettperrno function returns an errno, which is an error code set in the client and server, when calling the Tmax System.
Prototype
#include <atmi.h> int gettperrno(void)
Return Value
Returns an errno. For more information about errno, refer to "Appendix A. Error Codes and Actions to Be Taken" or "Tmax Application Development Guide".
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char* argv[]) { int ret, usrerrno=0; char *sndbuf, *rcvbuf; ret=tpstart((TPSTART_T*)NULL); if (ret==-1){ usrerrno=gettperrno(); printf(“error no : %d\n”, usrerrno); } data process… tpend(); }
Related Function
gettpurcode()
The tmax_chk_conn function checks the connection status of a client by checking the execution status of a tpstart() function, socket status, and message transmission.
Prototype
#include <usrinc/tmaxapi.h> int tmax_chk_conn (int sec)
Parameter
Parameter | Description |
---|---|
sec | Input options:
|
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_chk_conn() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | tpstart() did not execute. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include <usrinc/tmaxapi.h> #include “../fdl/demo_fdl.h” main(int argc, char *argv[]) { FBUF *sndbuf, *rcvbuf; int fc, fg, ret, i, chkno; char sndata[30], rcvdata[30]; char input[10], outdata[10]; long sndlen, rcvlen; int Count = 1; if (argc != 2) error processing… if ( (ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ) error processing… /* tpstart check */ /*** chkno = tmax_chk_conn(-1); printf(“chkno = %d\n”, chkno); if(chkno < 0) { printf(“tpstart is not started\n”); printf(“errno = %d\tstrerror=%s\n”, tperrno, tpstrerror(tperrno) ); } else if(chkno == 0) { printf(“tpstart is started\n”); } ***/ if (tpstart((TPSTART_T *)NULL) == -1) error processing… if ((sndbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)) == NULL) error processing… if ((rcvbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)) == NULL) error processing… /* socket status check */ /*********** chkno = tmax_chk_conn(0); printf(“chkno = %d\n”, chkno); if(chkno < 0) { printf(“The situation of socket is bad\n”); printf(“errno = %d\tstrerror=%s\n”, tperrno, tpstrerror(tperrno) ); } else if(chkno == 0) { printf(“The situation of socket is good\n”); } **********/ printf(“My Count = %d\n”, Count++); strcpy(input, “INPUT”); strcpy(sndata, argv[1]); fc = fbput(sndbuf, fbget_fldkey(input), sndata, 0); if (tpcall(“FDLTOUPPER”, (char *)sndbuf, 0, (char **)&rcvbuf, (long *)&rcvlen, TPNOFLAGS) == -1) error processing… /* Check for the connection status by transmitting message */ chkno = tmax_chk_conn(1); printf(“chkno = %d\n”, chkno); if(chkno < 0) { printf(“The situation of connection(Message Transfer) is bad\n”); printf(“errno = %d\tstrerror=%s\n”, tperrno, tpstrerror(tperrno) ); } else if(chkno == 0) { printf(“The situation of connection(Message Transfer) is good\n”); } strcpy(outdata, “OUTPUT”); fg = fbget(rcvbuf, fbget_fldkey(outdata), rcvdata, 0); fbprint(rcvbuf); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Function
tpalivechk()
The tmax_gq_count function returns the amount of data stored in a GQ.
Prototype
#include <tmaxapi.h> int tmax_gq_count (void)
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_gq_count() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPENOENT] | A GQ does not exist for a current session. |
The tmax_gq_get function uses a key to retrieve data from a GQ. By default, tmax_gq_get() deletes data retrieved in a queue. To preserve this data, a TPSQ_PEEK flag must be enabled.
Prototype
#include <tmaxapi.h> int tmax_gq_get(char *key, long keylenl, char **data, long *lenl, long flagsl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores data from a GQ. |
keylenl | A key buffer size. (Unit: byte) |
data | A pointer to a data buffer on a GQ. The buffer must be allocated by a tpalloc(). |
lenl | The size of a data buffer on a GQ. (Unit: byte) |
flagsl | Only TPSQ_PEEK is available. This flag prevents data from being deleted from a queue. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_gq_get() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEMATCH] | No data can be found for a given key. |
The tmax_gq_getkeylist function retrieves a GQ key list. The key list is a SQ_KEYLIST_T type, and detailed key data can be obtained using tmax_keylist_count(), tmax_keylist_count(), and tmax_keylist_free(). The key list is sorted according to the ASCII value of each byte, from lowest to highest.
When specifying a key value, a key list with greater or equal value is queried and sorted. If a key value is set to NULL, the entire key list will be queried.
Prototype
#include <tmaxapi.h> SQ_KEYLIST_T tmax_gq_getkeylist(char *key, long keylenl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores keys. |
keylenl | A key buffer size. (Unit: byte) |
Return Value
Value | Description |
---|---|
SQ_KEYLIST_T | A function call was successful. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When tmax_gq_getkeylist() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEMATCH] | A key value is too big or no data can be found for the given key. |
The tmax_gq_keygen function generates a system key and stores it in a buffer. The buffer size must be greater than or equal to SQ_SYSKEY_SIZE (16 bytes), the system key size.
Prototype
#include <tmaxapi.h> int tmax_gq_keygen(char *key, long keylenl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores a generated system key. |
keylenl | A key buffer size. It must be greater than or equal to SQ_SYSKEY_SIZE(16 bytes). |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_gq_keygen() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid key. |
The tmax_gq_purge function deletes GQ data that is specified by a key. If a key is not specified, all data in the GQ is deleted.
Prototype
#include <tmaxapi.h> int tmax_gq_purge(char *key, long keylenl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores the key of data being deleted from a GQ. If NULL, all data in a current session’s GQ is deleted. |
keylenl | A key buffer size. (Unit: byte) |
Return Value
Value | Description |
---|---|
The number of the deleted data | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_gq_purge() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid key. |
[TPENOENT] | A GQ does not exist for a current session. |
The tmax_gq_put function enters data into a GQ. Both a key value and a data value must be passed. When using a system key generated by a tmax_gq_keygen(), a TPSQ_SYSKEY flag must be set. To generate and store a system key, a TPSQ_KEYGEN flag must be set.
Prototype
#include <tmaxapi.h> int tmax_gq_put(char *key, long keylenl, char *data, long lenl, long flagsl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores the key of data being retrieved from a GQ. |
keylenl | A key buffer size. (Unit: byte) |
data | A pointer to a data buffer to be retrieved from a GQ. The buffer must be allocated by a tpalloc(). |
lenl | The size of a data buffer retrieved from a GQ (Unit: byte). |
flagsl | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPSQ_UPDATE | Updates data if a data's key already exists in a GQ to which the data will be saved. If this flag is not specified, a TPEMATCH error will be returned. |
TPSQ_SYSKEY | Uses a system key. |
TPSQ_KEYGEN | Generates and stores a system key. When TPSQ_KEYGEN is set, a key must be assigned based on SQ_SYSKEY_SIZE. When keylenl = SQ_SYSKEY_SIZE is set, the value created in the key is stored. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_gq_put() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEMATCH] | A key value is already being used. |
[DELIMIT] | A maximum GQ count or GQ key count has been exceeded. |
The tmax_get_sessionid function returns a current session ID.
Prototype
#include <tmaxapi.h> int tmax_get_sessionid(void)
Return Value
Value | Description |
---|---|
A value other than -1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_get_sessionid() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEPROTO] | A session already closed. |
The tmax_keylist_count function retrieves the key count from the keylist handle.
Prototype
#include <tmaxapi.h> int tmax_keylist_count(SQ_KEYLIST_T keylist)
Parameter
Parameter | Description |
---|---|
keylist | A keylist is a handle obtained from a tmax_sq_getkeylist() or a tmax_gq_getkeylist(). |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_keylist_count() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid keylist handle. |
The tmax_keylist_free function releases memory and other resources of the keylist handle.
Prototype
#include <tmaxapi.h> int tmax_keylist_free(SQ_KEYLIST_T keylist)
Parameter
Parameter | Description |
---|---|
keylist | A keylist is a handle obtained from a tmax_sq_getkeylist() or a tmax_gq_getkeylist(). |
Return Value
Value | Description |
---|---|
A value other than -1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_keylist_free() fails to execute, a tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid keylist handle. |
The tmax_keylist_getakey function retrieves information from a key located at the nth index in a keylist.
Prototype
#include <tmaxapi.h> int tmax_keylist_getakey(SQ_KEYLIST_T keylist, int nth, SQ_KEYINFO_T *keyinfo)
Parameter
Parameter | Description |
---|---|
keylist | A keylist is a handle obtained from a tmax_sq_getkeylist() or a tmax_gq_getkeylist(). |
nth | An index key in a keylist handle. The range of 'n' is between 0 and tmax_keylist_count() -1. |
keyinfo | An object that stores a nth key information. For more information about keyinfo, refer to the table below. |
The following is an example of keyinfo:
Structure keyinfo { long keylen long datalen time_t starttime char *key };
Member | Description |
---|---|
long keylen | A key size. (Unit: byte) |
long datalen | Data size. (Unit: byte) |
time_t starttime | Date when data is saved or updated. |
char *key | A buffer that contains key values. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_keylist_getakey() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid keylist handle. |
[DELIMIT] | An index n is out of range. |
The tmax_sq_count function returns the amount of data stored in a SQ of a current session.
Prototype
#include <tmaxapi.h> int tmax_sq_count(void)
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_sq_count() fails to execute, a tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPENOENT] | A SQ does not exist for a current session. |
The tmax_sq_get function retrieves data from a SQ. Data is retrieved by providing an associated key. By default, a tmax_sq_get() deletes data in a queue. To preserve this data, a TPSQ_PEEK must be set.
Prototype
#include <tmaxapi.h> int tmax_sq_get(char *key, long keylenl, char **data, long *lenl, long flagsl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores data from a SQ. |
keylenl | A key buffer size. (Unit: byte) |
data | A pointer to a data buffer on a SQ. The buffer must be allocated by a tpalloc(). |
lenl | The size of a data buffer on a SQ in bytes. |
flagsl | Only a TPSQ_PEEK is available. This flag prevents data from being deleted from a queue. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_sq_get() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A SQ does not exist for a current session. |
[TPEMATCH] | Data with a specified key does not exist. |
The tmax_sq_getkeylist function retrieves the key list of the current SQ. A key list is a SQ_KEYLIST_T type, and detailed key data can be obtained using tmax_keylist_count(), tmax_keylist_count(), and tmax_keylist_free(). A key list is sorted according to ASCII values of each byte from lowest to highest.
When specifying a key value, a key list with greater or equal value is queried and sorted. If a key value is set to NULL, an entire key list is queried.
Prototype
#include <tmaxapi.h> SQ_KEYLIST_T tmax_sq_getkeylist(char *key, long keylenl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores keys. |
keylenl | A key buffer size. (Unit: byte) |
Return Value
Value | Description |
---|---|
SQ_KEYLIST_T | A function call was successful. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_sq_getkeylist() fails to execute, a tperrno is set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A SQ does not exist for a current session. |
[TPEMATCH] | A key value is too big or a specified key cannot be found. |
The tmax_sq_keygen function generates a system key and stores it in a user-specified buffer. The buffer size must be greater than or equal to a system key size, SQ_SYSKEY_SIZE (16 bytes).
Prototype
#include <tmaxapi.h> int tmax_sq_keygen(char *key, long keylenl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores a generated system key. |
keylenl | A key buffer size. It must be larger than a SQ_SYSKEY_SIZE(16 bytes). |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_sq_keygen() fails to execute, a tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPENOENT] | A SQ does not exist for a current session. |
The tmax_sq_purge function deletes SQ data specified by a key. If a key is not specified, all data in a SQ is deleted.
Prototype
#include <tmaxapi.h> int tmax_sq_purge(char *key, long keylenl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores the key of data being deleted from a SQ. If NULL, all data in a SQ of a current session will be deleted. |
keylenl | A key buffer size. (Unit: byte) |
Return Value
Value | Description |
---|---|
Amount of deleted data | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_sq_purge() fails to execute, a tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPENOENT] | A GQ does not exist for a current session. |
The tmax_sq_put function enters data into the SQ. Both the key value and the data value must be passed.
Prototype
#include <tmaxapi.h> int tmax_sq_put(char *key, long keylenl, char *data, long lenl, long flagsl)
Parameter
Parameter | Description |
---|---|
key | A buffer that stores the key of data being retrieved from a SQ. |
keylenl | A key buffer size (Unit: byte). |
data | A pointer to a data buffer to be retrieved from a SQ. The buffer must be allocated by a tpalloc(). |
lenl | The size of a data buffer retrieved from a SQ in bytes. |
flagsl | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPSQ_UPDATE | Updates data if a data's key already exists in a SQ to which the data will be saved. If this flag is not specified, a TPEMATCH error will be returned. |
TPSQ_SYSKEY | Uses a system key created by a tmax_sq_keygen(). |
TPSQ_KEYGEN | To generate and store a system key, a TPSQ_KEYGEN must be set. When TPSQ_KEYGEN is set, a key must be assigned based on a SQ_SYSKEY_SIZE. When keylenl = SQ_SYSKEY_SIZE is set, the value created in the key is stored. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_sq_put() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A SQ does not exist for a current session. |
[TPEMATCH] | A specified key value is already in use. |
[DELIMIT] | A maximum SQ count or a SQ key count has been exceeded. |
The tmaxlastsvc function returns a service name before returning results. This information allows a user to find the name of a service in which an error occurred or the name of a server that executed a last routine.
When using tpforward() or tprely(), other service routines are executed in addition to the services called by a user. In this case, when an error occurs during the execution of multiple server routines, a user cannot find the server in which an error occurred.
Prototype
#include <tmaxapi.h> char *tmaxlastsvc(char *idata, char *odata, long flags)
Parameter
Parameter | Description |
---|---|
idata, odata | Uses a send/rcv buffer used in a tpcall. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
Internal buffer pointer | A function call was successful. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tmaxlastsvc() fails to execute, a tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
Example
#include <usrinc/atmi.h> main(int argc, char *argv[]) { ... if(tpcall(“TOUPPER”, sndbuf, 0, &rcvbuf, &rcvlen, TPNOFLAGS)==-1){ memset(svc, NULL, 16); strcpy((char *)svc, tmaxlastsvc(sndbuf, rcvbuf, TPNOFLAGS)); printf(“servicename = %s\n”, svc); error processing } ... }
The tmaxreadenv function reads information about a system to be accessed from a file and sets an environment variable value.
To access a Tmax system, several environment parameters must be first registered. By referring to registered environment parameters and using a tpstart() function, a client can access a Tmax system. Generally, UNIX defines csh in <.cshrc> and ksh in <.profile>, while DOS defines environment variables in a <autoexec.bat> file.
To access multiple systems, a client can change the system to be accessed depending on the situation. This function must be executed before accessing a Tmax system because the information required for access must be set in the environment variable.
For more information about registering environment variables in the configuration file, refer to "Tmax Administrator's Guide".
Prototype
#include <tmaxapi.h> int tmaxreadenv (char *file, char *label)
Parameter
Parameter | Description |
---|---|
file | A file that stores configuration information of a system to be accessed. This file must be registered according to a prescribed text format. |
label | Descriptor of the configuration information registered in a file. I.e., this value identifies each system if information about multiple systems is registered in one file. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A file or label does not exist. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char* argv[]) { tmaxreadenv(“tmax.env”, “tmax”); /*”obtains environment variable from "tmax"section of tmax.env"*/ tpstart((TPSTART_T *)NULL); data process… tpend(); }
Related Function
tpstart()
The tp_sleep function waits for data to arrive.
In Tmax v5.0 SP2 Fix#1 and previous versions, if a command is executed in a tmadmin while executing a tp_sleep(), a server library received an event from a TMM and a tp_sleep() no longer waited for data. After Tmax v5.0 SP2 Fix#1, if a server library receives an event, the event will be handled and a tp_sleep() will wait for data to arrive for the remaining time.
Prototype
#include <tmaxapi.h> int tp_sleep (int sec)
Parameter
Parameter | Description |
---|---|
sec | A wait period value. Must be a positive number in seconds. |
Return Value
Value | Description |
---|---|
Positive Number | Data arrived within a sec. |
0 | Data did not arrive within a sec. |
-1 | An error occurred. A tperrno is set to an error code. |
Error
When a tp_sleep() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Related Functions
tpacall(), tpbroadcast(), tpgetrply(), tp_usleep(), tpsleep()
The tp_usleep function waits for data to arrive and immediately returns it if data arrives within a specified time.
Prototype
#include <tmaxapi.h> int tp_usleep (int usec)
Parameter
Parameter | Description |
---|---|
usec | A wait period value. Must be a positive number in microseconds. |
Return Value
Value | Description |
---|---|
Positive Number | Data arrived within usec. |
0 | Data did not arrive within usec. |
-1 | An error occurred. A tperrno is set to an error code. |
Error
When a tp_usleep() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret, cd; char *buf; long revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) {error processing} data process… cd=tpconnect(“SERVICE”, buf, 0, TPRECVONLY); if (cd<0) { error processing } while(1) { ret=tp_usleep(2000000); if (ret<0) {error processing } if (ret==0) printf("waited 2sec..\n"); else { printf("data received!\n"); break; } } ret=tprecv(cd, &buf, &len, TPNOFLAGS, &revent); if (ret<0) { error processing } data process.... tpend(); }
Related Functions
tmax_get_db_usrname(), tmax_get_db_tnsname()
The tpabort function operates similarly as a tx_rollback(). This function is used to apply a function used in Tuxedo to a Tmax system, and helps convert a program developed for Tuxedo into a program suitable for Tmax without any modifications.
Prototype
#include <tuxfml.h> int tpabort (long flags)
Parameter
Parameter | Description |
---|---|
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Refer to "3.1.88. tx_rollback".
Error
Refer to "3.1.88. tx_rollback".
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <tuxinc/tuxfml.h> void main(int argc, char *argv[]) { char *buf; int ret; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process… ret = tpbegin(5, TPNOFLAGS); if (ret < 0){ error processing } ret=tpcall(“SERVICE",(char *)buf,strlen(buf),(char **)&buf,&len,TPNOFLAGS); if (ret == -1) { ret = tpabort(TPNOFLAGS); if (ret < 0){ error processing } tpfree(buf); tpend(); exit(1); } ret = tpcommit(TPNOFLAGS); if (ret < 0){ error processing } tpfree(buf); tpend(); }
Related Function
tx_rollback()
The tpacall function sends a service request to a svc service through asynchronous communication and returns a response immediately. A response can be obtained using a tpgetrply() or canceled using a tpcancel().
Prototype
# include <atmi.h> int tpacall (char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
svc | A service to call. Must be provided by a Tmax application server program. |
data | A pointer to a buffer allocated by a tpalloc(). |
len | The length of data to be sent.
If data is NULL, len will be ignored and a service request is received without data. The data type and subtype must be supported by svc. If a service request is sent in transaction mode, a reply must be received. |
flags | Flags are listed in the following table. |
The following are the available flags:
Flag | Description |
---|---|
TPBLOCK | If a tpacall is used without a flag, a normal reply is returned even if a called service does not exist in a svc or an invalid result is returned. An error is returned when a tpgetrply is called. If a TPBLOCK is used to call a tpacall(), the service state can be checked. |
TPNOTRAN | If a service does not support transactions in a transaction mode, a TPNOTRAN flag must be set in order to call a tpacall(). If a caller requests a svc service by setting a flag in a transaction mode, a svc service will be excluded from the transaction mode and executed. When a process that uses a tx_begin() to start a transaction calls a tpacall() in a transaction mode, it is affected by a transaction timeout (TXTIME) even if a TPNOTRAN is set. For example, a tpacall with a set TPNOTRAN will fail after a transaction times out without calling a service. If a service called when a TPNOTRAN is set fails, the current transaction of the caller will not be affected. |
TPNOREPLY | If a tpacall() is used to send a service request, tpacall will be returned immediately without waiting for a response. A client can retrieve results by using a tpgetrply() through the descriptor returned by tpacall(). If a TPNOREPLY is set, a tpacall() will not receive a reply and will return a 0 if a service is called successfully. If a caller is in transaction mode, a TPNOREPLY must be set together with a TPNOTRAN. If a TPNOREPLY is set, a TPBLOCK must also be set in order to check a service state. If a TPBLOCK is not set, an error will not be returned even if a service is NRDY. |
TPNOBLOCK | If there is a blocking condition (e.g., an internal buffer is filled with messages to transmit), this option will cause a request to fail. If a tpacall() is called without setting a TPNOBLOCK flag and a blocking condition occurs, a caller must wait until a timeout (transaction or blocking timeout) occurs. |
TPNOTIME | A caller must wait indefinitely until a response is received. Blocking timeouts are ignored. A timeout will occur even if a tpacall() is called during a transaction timeout. |
TPSIGRSTRT | Allows signal interrupts. If a system function call is interrupted by a signal, it will be re-executed. If a signal interrupt occurs without this flag set, a function will fail and tperrno will be set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call is successful. A returned descriptor is used to get a service reply. |
-1 | A function call failed, and a tperrno is set to an error code. |
Error
If a tpacall() fails, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, when a svc is NULL, data will point to a buffer that was not allocated by a tpalloc(), or a flag will be invalid. |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A data type or subtype is not supported by a svc. For a struct, this error occurs when the struct is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests has been reached. A request cannot be sent. |
[TPETIME] | A transaction timeout occurred when a caller was in a transaction mode, and a transaction was rolled back. If a caller is not in a transaction mode, a block timeout will occur if both a TPNOTIME and a TPNOBLOCK are not set. In such cases, the data in *data and *len are not changed. If a transaction timeout occurs, any new service requests and processes waiting for a response will fail due to a [TPETIME] error until the transaction is rolled back. |
[TPEBLOCK] | Blocking occurred while a TPNOBLOCK is set. |
[TPGOTSIG] | A signal is received while a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpacall() was called in an invalid state. For example, a TPNOREPLY was called in a transaction mode without setting a TPNOTRAN. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len; ret=tpstart((TPSTART_T *)NULL); if (ret<0) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing } data process.... cd = tpacall(“SERVICE”, sndbuf, 20, TPNOTIME); if (cd<0) {error processing } data process… ret=tpgetrply(&cd, (char **)&buf, &len, TPNOTIME); if (ret<0) { error processing } data process.... tpfree((char *)buf); tpend(); }
Related Functions
tpalloc(), tpcall(), tpcancel(), tpgetrply()
The tpacallsvg function asynchronously calls a service from a server group in a multi server group environment grouped by COUSIN. The only difference between tpacall and tpacallsvg is that tpacallsvg can call a service from specific a server group.
Prototype
#include <usrinc/tmaxapi.h> int tpacallsvg (int svgno, char *svc, char *data, long lenl, long flagsl)
Parameter
Refer to "3.1.24. tpacall" for the parameters other than svgno.
Parameter | Description |
---|---|
svgno | The number of a server group that contains a service to be called. The server group number can be found using a tpgetsvglist() API. If a svgno is set to -1, a tpacallsvg() functions the same as a tpacall(). When calling a service from within a service, a tpgetmysvgno() API can be used to look up the current server group number and call other services in the same server group. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful. (client descriptor). |
-1 | A function call failed. A tperrno is set to an error code. |
Error
Refer to the error section of the "3.1.24. tpacall" function.
Example
<Client Program>
#include <usrinc/tmaxapi.h> #include “../fdl/demo_fdl.h” int main(int argc, char *argv[]) { FBUF *sndbuf, *rcvbuf; int ret, I, cd; char sndata[30], rcvdata[30]; long sndlen, rcvlen; struct svglist *svg_list; char svc[32]; ret = tmaxreadenv( “tmax.env”,”TMAX” ); ret = tpstart((TPSTART_T *)NULL); sndbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)}; rcvbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)); strcpy(sndata, argv[1]); ret = fbput(sndbuf, INPUT, sndata, 0); strcpy(svc, “FDLTOUPPER”); svg_list = (struct svglist *)tpgetsvglist(svc, 0); for(i=0; i< svg_list->ns_entry; i++) { printf(“\n”); printf(“ >>> tpcallsvg ( %d th svg )\n”, i+1); strcpy(sndata, argv[1]); ret = fbput(sndbuf, INPUT, sndata, 0); cd = tpacallsvg(svg_list->s_list[i], svc, (char *)sndbuf, 0, 0); if(cd < 0) { printf(“tpacall failed! errno = %d[%s]\n”, tperrno, tpstrerror(tperrno)); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } ret = tpgetrply(&cd, (char **)&rcvbuf, (long *)&rcvlen, 0); ret = fbget(rcvbuf, OUTPUT, rcvdata, 0); fbprint(rcvbuf); } tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); return 0; }
Related Functions
tpacall(), tpcallsvg(), tpgetsvglist(), tpgetmysvgno()
The tpalivechk function displays the connection status of a client by checking the socket status. This function acts the same as the tmax_chk_conn() function if the factor is set to 0.
Prototype
#include <usrinc/tmaxapi.h> int tpalivechk(void)
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpalivechk() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | tpstart() did not execute. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include <usrinc/tmaxapi.h> #include “../fdl/demo_fdl.h” main(int argc, char *argv[]) { FBUF *sndbuf, *rcvbuf; int chkno; char sndata[30], rcvdata[30]; char input[10], outdata[10]; long sndlen, rcvlen; if ( (ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ){ printf( “tmax read env failed\n” ); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1) error processing… if ((sndbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)) == NULL) error processing… if ((rcvbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)) == NULL) error processing… /* socket status check */ chkno = tpalivechk(); printf(“chkno = %d\n”, chkno); if(chkno < 0) { printf(“The situation of socket is bad\n”); printf(“errno = %d\tstrerror=%s\n”, tperrno, tpstrerror(tperrno) ); } else if(chkno == 0) { printf(“The situation of socket is good\n”); } tpcall… data process… tpend(); }
Related Function
tmax_chk_conn()
A server or client allocates the buffer type to be used. A buffer cannot be set by malloc(), realloc(), or free() of C library. For example, the buffer allocated with tpalloc() cannot be deleted through free().The tpalloc function allocates a typed buffer in servers and clients. It cannot be used along with malloc(), realloc(), or free() of C library. For example, a buffer allocated by tpalloc() cannot be released by free().In this case, tpfree() must be used.
The tpalloc function allocates a buffer of the type specified by "type", and it returns the pointer to the buffer. The buffer subtype and size can also be specified for some types. Some types of buffers require initialization, so tpalloc() initializes and returns pointers to these buffers. The buffer returned to the caller can be used immediately. If tpalloc() fails to initialize the buffer to 0, the allocated buffer becomes free.
Prototype
# include <atmi.h> char * tpalloc (char *type, char *subtype, long size)
Parameter
Parameter | Description |
---|---|
type | Buffer type. Input options:
|
subtype | For STRUCT, X_C_TYPE, and X_COMMON type buffers, a subtype must be set. Only the first 8 bytes of type and the first 16 bytes of subtype are used. Any remaining data is truncated. If the specified buffer type does not use a subtype, the subtype is ignored and NULL is used. The default allocated buffer size is greater than 1024 bytes. |
size | If type is CARRY or X_OCTET, size must be specified. size is not required for other buffer types. If size is 0, the default size of each buffer is used. The default size of STRING, STRUCT, X_C_TYPE, X_COMMON is 1024 bytes. The default size of CARRY is 0, but the size must be greater than 0 when allocating a buffer. |
Return Value
Value | Description |
---|---|
Buffer Pointer | A function call was successful and a proper buffer pointer is returned. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tpalloc() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a type is NULL. |
[TPENOENT] | Unknown type or subtype. For example, in a STRUCT buffer type the subtype (tag name of the structure) does not exist in SDLFILE. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPEOTYPE] | Buffer type is STRUCT but the server is compiled without a structure file. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” void main(int argc, char *argv[]) { int ret; struct data *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret<0) { error processing } buf=(struct data *)tpalloc(“STRUCT”, “data”,0); data process.... ret=tpcall(“SERVICE”, (char *)sndbuf, 0, (char **)&rcvbuf, &len, TPNOFLAGS); if (ret<0) {error processing } data process.... tpfree((char *)buf); tpend(); }
Related Functions
tpfree(), tprealloc(), tptypes()
The tpbegin function executes both tx_set_transaction_timeout() and tx_begin() simultaneously. This function enables functions used in Tuxedo to have the same effect in a Tmax system. I.e., this function allows a program developed in Tuxedo to be used in Tmax without any modifications. The global transaction function for tpbegin() is the same as for tx_begin().
Prototype
int tpbegin(unsigned long timeout, long flags);
Parameter
Parameter | Description |
---|---|
timeout | Transaction timeout. Used in the same manner as tx_set_transaction_timeout(). (Unit: second) |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Refer to "3.1.91. tx_set_transaction_timeout" and "3.1.85. tx_begin".
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <tuxinc/tuxfml.h> void main(int argc, char *argv[]) { char *buf; int ret; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process… ret = tpbegin(5, TPNOFLAGS); if (ret < 0){ error processing } ret = tpcall(“SERVICE”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { ret = tpabort(TPNOFLAGS); if (ret < 0){ error processing } tpfree(buf); tpend(); exit(1); } ret = tpcommit(TPNOFLAGS); if (ret < 0){ error processing } tpfree(buf); tpend(); }
Related Functions
tx_set_transaction_timeout(), tx_begin()
The tpbroadcast function broadcasts notifications to clients registered in the Tmax system. To receive a notification, a client must be connected to the Tmax system using tpstart(), the client name and flags must be defined correctly, and flag values of the TPSTART_T structure used for tpstart() must be set to TPUNSOL_POLL or TPUNSOL_HND. This function can be used on both the client and the server.
Prototype
# include <atmi.h> int tpbroadcast (char *nodename, char *usrname, char *cltname, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
nodename, usrname, cltname | Logical names used to select target clients. The name length must be 15 characters or less. Wildcards (?, *, etc.) can be used to specify names. NULL can also be used as a wildcard corresponding to all clients. A string argument with a length of 0 corresponds only to a client name with a string length of 0. cltname is the client name used, which is registered when the client first accesses the Tmax system, when using the tpstart() function. |
data | A buffer must be allocated through tpalloc() in advance. |
len | Length of data to receive. For STRING, STRUCT, X_COMMON, and X_C_TYPE buffers, which require no length specification, len is ignored and 0 is used by default. len is also ignored if data is NULL. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOBLOCK | If a blocking condition (e.g., the internal buffer is filled with messages to be transmitted) is encountered, the request is not sent. |
TPNOTIME | Function caller must wait indefinitely until a response is received. Blocking timeout is ignored. If tpbroadcast() is called during a transaction timeout, transaction timeout applies. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function is executed again. If the signal interrupt occurs without this flag, the function fails and tperrno is set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpbroadcast() fails to execute and no messages can be transmitted to a client, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, an identifier is too long or a flag is invalid. If a nodename is incorrect, a tpbroadcast() will fail and return a TPEINVAL. However, if a usrname or cltname is invalid, a message will not be transmitted, but a function will be considered to have executed successfully. |
[TPETIME] | Blocking timeout occurred while TPNOBLOCK or TPNOTIME is not set. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpbroadcast() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *buf; TPSTART_T *tpinfo; tpinfo = (TPSTART_T *)tpalloc(“TPSTART”, NULL, sizeof(TPSTART_T)); if (tpinfo==NULL) { error processing } strcpy(tpinfo->cltname, “cli1”); strcpy(tpinfo->usrname, “navis”); ret=tpstart(tpinfo); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process… tpbroadcast(“tmax”, NULL, NULL, buf, 0, TPNOFLAGS); data process.... tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpend(), tpstart()
The tpcall function sends a service request to a svc service named through synchronous communication and receives a response. It works similar to calling a tpgetrply() successively after calling a tpacall().
Prototype
# include <atmi.h> int tpcall (char *svc, char *idata, long ilen, char **odata, long *olen, long flags)
Parameter
Parameter | Description |
---|---|
svc | A service to call. Must be provided by a Tmax application server program. |
idata | A pointer to service request data. Must be a buffer that is allocated by a tpalloc(). The type and subtype of an idata must be supported by a svc. |
ilen | Data length.
If an idata is NULL, it will be ignored. |
*odata | Response data buffer pointer with length of a *olen. Must be allocated by a tpalloc(). If the same buffer is used for both sent and received data, a *odata must be set to an idata address. To detect change in a response buffer size, compare the response buffer size allocated to a *odata before a tpcall() is complete and the size of a returned *olen. If a *olen size is larger, an allocated response buffer size will be increased. Otherwise, it will remain the same. If a tpcall() is called when an idata and a *odata are using the same buffer, the address indicated by the idata will no longer be valid if the *odata is changed. The *odata may be changed if received data is too big or for other reasons. If a *olen is returned as a 0, no data will be received and a *odata and a buffer pointed to by the *odata will not be changed. If *odata or *olen are NULL, an error will occur. |
*olen | Reply data length in a *odata. |
flags | A communication mode option. |
The following are available flags:
Flag | Description |
---|---|
TPNOTRAN | If a service does not support transactions in a transaction mode, a TPNOTRAN flag must be set in order to call a tpcall() in a transaction mode. If a caller requests a svc service by setting a flag in a transaction mode, the svc service will be excluded from a transaction mode and then executed. When a process that uses a tx_begin() to start a transaction calls a tpcall() in a transaction mode, it will be affected by a transaction timeout (TXTIME) even if a TPNOTRAN was set. For example, a tpacall with a TPNOTRAN set will fail after a transaction times out without calling a service. If a service called with a TPNOTRAN set fails, a caller's current transaction will not be affected. |
TPNOCHANGE | If a TPNOBLOCK flag is set and a blocking condition (e.g., the internal buffer is full with messages to send) occurs, a request will fail. A TPNOCHANGE is applied only to a Tx in a tpcall(). If a tpacall() is called without setting a TPNOBLOCK flag and a blocking condition occurs, a caller must wait until it is unblocked or timeout (transaction or blocking timeout) occurs. |
TPNOTIME | A caller must wait indefinitely until a response is received and blocking timeout will be ignored. Timeout will occur even if a tpcall() is called during a transaction timeout. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. . |
-1 | A function call failed, and a tperrno is set to an error code. |
Error
If a tpcall() fails, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | Invalid parameter or flag. For example, svc is NULL or idata points to a buffer that was not allocated by a tpalloc(). |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support the idata type or subtype. |
[TPEOTYPE] | A function caller does not know the type or subtype of a response buffer, or flags were set to a TPNOCHANGE but the type or the subtype of the buffer pointed to by a *odata does not match that of the response buffer. In this case, the data in a *odata and a *olen are not changed. If a caller requests a service in a transaction mode, the transaction will be rolled back because the reply will be ignored. |
[TPETRAN] | A xa_start failed due to an error in a database while invoking a transaction service. |
[TPETIME] | A transaction timeout occurred when a caller was in a transaction mode, and the transaction was rolled back. If a caller is not in a transaction mode, a block timeout will occur if both a TPNOTIME and a TPNOBLOCK are not set. In such cases, the data in a *data and a *len are not changed. If a transaction timeout occurs, any new service requests and processes waiting for a response will fail due to a [TPETIME] error until the transaction is rolled back. |
[TPESVCFAIL] | A service routine sent a reply by calling a tpreturn() with a TPFAIL because an error occurred in an application program. Service reply data can be accessed through a *odata. When a transaction timeout occurs, other communication may be attempted before a transaction is rolled back. For such attempts to be successful, a TPNOTRAN must be set. All operations performed while a caller is in a transaction mode are rolled back when the transaction is complete. |
[TPESVCERR] | An error occurred during the execution of a service routine or a tpreturn() (e.g., a wrong argument was passed). If this error occurs, no reply data will be returned (i.e., neither *odata nor *olen is changed). This error occurs when a buffer that was not allocated by a tpalloc is used, the Tmax header of an allocated buffer is affected by an invalid pointer (due to memcpy, etc.), a call descriptor of a tpacall or a tpconnect is returned, or when a service includes invalid conversational data while in a Recv mode. A client will receive this error when attempting to execute a tpreturn. When a TPEV_DISCOMN event occurs (e.g., after a client forcefully disconnects a conversation, a service program will receive a TPEV_DISCOMN) a client will receive this error through a tpreturn of a service. When a caller is in a transaction mode, other communication may be attempted before a transaction is rolled back and timeout occurs. For such attempts to be successful, a TPNOTRAN must be set. All operations performed while a caller is in a transaction mode are rolled back when a transaction is complete. A SVCTIMEOUT can be specified for each service. If a service execution time exceeds a specified limit, a service will stop executing and will return a TPESVCERR. If a SVCTIMEOUT occurs, a tpsvctimeout() will be called. Operations such as buffer lock releases and logging can be performed during a tpsvctimeout() as needed. |
[TPEBLOCK] | Blocking occurred while a TPNOBLOCK was set. |
[TPGOTSIG] | A signal was received while a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpcall() was called in an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *sndbuf, *rcvbuf; long sndlen, rcvlen; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } sndbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (sndbuf==NULL) {error processing }; rcvbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (rcvbuf==NULL) {error processing }; data process.... sndbuf=strlen(sndbuf); ret=tpcall(”SERVICE”, sndbuf, sndlen, &rcvbuf, &rcvlen, TPNOCHANGE); if (ret==-1) { error processing } data process.... tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Functions
tpalloc(), tpacall(), tpgetrply(), tpreturn()
The tpcallsvg function synchronously calls a service from a server group in a multi server group environment grouped by a COUSIN. The only difference between a tpcall function and a tpcallsvg function is that a tpcallsvg can call a service from a specific server group.
When calling a service from within a service, a tpgetmysvgno() API can be used to look up the current server group number and call other services in the same server group.
Prototype
#include <usrinc/tmaxapi.h> int tpcallsvg (int svgno, char *svc, char *idata, long ilenl, char **odata, long *olen, long flagsl)
Parameter
Refer to "3.1.30. tpcall" for parameters other than svgno.
Parameter | Description |
---|---|
svgno | The number of the server group that contains a service to be called. The server group number can be found using a tpgetsvglist() API. If a svgno is set to -1, a tpcallsvg() functions the same as a tpcall(). |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
Refer to the error section of the "3.1.30. tpcall" section.
Example
<Client Program>
#include <usrinc/tmaxapi.h> #include “../fdl/demo_fdl.h” int main(int argc, char *argv[]) { FBUF *sndbuf, *rcvbuf; int ret, i; char sndata[30], rcvdata[30]; long sndlen, rcvlen; struct svglist *svg_list; char svc[32]; ret = tmaxreadenv( “tmax.env”,”TMAX” ); ret = tpstart((TPSTART_T *)NULL); sndbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)}; rcvbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)); strcpy(sndata, argv[1]); ret = fbput(sndbuf, INPUT, sndata, 0); strcpy(svc, “FDLTOUPPER”); svg_list = (struct svglist *)tpgetsvglist(svc, 0); for(i=0; i< svg_list->ns_entry; i++) { printf(“\n”); printf(“ >>> tpcallsvg ( %d th svg )\n”, i+1); strcpy(sndata, argv[1]); ret = fbput(sndbuf, INPUT, sndata, 0); if (tpcallsvg(svg_list->s_list[i], svc, (char *)sndbuf, 0, (char **)&rcvbuf, &rcvlen, 0) == -1) { printf("tpcall failed! errno = %d[%s]\n",tperrno,tpstrerror(tperrno)); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } ret = fbget(rcvbuf, OUTPUT, rcvdata, 0); fbprint(rcvbuf); } tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); return 0; }
Related Functions
tpcall(), tpacallsvg(), tpgetsvglist(), tpgetmysvgno()
The tpcancel function cancels a server or client response. It cancels a cd, the caller description returned by a tpacall().
Prototype
# include <atmi.h> int tpcancel (int cd)
Parameter
Parameter | Description |
---|---|
cd | A target to be canceled, which is set by a caller descriptor returned by a tpacall(). Services related to global transactions cannot be canceled. If a service response is canceled, a cd is nullified and all responses received through the cd are ignored. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpcancel() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid cd. |
[TPETRAN] | A cd is related to a caller's global transaction. It is still valid and the caller's current transaction is not affected. |
[TPEPROTO] | A tpcanceled() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *test[2]; int ret, i, cd[2]; long len; if (argc != 4) { error processing } ret=tpstart((TPSTART_T *)NULL; if (ret==-1) { error processing } for (i=0; i<3; i++) { test[i] = tpalloc(“STRING”,NULL,0); if (test[I])==NULL} { error processing } strcpy(test[i],argv[i+1]); cd[i]=tpacall(“SERVICE”, test[i], 0, TPNOTIME); ) ret=tpcancel(cd[1]); /* Cancels the second response. */ if (ret==-1) { error processing } for (i=0; i<3; i++) { ret=tpgetrply(&cd[i], (char **)&test[i], &len, TPNOTIME) if (ret==-1) printf(“Can’t rcv data from service of %d\n”,cd[i]); else prtinf(“%dth rcv data : %s\n”, I+1, test[I]); tpfree(test[I]); } tpend(); }
Related Function
tpacall()
The tpcommit function performs the same function as the tx_commit() function.
This function is used to apply a function used in Tuxedo to a Tmax system. A tpcommit() helps convert a program developed for Tuxedo into a program suitable for Tmax without any modification.
Prototype
#include <tuxfml.h> int tpcommit (long flags)
Parameter
Parameter | Description |
---|---|
flags | Flags are not used. Set to TPNOFLAGS. |
Return Value
Refer to "3.1.86. tx_commit".
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <tuxinc/tuxfml.h> void main(int argc, char *argv[]) { char *buf; int ret; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process… ret = tpbegin(5, TPNOFLAGS); if (ret < 0){ error processing } ret=tpcall("SERVICE",(char *)buf,strlen(buf),(char **)&buf,&len,TPNOFLAGS); if (ret == -1) { ret = tpabort(TPNOFLAGS); if (ret < 0){ error processing } tpfree(buf); tpend(); exit(1); } ret = tpcommit(TPNOFLAGS); if (ret < 0){ error processing } tpfree(buf); tpend(); }
Related Function
tx_commit()
The tpconnect function allows a program to communicate with an interactive service svc. Communication is half-duplex, which only allows receiving or sending but not both at the same time. During a connection configuration process, a function caller can deliver data to a service routine. Interactive services receives data and len using a TPVCINFO structure, so calling a tprecv() is unnecessary to receive data delivered by a tpconnect(). This function can be used on both a client and a server.
Prototype
# include <atmi.h> int tpconnect (char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
svc | The service name of an interactive service. |
data | A buffer must be allocated by a tpalloc() for a caller to deliver data. |
len | The length of data to be sent.
If data is NULL, a len will be ignored and a service request will be received without data. The data type and subtype must be supported by a svc. |
flags | An option to call a function. Determines a call mode. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOTRAN | If a tpconnect() caller requests a svc service by setting a TPNOTRAN flag in a transaction mode, the svc service will be excluded from a transaction mode and then executed. If a svc does not support transactions in a transaction mode and a tpconnect() is called in a transaction mode, a flag must be set to TPNOTRAN. If a tpconnect() is called in a transaction mode, it is affected by a transaction timeout even if TPNOTRAN is set. If a service with a TPNOTRAN flag set fails, a caller's transaction will not be affected. |
TPSENDONLY | After a connection is made, a caller can initially only send data and only requested services can be performed, so at first, a caller only has communication control. Either a TPSENDONLY or TPRECVONLY must be set. |
TPRECVONLY | After a connection is made, a caller can initially only receive data and a requested service will send data, so at first, a requested service only has communication control. Either a TPSENDONLY or TPRECVONLY must be set. |
TPNOTIME | A function caller must wait indefinitely until a response is received. Blocking timeouts are ignored. If a tpacall() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, the function will fail and a tperrno will be set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful and a descriptor used for a following connection is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
If a function call fails, a caller's transaction will not be affected unless there is a specific direction. When a tpconnect() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | Cannot request a service because a service corresponding to a svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. |
[TPELIMIT] | A maximum number of connections has been reached. Cannot request a service. |
[TPETRAN] | A xa_start failed because a problem occurred in a database when a transaction service was requested. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, the transaction will be rolled back. If the function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, *data content and *len are not changed. If a transaction timeout occurs, new service requests and processes waiting for a response fail with the [TPETIME] error until the transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal was received when a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpconnect() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *buf; int ret, cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”,NULL,0); if (buf=NULL) { error procesing } data process .... cd = tpconnect(“SERVICE”,sndbuf,0,TPRECVONLY); if (cd==-1) { error processing } data process.... ret=tprecv(cd, &buf, &len, TPNOFLAGS, revent); if (ret==-1) { error processing } tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpdiscon(), tprecv(), tpsend()
The tpdeq function loads data from a RQ. It receives the result of a service request or sets a service name to NULL and then reads stored data by using a tpenq() function. However, if a TPNOREPLY is set when a tpenq() is called, a service cannot receive any results, so even if an error occurs while executing a tpdeq() in a transaction mode, a transaction will not be affected.
Prototype
# include <tmaxapi.h> int tpdeq (char *qname, char *svc, char **data, long *len, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | A svc must be set to a service name when a tpenq() is called. In other words, if a tpenq() is called with a service name, a service will automatically be requested and the results will be stored in a RQ. In order to receive service results, the same service name must be specified. If the service name is NULL when a tpenq() is called, the same service name must be entered for a tpdeq_ctl(). If the service name is NULL, all data accumulated in a queue can be loaded individually regardless of the service name. To call a tpdeq() for data saved in a fail queue due to an error or a system failure, a svc must be set to _rq_sub_queue_name[TMAX_FAIL_QUEUE]. |
*data | A pointer to a buffer allocated by a tpalloc(). When a function is successfully returned, received data will be stored in a *data. |
len | Size of the data received by a tpdeq(). A tpdeq() can increase a buffer size if a reply is larger than the buffer. Returned results are stored in a *data, and a len will be the size of received data. A *data can be modified if the size of received data is too large. If a len is larger than the total size of a previously called buffer, a larger buffer size will be allocated. If a len returns a 0, no data will be received and nothing will be changed in the buffer indicated by a *data and a len. If a *data or a len is NULL, an error will occur. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPRQS | Loads service results from a reply queue (RQ). |
TPFUNC | Manages RQ data by service. If a TPFUNC is not set, data stored by a tpenq() will be dequeued when it is initially stored. If data must be dequeued before it is stored, a TPFUNC must be set when calling a tpenq(). |
TPBLOCK | Waits until a message is returned during a block timeout. |
TPNOTIME | If a TPNOTIME and a TPBLOCK are both set, a function will wait until a reply is returned regardless of a block timeout. |
0(zero) | Loads data from the buffer of a client that a function caller is connected to. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpdeq() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT was not set. |
[TPEMATCH] | When a service name is wrong or there is no data to be dequeued, no data will be found for a given key. |
[TPENOENT] | An invalid qname. |
[TPEPROTO] | A tpdeq() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) { error processing } data process.... ret=tpdeq(“RQ”, “SERVICE”, (char **)&buf, (long *)&len, TPRQS); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpenq(), tpqstat()
The tpdeq_ctl function reads data from tpenq_ctl() service request results or data from a tpenq_ctl() with a NULL argument. However, there are no response if a tpenq_ctl() has a TPNOREPLY flag set. If a tpdeq_ctl() is executed in a transaction mode, data load operations from a RQ will be processed in a transaction. If two or more calls to a tpdeq_ctl() are grouped as one transaction, an error while loading data from a RQ will roll back everything.
Prototype
#include <usrinc/tmaxapi.h> int tpdeq_ctl(char *qname, char *svc, TMQCTL *ctl, char **data, long *len, long flags);
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | A svc must be set to a service name when a tpenq() is called. In other words, if a tpenq() is called with a service name, a service will automatically be requested and the results will be stored in a RQ. In order to receive service results, the same service name must be specified. If the service name is NULL when a tpenq() is called, the same service name must be entered for a tpdeq_ctl(). If the service name is NULL, all data accumulated in a queue can be loaded individually regardless of the service name. To call a tpdeq() for data saved in a fail queue due to an error or a system failure, a svc must be set to _rq_sub_queue_name[TMAX_FAIL_QUEUE]. |
data | A pointer to a buffer allocated by a tpalloc(). When a function is successfully returned, received data will be stored in a *data. |
len | The size of the data received by a tpdeq_ctl(). A tpdeq_ctl() can increase a buffer size if a reply is larger than the buffer. Returned results are stored in a *data, and a len will be the size of received data. A *data can be modified if the size of received data is too large. If a len is larger than the total size of a previously called buffer, a larger buffer size will be allocated. If a len returns a 0, no data will be received and nothing will be changed in the buffer indicated by a *data and a len. If a *data or a len is NULL, an error will occur. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPRQS | Loads service results from a RQ. |
TPFUNC | Manages RQ data by service. If a TPFUNC is not set, data stored by a tpenq() will be dequeued when it is initially stored. If data must be dequeued before it is stored, a TPFUNC must be set when calling a tpenq(). |
TPBLOCK | Waits until a message returns during a block timeout. |
TPNOTIME | If a TPNOTIME and a TPBLOCK are both set, a function will wait until a reply is returned regardless of a block timeout. |
0(zero) | Loads data from the buffer of a client that a function caller is connected to. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpdeq_ctl() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT was not set. |
[TPEMATCH] | When a service name is wrong or there is no data to be dequeued, no data will be found for a given key. |
[TPENOENT] | An invalid qname. |
[TPEPROTO] | A tpdeq() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen, sndlen, revent; int ret, i, cd; TMQCTL *ctl; ctl = (TMQCTL*)malloc(sizeof(TMQCTL)); memset(ctl, 0, sizeof(TMQCTL)); if (argc != 2) { printf(“Usage: toupper_rq string\n”); exit(1); } if ( (ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ){ printf( “tmax read env failed\n” ); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf(“tpstart failed\n”); exit(1); } if ((sndbuf = (char *)tpalloc(“STRING”, NULL, 0)) == NULL) { printf(“sendbuf alloc failed !\n”); tpend(); exit(1); } if ((rcvbuf = (char *)tpalloc(“STRING”, NULL, 0)) == NULL) { printf(“recvbuf alloc failed !\n”); tpfree((char *)sndbuf); tpend(); exit(1); } ret = tx_begin(); if(ret < 0) { fprintf(stderr, “tx_begin() fail\n”); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); exit(1); } strcpy(sndbuf, argv[1]); cd = tpdeq_ctl(“txrq1”, “TOUPPER”, ctl, &rcvbuf, &rcvlen, TPRQS ); if (cd < 0) { printf(“tpdeq failed [%s]\n”, tpstrerror(tperrno) ); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } cd = tpdeq_ctl(“txrq1”, “TOUPPER”, ctl, &rcvbuf, &rcvlen, TPRQS ); if (cd < 0) { printf(“tpdeq failed [%s]\n”, tpstrerror(tperrno) ); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } data process.... ret = tx_commit(); if(ret < 0) { fprintf(stderr, “tx_commit() fail\n”); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tx_rollback(); exit(1); } tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Functions
tpenq_ctl(), tpqstat()
The tpdiscon function terminates an interactive communications connection. If a service is connected by a tpconnect(), in extremely rare cases the connection will immediately terminate and a TPEV_DISCONIMM event will occur for the connection partner. This function can be used on both a client and a server.
A tpdiscon() can be called only by the side that started an interactive communication. The service that provides a descriptor cannot call a tpdiscon(). A program that communicates with an interactive service can terminate communication. To ensure correct results, a tpreturn() should be called to terminate the connection.
A tpdiscon() terminates a connection forcibly, which may result in data that did reach a target to become lost. It can be called while a connected program participates in a caller's transaction. In this case a transaction is canceled and data may be lost. A function caller does not need to have communication control.
Prototype
# include <atmi.h> int tpdiscon (int cd)
Parameter
Parameter | Description |
---|---|
cd | A descriptor returned by a tpconnect(). |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpdiscon() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid cd, or a cd is already in use by an interactive service. |
[TPETIME] | A timeout occurred due to an invalid cd. |
[TPEPROTO] | A tpdiscon() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <stdlib.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret, cd; char *buf long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... cd=tpconnect(“SERVICE”,buf,0,TPRECVONLY); if (cd==-1) { error processing } data process.... ret=tprecv(cd, (char **)&buf, &len, TPNOFLAGS, &revent); if (ret==-1 && revent != TPEV_SENDONLY && revent != TPEV_SVCSUCC) { error processing } printf(“received data = %s\n”, buf); if (atoi(buf)>90) { ret=tpdiscon(cd); if (ret==-1) {error processing } tpfree(buf); tpend(); exit(1); } data process.... tpfree(buf); tpend(); }
Related Functions
tpconnect(), tprecv(), tpreturn(), tpsend()
The Tmax system ensures the integrity of data stored in a RQ even when a system fault or error causes an out of service status. A tpenq() saves data to a RQ. If a system crashes, it will continue processing data once the system recovers.
If a service is requested through a tpcall() or a tpacall(), requests will be queued if there are other requests waiting to be processed. If a system error or failure causes a system shutdown, queued data will be lost. To prevent data loss and to improve data consistency, a tpenq() saves data in a RQ for each service request.
Although a tpenq() is executed in a transaction mode, it is excluded from transaction modes. If an error occurs while this function is being executed in a transaction mode, a transaction will not be affected.
Prototype
# include <tmaxapi.h> int tpenq (char *qname, char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | Stores data to a RQ and immediately requests a service unless a svc name is NULL. If the svc name is NULL, data is stored in the RQ but a service will not be performed. In this case, a function caller must request the service again using a tpdeq(). If a system fault occurs when there is no service named svc or a service result has not been received after a service was performed, the data will be stored internally in a Fail Queue. This data must be re-requested using a tpdeq() or processed as an error. |
data | This is a pointer to a buffer allocated by a tpalloc() unless the value is NULL,. The type and subtype of data must be supported by a svc. |
len | The length of data to be sent.
If data is NULL, len is ignored and a service request will be received without data. The data type and subtype must be supported by a svc. If a service request is sent in a transaction mode, a response must be received. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPRQS | When a svc is not NULL, a function caller will request a svc service and store service results in a RQ. To receive service results,a tpdeq() must be called. If a svc is NULL, data will be stored in a RQ but a service will not be performed. |
TPNOREPLY | When a svc is not NULL, a function caller will request a svc service and will not store results in a RQ. If a svc is NULL, data will be stored in a RQ but a service will not be not performed. |
TPFUNC | Manages RQ data by service. If a TPFUNC is not set, data stored by a tpenq() will be de-queued when it is initially stored. If data must be de-queued before it is stored, a TPFUNC must be set when calling a tpenq(). |
0(zero) | Stores service results to a client buffer of a Tmax system that is connected to a function caller. Service is requested through a RQ, but the results are saved to a client’s buffer similarly to a tpcall() function. Once this flag is set, a 0 (zero) must also be set when calling a tpdeq() in order to receive service results. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpenq() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A qname does not exist. |
[TPEQFULL] | A maximum queue length reached due to continuous service results. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpenq() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) { error processing } data process.... ret=tpdeq(“RQ”, “SERVICE”, (char **)&buf, (long *)&len, TPRQS); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpdeq(), tpqstat()
The tpenq_ctl function saves data to a RQ and supports transactions in both a server and a client. The Tmax system ensures the integrity of data stored in a RQ by saving data even when a system fault or error causes an out of service status. If a system crashes, it will continue to process data once the system recovers.
If a service is requested using a tpcall() or a tpacall(), requests will be queued if there are other requests waiting to be processed. If a system error or failure causes a system shutdown, queued data will be lost. To prevent data loss and to improve data consistency, a tpenq_ctl() saves data in a RQ for each service request.
If a tpenq_ctl() is called in a transaction mode, it will be executed using a transaction. If this function is called multiple times and the multiple calls are grouped and processed using a single transaction, data cannot be loaded using a tpdeq_ctl() until all calls are completed. If an error occurs while processing the multiple calls, the transaction will be rolled back.
Prototype
#include <usrinc/tmaxapi.h> int tpenq_ctl(char *qname, char *svc, TMQCTL *ctl, char *data, long len, long flags);
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | Stores data to a RQ and immediately requests a service unless a svc name is NULL. If a svc name is NULL, data will be stored in a RQ but a service will not be performed. In this case, a function caller must request a service again using a tpdeq_ctl(). If a system fault occurs when there is no svc service, or service results have not been received after a service was performed, data will be stored internally in a Fail Queue. This data must be re-requested using a tpdeq_ctl() or a processed error. |
ctl | If a time value is given as the third argument of a tpenq_ctl() using a TMQCTL det_time, a svc call is requested after the given time. A deq_time must be the sum of the current time and a delay_time. For example, delay_time 3 would result in deq_time of cur_time + 3. |
data | A pointer to a buffer allocated by a tpalloc(), except when NULL. type and subtype of data must be supported by a svc. |
len | The length of data to be sent.
If data is NULL, len is ignored and a service request will be received without data. The data type and subtype must be supported by a svc. If a service request is sent in a transaction mode, a response must be received. |
flags | Sets the data processing mode. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPRQS | When a svc is not NULL, a function caller will request a service named svc and store service results in a RQ. To receive the service results, a tpdeq_deq() must be called. If a svc is NULL, data will be stored to a RQ but a service will not be performed. |
TPNOREPLY | When a svc is not NULL, a function caller will request a service named svc but not store results in a RQ. If a svc is NULL, data will be stored to a RQ but a service will not be performed. |
TPFUNC | Manages RQ data by service. If a TPFUNC is not set, data stored by a tpenq() will be dequeued when it is initially stored. If data is dequeued before it is stored, a TPFUNC must be set when calling a tpenq(). |
0(zero) | Stores a service result to the client buffer of a Tmax system to which a function caller is connected. Service is requested through a RQ, but the results are saved to a client’s buffer similar to a tpcall(). Once this flag is set, a 0 (zero) must also be set when calling a tpdeq_ctl() in order to receive service results. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpenq_ctl() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | An invalid qname. |
[TPEQFULL] | A queue for service results is full. |
[TPGOTSIG] | A signal received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpenq_ctl() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen, sndlen, revent; int ret, i, cd; TMQCTL *ctl; long t; ctl = (TMQCTL*)malloc(sizeof(TMQCTL)); memset(ctl, 0, sizeof(TMQCTL)); time(&t); ctl->deq_time = (int)t + 3; if (argc != 2) { printf(“Usage: toupper string\n”); exit(1); } if ( (ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ){ printf( “tmax read env failed\n” ); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf(“tpstart failed\n”); exit(1); } if ((sndbuf = (char *)tpalloc(“STRING”, NULL, 0)) == NULL) { printf(“sendbuf alloc failed !\n”); tpend(); exit(1); } if ((rcvbuf = (char *)tpalloc(“STRING”, NULL, 0)) == NULL) { printf(“recvbuf alloc failed !\n”); tpfree((char *)sndbuf); tpend(); exit(1); } ret = tx_begin(); if(ret < 0) { fprintf(stderr, “tx_begin() fail\n”); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); exit(1); } strcpy(sndbuf, argv[1]); cd = tpenq_ctl(“txrq1”, “TOUPPER”, ctl, (char *)sndbuf, 0, TPRQS ); if (cd < 0) { printf(“tpenq failed [%s]\n”, tpstrerror(tperrno)); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } cd = tpenq_ctl(“txrq1”, “TOUPPER”, ctl, (char *)sndbuf, 0, TPRQS ); if (cd < 0) { printf(“tpenq failed [%s]\n”, tpstrerror(tperrno)); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } data process.... ret = tx_commit(); if(ret < 0) { fprintf(stderr, “tx_commit() fail\n”); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tx_rollback(); exit(1); } tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Functions
tpdeq_ctl(), tpqstat()
The tperrordetail function extracts the depth of an error, allowing clients to handle errors quickly by taking appropriate action. If a system level error occurs, a client can request for help from administrators. If an application level error occurs, a client can request help from developers.
Prototype
# include <atmi.h> int tperrordetail(int errno)
Parameter
Parameter | Description |
---|---|
errno | Currently not used. A tperrno is set to a value corresponding to an error. |
Return Value
Value | Description |
---|---|
1 | An application level error. |
2 | A system level error. |
-1 | Unknown |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } data process… ret = tpcall(“SERVICE”, sndbuf, 20, &rcvbuf, &rcvlen, TPNOCHANGE); if (ret == -1){ fprintf(stderr, “tpcall fail,,,[%d][%s]\n”, tperrordetail(tperrno), tpstrerror(tperrno)); error processing } tpfree(buf); tpend(); }
The tpextsvcinfo function provides detailed information about data from a RQ through a tpdeq() in both a server and a client.
Prototype
# include <tmaxapi.h> int tpextsvcinfo (char *data, char *svc, , int *type, int *errcode )
Parameter
Parameter | Description |
---|---|
data | A pointer allocated by a tpalloc() that stores the data read from a RQ through a tpdeq(). |
svc | A pointer that receives the service name of data. |
type | Indicates data results. |
errcode | An error code that is set when an error occurs. |
The following are the possible type values:
Configuration Value | Description |
---|---|
TPREQ(0) | A tpenq(), with a svc set to NULL, executed successfully. |
TPFAIL(1) | A tpenq(), with a svc set to a service name, failed to execute. The first parameter of a tpreturn will be set to TPFAIL. |
TPSUCCESS(2) | A tpenq(), with a svc set to a service name, executed successfully. The first parameter of a tpreturn will be set to TPSUCCESS. |
TPERR(-1) | A tpenq() failed to execute and was sent to a fail queue. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpextsvcname() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, data or a svc is NULL. |
[TPEITYPE] | An Invalid parameter. For example, data was not received from a RQ. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Related Functions
tpenq(), tpdeq(), tpextsvcname()
The tpextsvcname function extracts a service name from the data read from a RQ by using a tpdeq(). This function is generally used to read data stored in a Fail Queue and can be used on both a client and a server.
Prototype
# include <tmaxapi.h> int tpextsvcname (char *data, char *svc)
Parameter
Parameter | Description |
---|---|
data | A pointer allocated by a tpalloc() that stores read data from a RQ through a tpdeq(). |
svc | A pointer that receives the service name of data. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpextsvcname() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf, *svc_name; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) { error processing } data process.... ret=tpdeq(“RQ”, “SERVICE”, (char **)&buf, (long *)&len, TPRQS); if (ret==-1) { error processing } ret=tpextsvcname(buf, svc_name); if (ret==-1) { error processing } printf(“svc name : %s ,”,svc_name); data process.... tpfree(buf); tpend(); }
Related Functions
tpenq(), tpdeq()
The tpfree function releases memory that is allocated to a typed buffer by a tpalloc() or a tprealloc(). This function can be used on both a client and a server.
Prototype
# include <atmi.h> void tpfree(char *ptr)
Parameter
Parameter | Description |
---|---|
ptr | A pointer to a buffer allocated by a tpalloc() or a tprealloc(). If a ptr is NULL, nothing will happen. If a ptr points to a non-typed buffer or a buffer already released by a tpfree(), nothing will happen. If a ptr points to a buffer sent to a service routine, a tpfree() will not free the buffer but instead will return it as it is. To free some buffer types, related data or status information must first be removed. A tpfree() removes related information before freeing these types of buffers. Once a tpfree() returns, a ptr cannot be transferred to a XATMI routine as a parameter, and it cannot be used in any other way. |
Return Value
A tpfree() function does not return any value to a function caller.
Example
#include <usrinc/atmi.h> #include <stdio.h> #include “../sdl/demo.s” void main(int argc, char *argv[]) { int ret; struct data *buf; char *message, *message2; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct data *)tpalloc(“STRUCT”, “data”,0); if (buf==NULL) { error processing } message=tpalloc(“STRING”, NULL, 0); if (message==NULL) { error processing } message2=tpalloc(“CARRAY”, NULL, 20); if (message==NULL) { error processing } data process.... tpfree((char *)buf); tpfree(message); tpfree((char *)message2); tpend(); }
Related Functions
tpalloc(), tprealloc()
A tpfree() cannot be set with a malloc(), a realloc(), or a free() from a C library. A buffer allocated by a tpalloc() cannot be freed using a free().
The tpget_timeout function enables a user to check a configured blocking timeout, which is the maximum time for a client program to wait for a service response. This function can be used on both a client and a server.
A blocking time configured with a tpset_timeout() can be checked with a tpget_timeout(). If a tpset_timeout() is not configured, this function displays the value configured in a BLOCKTIME of a Tmax configuration file.
Prototype
#include <tmaxapi.h> int tpget_timeout(void)
Return Value
A tpget_timeout() returns a configured blocking time (in seconds) and does not return an error.
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *sndbuf, *rcvbuf; long sndlen, rcvlen; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } sndbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (sndbuf==NULL) {error processing }; rcvbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (rcvbuf==NULL) {error processing }; data process.... sndbuf=strlen(sndbuf); ret=tpset_timeout(4); if (ret==-1) { error processing } ret=tpget_timeout(); printf(“block time = %d\n”, sec); ret=tpcall(“SERVICE”, sndbuf, sndlen, &rcvbuf, &rcvlen, TPNOCHANGE); if (ret==-1) { error processing } data process.... tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
The tpgetactivesvr function retrieves a list of active servers in a node specified by a parameter. This function can be used on both a client and a server.
Prototype
#include <tmaxapi.h> int tpgetactivesvr(char *nodename, char **outbufp);
Parameter
Parameter | Description |
---|---|
nodename | The name of a node from which a list of active servers is retrieved. If a nodename is set to NULL and it is called from a client, the function will retrieve a list of servers in the node to which a Tmax system is currently connected. If it is called from a server, the function will retrieve a list of servers in the node with active servers. A list of servers in a node to which an invoking server belongs to is stored in a outbufp. |
outbufp | A list of servers is saved to a pointer of a receiving buffer. The server list is sent to a CARRAY type buffer allocated by a tpalloc() in a tpgetactivesvr(). After a list has been used, the buffer must be removed by a tpfree(). A NULL acts as a delimiter when listing servers. For example, servers svr10 and svr111 are listed as { 's', 'v', 'r', '1', '0', NULL, 's', 'v', 'r', '1', '1', '1', NULL }. |
Return Value
Value | Description |
---|---|
The number of servers | A function call was successful and the number of activated servers is returned |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetclid() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> main(int argc, char *argv[]) { char *sndbuf, *rcvbuf, *data; long rcvlen, sndlen; int ret, n, i; char nodename[35]; if (argc != 2) { printf(“Usage: toupper string\n”); exit(1); } if ( (ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ){ printf( “tmax read env failed\n” ); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf(“tpstart failed\n”); exit(1); } if ((rcvbuf = (char *)tpalloc(“STRING”, NULL, 0)) == NULL) { printf(“recvbuf alloc failed !\n”); tpfree((char *)sndbuf); tpend(); exit(1); } strcpy(nodename, “starbj”); if((n = tpgetactivesvr(nodename, &rcvbuf)) < 0) { printf(“getactivesvr failed\n”); tpfree((char *)rcvbuf); tpend(); exit(1); } printf(“Total %d servers\n”, n); data = rcvbuf; for (i = 0; i < n; i++) { printf(“ACTIVE[%s]\n”, data); data += strlen(data) + 1; } tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
The tpgetcliaddr function is used to retrieve the IP and port number of a client connecting to a Tmax system.
In the IPv6 protocol environment, use "3.1.47. tpgetcliaddr_ipv6".
Prototype
#include <tmaxapi.h> int tpgetcliaddr(int clid, int *ip, int *port, long flags);
Parameter
Parameter | Description |
---|---|
clid | A clid to be retrieved. |
ip | When a tpgetcliaddr is used, client information is returned in an ip and a port. However, an IP address is specified in the s_addr field of a sockaddr_in struct, and a inet_ntoa() function must be used to change a value into an IP address. |
port | The port number of a client. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetcliaddr() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPEITYPE] | A tpgetcliaddr() was called in an IPv6 protocol environment. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
Example
#include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) { int ret; int clid; int port; int* ip; ... clid = tpgetclid(); printf(“clid = %d\n”, clid); ret = tpgetcliaddr(clid, ip, &port, 0); if(ret < 0) error routine.. printf(“ip = %s, port = %d\n”, inet_ntoa(ip), port); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); }
Related Function
tpgetclid()
The tpgetcliaddr_ipv6 function retrieves the IP and port number of a client connecting to a Tmax system in an IPv6 protocol environment.
Prototype
#include <tmaxapi.h> #include <arpa/inet.h> int tpgetcliaddr_ipv6(int clid, struct sockaddr_storage *saddr, long flags);
Parameter
Parameter | Description |
---|---|
clid | A clid to be retrieved. |
ipaddr | When a tpgetcliaddr_ipv6 is used, client information is returned in an ip. If successful, an IP address and port number are set by a ipaddr. The protocol version of an IP can be checked through the ss_family member of a sockaddr_storage struct. A inet_ntop() is used to change an IP address into character string. Use a ntohs() to get a correct port number. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
0 | A function call was successful.. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetcliaddr_ipv6() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <arpa/inet.h> TOUPPER(TPSVCINFO *msg) { int ret; int clid; int portno; struct sockaddr_storage saddr; struct sockaddr_in *cli_sin4; struct sockaddr_in6 *cli_sin6; char ipaddrbuf[INET6_ADDRSTRLEN]; const char *ipaddr = NULL; ... clid = tpgetclid(); printf(“clid = %d\n”, clid); ret = tpgetcliaddr_ipv6(clid, &ipaddr, 0); if(ret < 0) error routine.. if (saddr.ss_family == AF_INET) { cli_sin4 = (struct sockaddr_in *)&saddr; ipaddr = inet_ntop(AF_INET, &(cli_sin4->sin_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin4->sin_port); } else if (saddr.ss_family == AF_INET6) { cli_sin6 = (struct sockaddr_in *)&saddr; ipaddr = inet_ntop(AF_INET6, &(cli_sin6->sin6_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin6->sin6_port); } if (ipaddr == NULL) ipaddr = "unknown"; printf(“ip = %s, port = %d\n”, ipaddr, portno); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); }
Related Function
tpgetclid()
The tpgetclid function retrieves the ID of a client connected to a Tmax system. This ID is a unique number in a domain system. In other words, even though a domain system is built up with multiple nodes, unique numbers are given to each client. This function is available only for a server. An ID is retrieved so that other functions, such as a tpsendtocli() function, can use it for sending a message to a client.
Prototype
#include <tmaxapi.h> int tpgetclid(void)
Return Value
Value | Description |
---|---|
A positive integer | A function call was successful and a positive integer value that corresponds to a client number is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetclid() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A tpgetclid() was called from an invalid state. For example, it was used in a client program. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int ret, clid; char *buf; buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } strcpy(buf, msg->data); data process… clid = tpgetclid(); if (clid==-1) { error process } ret=tpsendtocli(clid, buf, strlen(buf), 0); if (ret==-1) { error processing } data process…. tpreturn(TPSUCCESS,0,buf, strlen(buf), 0); }
Related Function
tpsendtocli()
The tpgetctxt function returns a context ID, which is set in a thread that calls a function, as its first parameter.
In a MultiThread/MultiContext server, a tpgetctxt returns a value of 1 or greater when the context set in a thread is valid. A tpgetctxt returns a TPNULLCONTEXT(-2) when a context is invalid or not set. A context is valid only while a service thread is processing a service request. If a tpreturn() is called after completing a service request, a context will no longer be valid and a user created thread can no longer use the context.
A tpgetctxt() is used differently in client and server programs. The following information describes the function by separating examples by server and client.
A MultiThread/MultiContext server does not support a Singlecontext.
Prototype
#include <usrinc/atmi.h> int tpgetctxt(int *ctxtid, long flags)
Parameter
Parameter | Description |
---|---|
ctxtid | Retrieves a current context at the time a function is called.
|
flags | Not currently supported. Set to TPNOFLAGS. |
Return Values
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetctxt() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a first parameter is a pointer or a second parameter is not set to 0. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example - Client Program
int newContext() { int i; int id; i = tpstart(tpinfo); if (i < 0) { printf(“\t[newContext]tpstart fail[%d][%s]\n",tperrno,tpstrerror(tperrno)); tpfree((char *)tpinfo); return -1; } i = tpgetctxt(&id,TPNOFLAGS); if (i < 0) { printf(“\t[newContext]tpgetctxt fail[%d][%s]\n",tperrno,tpstrerror(tperrno)); return -1; } return id; }
Example - Server Program
typedef param { int ctxtid; TPSVCINFO *svcinfo; } param_t; MSERVICE(TPSVCINFO *svcinfo) { pthread_t tid; param_t param; printf("MSERVICE service is started!"); tpgetctxt(¶m.ctxtid, TPNOFLAGS); param.svcinfo = svcinfo; pthread_create(&tid, NULL, THREAD_ROUTINE, ¶m); pthread_join(tid, NULL); printf("MSERVICE service is finished!"); tpreturn(TPSUCCESS, 0, svcinfo->data, 0L, TPNOFLAGS); } void *THREAD_ROUTINE(void *arg) { param_t *param; TPSVCINFO *svcinfo; param = (param_t *)arg; svcinfo = param->svcinfo; if (tpsetctxt(param->ctxtid, TPNOFLAGS) == -1) { printf("tpsetctxt(%d) failed, [tperrno:%d]", param->ctxtid, tperrno); return NULL; } tpcall("MTOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, TPNOFLAGS); if (tpsetctxt(TPNULLCONTEXT, TPNOFLAGS) == -1) { printf("tpsetctxt(TPNULLCONTEXT) failed, [tperrno:%d]", tperrno); return NULL; } return NULL; }
Related Function
tpsetctxt()
The tpgetenv function returns the value of an environment variable registered as a name. In general, a tpgetenv acts the same as a getenv() function. In a Windows client, a tpgetenv returns a value that is applied to a autoexec.bat file or a file read by a tmaxreadenv(). In Windows NT or Windows 2000, a tpgetenv returns a value specified in an environment variable. In a server, a tpgetenv returns a value specified in a shell configuration file or an envfile. This function can be used on both a client and a server.
Prototype
#include <tmaxapi.h> char *tpgetenv(char *name)
Parameter
Parameter | Description |
---|---|
name | A registered environment variable name. |
Return Value
Value | Description |
---|---|
NULL | A corresponding environment variable does not exist. |
Pointer | A corresponding environment variable exists. A pointer for the current value of an environment variable is returned. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> main(int argc, char *argv[]) { char *TMAXD, *SDLFI; TMAXD=tpgetenv(“TMAXDIR”); SDLFI=tpgetenv(“SDLFILE”); printf (“tmaxdir : %s\nsdlfile : %s\n”,TMAXD,SDLFI); }
Related Function
tpputenv()
The tpgetlev function checks whether a transaction mode is active. This function can be used on both a client and a server.
Prototype
#include <tuxatmi.h> int tpgetlev(void)
Return Value
Value | Description |
---|---|
1 | In a transaction mode. |
0 | Not in a transaction mode. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” EXEC SQL include sqlca.h; EXEC SQL begin declare section; struct emp *buf; EXEC SQL end declare section; DELETE(TPSVCINFO *msg) { struct emp *buf; buf = (struct emp *)msg->data; data process... if (tpgetlev()) printf(“transaction mode\n”); else printf(« nontransaction mode\n »); EXEC SQL DELETE FROM emp WHERE empno = :buf->empno; data process... tpreturn(TPSUCCESS,0,buf, strlen(buf), 0); }
The tpgetpeername function returns a socket address of a peer node after a connection is established to a Tmax system. This function can be used on both a client and a server.
Prototype
#include <tmaxapi.h> int tpgetpeername(struct sockaddr *name, int *namelen)
Parameter
Parameter | Description |
---|---|
name | A struct that stores an address.In an IPv6 protocol environment, a sockaddr_in6 struct can be used to check address information, while a sockaddr_storage struct can be used in both IPv4 and IPv6 environments. |
namelen | Before a tpgetpeername is called, a namelen is initialized to the size of a struct allocated by name. After a function returns a value, a namelen will be set to the actual size of a struct. |
Return Value
Value | Description |
---|---|
Socket address | A function call was successful and a peer's socket address is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetpeername() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPINVAL] | An invalid parameter. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
[TPEITYPE] | Occurs when the size of a name struct (namelen) is smaller than the actual size to be used. |
Example
#include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <usrinc/atmi.h> #inlcude <usrinc/tmaxapi.h> ... DELETE(TPSVCINFO *msg) { struct sockaddr_in cli; char ipAddr[16]; int cli_len, ret; data process... memset((char *)&cli, 0, sizeof(cli)); ret = tpgetpeername((struct sockaddr *)&cli, &cli_len); if (ret == -1){ error processing } else{ memcpy(ipAddr, inet_ntoa(cli.sin_addr), 16); } printf(“ip = %s , port = %d\n”, ipAddr, cli.sin_port); data process... tpreturn(TPSUCCESS, 0, 0, 0, 0); }
Example - IPv6 protocol environment
#include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <usrinc/atmi.h> #inlcude <usrinc/tmaxapi.h> ... DELETE(TPSVCINFO *msg) { struct sockaddr_storage cli_saddr; struct sockaddr_in *cli_sin4; struct sockaddr_in6 *cli_sin6; char ipaddrbuf[INET6_ADDRSTRLEN]; const char *ipaddr = NULL; int cli_len, ret; int portno; data process... memset((char *)&cli_saddr, 0, sizeof(cli_saddr)); cli_len = sizeof(cli_saddr); ret = tpgetpeername((struct sockaddr *)&cli_saddr, &cli_len); if (ret == -1) { error processing } else { if (cli_saddr.ss_family == AF_INET) { cli_sin4 = (struct sockaddr_in *)&cli_saddr; ipaddr = inet_ntop(AF_INET, &(cli_sin4->sin_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin4->sin_port); } else if (cli_saddr.ss_family == AF_INET6) { cli_sin6 = (struct sockaddr_in *)&cli_saddr; ipaddr = inet_ntop(AF_INET6, &(cli_sin6->sin6_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin6->sin6_port); } if (ipaddr == NULL) ipaddr = "unknown"; } printf(“ip = %s , port = %d\n”, ipaddr, portno); data process... tpreturn(TPSUCCESS, 0, 0, 0, 0); }
Related Functions
tpgetpeer_ipaddr(), tpgetsockname(), tpstart()
The tpgetrply function is used to get a reply for an asynchronous service request made through a tpacall(). This function can be used on both a client and a server.
Prototype
# include <atmi.h> int tpgetrply(int *cd, char **data, long *len, long flags)
Parameter
Parameter | Description |
---|---|
cd | A call descriptor returned by a tpacall(). In general, a tpgetrply waits until a response for a cd is received or until a timeout occurs. In general, a cd will become invalid after a tpgetrply receives a valid response. |
*data | Must be a pointer to a buffer allocated by a tpalloc(). |
len | The length of data received from a tpgetrply(). If necessary, a buffer size can be increased to store a reply. A *data can be changed for various reasons, including if a buffer is too small for received data. Before a tpgetrply is called, if a len is greater than the total size of a buffer, a buffer size will be set to the valu of len. If a returned len value is 0, no response will be received and buffers pointed to by a *data and len will not be changed. An error will occurs if a *data or a len is NULL. |
flags | Flags are listed in the following table. |
The following are the available flags:
Flag | Description |
---|---|
TPGETANY | Ignores an input argument call descriptor (cd) for a response and returns a reply that can be received. In general, a tpgetrply() will wait until a response is received. If a TPGETANY is not set, a *cd becomes null unless there is no specific configuration. If set, a cd can be used for an error response. If an error occurs before a response is returned, a cd will be set to 0. Unless otherwise specified, this does not affect a current transaction for a caller. |
TPNOCHANGE | The buffer type that a *data points to cannot be changed. If the types of a response buffer and a *data buffer do not match, the *data buffer type will be changed to the type of the response buffer. If a TPNOCHANGE flag is set, a buffer type will not be changed. The buffer type and subtype of a response buffer must be the same as those of a *data buffer. |
TPNOBLOCK | Does not wait for a response, but returns a valid response if available. If a TPNOBLOCK flag is not set, and there is no available response, a caller will wait until a response is received or a timeout (transaction or block timeout) occurs. |
TPNOTIME | A caller must wait indefinitely until a response is received. Blocking timeouts are ignored and timeout will occur even if a tpgetrply() is called during a transaction timeout. |
TPSIGRSTRT | Allows signal interrupts. If a system function call is interrupted by a signal, it will be re-executed. If a signal interrupt occurs without this flag set, the function will fail and a tperrno will be set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. When a tpgetrply() returns successfully or a tperrno is [TPESVCFAIL], the global variable tpurcode returned by a tpreturn() will be set to a value defined in the application. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
If a tpgetrply() fails, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a cd, data, *data, or a len is NULL or a flags is invalid. If a cd is not NULL, it is valid even if an error occurs, and a function will continue to wait for a response. |
[TPEBADDESC] | An invalid cd. |
[TPEOTYPE] | A caller does not know the type or subtype of a response buffer. In this case, flags are set to TPNOCHANGE but the type or subtype of *data does not match that of the response buffer, so the data in *data and *len are not changed. If the caller received a response in a transaction mode, the transaction will be rolled back because the response will be ignored. |
[TPETIME] | A transaction timeout occurred when a caller is in a transaction mode, and the transaction is rolled back. If a caller is not in a transaction mode, a block timeout will occur if both a TPNOTIME and a TPNOBLOCK are not set. In such cases, the data in a *data and a *len are not changed. If a transaction timeout occurs, any new service requests and processes waiting for a response will fail due to a [TPETIME] error until the transaction is rolled back. |
[TPESVCFAIL] | A service routine sent a reply by calling a tpreturn() with a TPFAIL because an error occurred in an application program. Service reply data can be accessed through a *data. If a caller is in a transaction mode, the transaction will be rolled back. When a transaction timeout occurs, other communication may be attempted before a transaction is rolled back. For such attempts to be successful, a TPNOTRAN must be set. All operations performed while a caller is in a transaction mode are rolled back when the transaction is complete. |
[TPEBLOCK] | Blocking occurred while a TPNOBLOCK was set. A cd is valid. |
[TPGOTSIG] | A signal was received while a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpcall() was called in an invalid state. |
[TPETRAN] | A xa_start failed due to an error in the database while invoking a transaction service. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; long len; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process … cd = tpacall(“SERVICE”, buf, 0, TPNOFLAGS); if (cd==-1) { error procesing } data process.... ret=tpgetrply(&cd, &buf, &len, TPNOTIME); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpacall(), tpalloc(), tpreturn()
The tpgetsockname function returns the name of a current socket used internally by a Tmax system.
Prototype
#include <tmaxapi.h> int tpgetsockname (struct sockaddr *name, int *namelen)
Parameter
Parameter | Description |
---|---|
name | A struct that stores an address. In an IPv6 protocol environment, a sockaddr_in6 struct can be used to check address information, while a sockaddr_storage struct can be used in both IPv4 and IPv6 environments. |
namelen | Before a tpgetsockname is called, a namelen is initialized to the size of a struct allocated by a name. After a function returns a value, a namelen is set to the actual size of a struct. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetsockname() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
[TPEITYPE] | Occurs when the size of a name struct (namelen) is smaller than the actual size to be used. |
Example
#include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <usrinc/atmi.h> #inlcude <usrinc/tmaxapi.h> ... DELETE(TPSVCINFO *msg) { ... struct sockaddr_in cli; char ipAddr[16]; int cli_len, ret, i; ... memset((char *)&cli, 0, sizeof(cli)); ret = tpgetsockname((struct sockaddr *)&cli_saddr, &cli_len); if (ret == -1){ error processing } else{ memcpy(ipAddr, inet_ntoa(cli.sin_addr), 16); } printf(“ip = %s , port = %d\n”, ipAddr, cli.sin_port); ... }
Example - IPv6 protocol environment
#include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <usrinc/atmi.h> #inlcude <usrinc/tmaxapi.h> ... DELETE(TPSVCINFO *msg) { struct sockaddr_storage cli_saddr; struct sockaddr_in *cli_sin4; struct sockaddr_in6 *cli_sin6; char ipaddrbuf[INET6_ADDRSTRLEN]; const char *ipaddr = NULL; int cli_len, ret; int portno; data process... memset((char *)&cli_saddr, 0, sizeof(cli_saddr)); cli_len = sizeof(cli_saddr); ret = tpgetsockname((struct sockaddr *)&cli_saddr, &cli_len); if (ret == -1) { error processing } else { if (cli_saddr.ss_family == AF_INET) { cli_sin4 = (struct sockaddr_in *)&cli_saddr; ipaddr = inet_ntop(AF_INET, &(cli_sin4->sin_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin4->sin_port); } else if (cli_saddr.ss_family == AF_INET6) { cli_sin6 = (struct sockaddr_in *)&cli_saddr; ipaddr = inet_ntop(AF_INET6, &(cli_sin6->sin6_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin6->sin6_port); } if (ipaddr == NULL) ipaddr = "unknown"; } printf(“ip = %s , port = %d\n”, ipaddr, portno); ... }
Related Functions
tpgetpeer_ipaddr(), tpgetpeername(), tpstart()
The tpgetsprlist function retrieves the index of a server process that a svc belongs to. A tpgetsprlist is used to call a service as a server process unit and it retrieves a starti and an endi of a list of servers, that a service belongs to.
Prototype
#include <usrinc/tmaxapi.h> int tpgetsprlist(char *svc, int svgno, int *starti, int *endi, long flagsl);
Parameter
Parameter | Description |
---|---|
svc | A service to be called. |
svgno | The number of a server group that contains a service to be called. The server group number can be found using a tpgetsvglist() API or a cfg –g from a tmadmin. |
starti | The index number of the first process of a server that a service belongs to. |
endi | The index number of the last process of a server that a service belongs to. If a starti is 36 and an endi is 40, the serial number of a process will be from 36 to 40. If the MIN of a server is 5 and MAX is 10, 10 indexes will be retrieved when a tpgetsprlist() is called. |
flagsl | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. A starti and an endi can be retrieved. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetsprlist() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
[TPEBLOCK] | A blocking state occurred. |
Example
main(int argc, char *argv[]) { int ret; int starti = 0, endi = 0; if (argc != 2) { printf(“Usage: argv[1] string\n”); exit(1); if((ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ){ printf(“<%-15s> tmaxreadenv fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf(“<%-15s> tpstart fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } /* tpgetsprlist in client */ ret = tpgetsprlist(argv[1], 2, &starti, &endi, 0); if (ret < 0) { printf(“<%-15s> tpgetsprlist fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } else { printf(“Received Message : starti[%d], endi[%d]\n”, starti, endi); } tpend(); }
The tpgetsvglist function returns information about a server group that a service belongs to, or information about its cousin server group. A returned structure contains the number of server groups or the sequence number of a server group. This function can be used on both a client and a server.
Prototype
#include <tmaxapi.h> struct svglist* tpgetsvglist(char *svc, long flags)
Parameter
Parameter | Description |
---|---|
svc | The name of a requesting service |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
A positive integer | A function call was successful. The serial number of a server process will be returned as a positive integer. |
NULL | A function call failed. A tperrno is set to an error code. |
When an error occurs, a tpgetsvglist() will return a NULL and a tperrno will be set to an error code. Otherwise, a tpgetsvglist() will store a list of server groups that failed to be called into a svglist struct and will return a struct.
The following is the structure of a svglist struct:
struct svglist { int ns_entry; int nf_entry; int *s_list; int *f_list; };
Member | Description |
---|---|
ns_entry | The number of server groups a service belongs to. |
nf_entry | The number of server groups that failed to be called. |
s_list | A pointer to the serial numbers of server groups that were successfully called. nf_entry and f_list are used for different purposes. |
f_list | A pointer to the serial numbers of server groups that failed to be called. |
Error
When a tpgetsvglist() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
The tpgprio function gets the priorty of a service request. A client side tpgprio() returns the priority of a last sent request. A server side tpgprio() returns the priority of a last request received. This function can be used on both a client and a server.
A tpgprio() may be called after a tpcall(), and the priority returned will be for a sent request. Also, a tpgprio() may be called within a service routine to check the priority of a requested service. Priority indicates a service precedence of a request message. A priority value can range from 0 to 100. The default value for each service is 50. By using tpsprio() and tpgprio() functions, a user can control the service priority of request messages.
Prototype
#include <tuxfatmi.h> int tpgprio (void)
Return Value
Value | Description |
---|---|
Priority | A function call was successful and a tpgprio() returned the priority of a request. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgprio() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A tpgprio() was called and no requests were sent, or a tpgprio() was called within a conversational service for which no requests were sent. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int ret, prio; prio = tpgprio(); if (prio==-1) { error processing } if (prio > 50) tpforward(“SERVICE1”, msg->data, msg->len, 0); else tpforward(“SERVICE2”, msg->data, msg->len, 0); }
Related Functions
tpacall(), tpcall(), tpsprio()
In a Tmax environment that contains server groups that belong to a COUSIN server group, a tpcall() function calls the services that belong to a single server group through Tmax routing. The tpmcall() function, however, calls the services of all server groups that belong to a single cousin server group. Therefore, a client performs a multicast in a tpmcall service routine.
Calling a tpmcall() is similar to calling a tpacall(…, TPNORPLY) to server groups that belong to a cousin, because a tpmcall() function does not participate in transactions.
Prototype
#include <tmaxapi.h> struct svglist *tpmcall(char *qname, char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
qname | If a qname is set, a tpmcall() requests a service through a RQ. Currently, a qname is not supported in this version of Tmax. |
svc, data, len | Identical to parameters used in a tpcall(). |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
When an error occurs, a tpmcall() will return a NULL and a tperrno will be set to an error code. Otherwise, a list of server groups that failed to be called will be returned in a svglist struct.
The following will be returned:
struct svglist { int ns_entry; int nf_entry; int *s_list; int *f_list; };
Member | Description |
---|---|
ns_entry | The number of server groups successfully called. |
nf_entry | The number of server groups that failed to be called. |
s_list | A pointer to the serial numbers of server groups successfully called. nf_entry and f_list are used for different purposes. nf_entry is set to 0, and f_list is set to NULL. |
f_list | A pointer to the serial numbers of server groups that failed to be called. |
Error
When a tpmcall() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by tpalloc(), or a flag is invalid. |
[TPENOENT] | A specified qname is not registered in Tmax. |
[TPEITYPE] | A svc does not support a data type or subtype. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
Example
#include <stdio.h> #include <usrinc/atmi.h> main(int argc, char *argv[]) { char *sndbuf; int ret; … ret = tpstart((TPSTART_T *)NULL); if (ret == -1){ error processing } sndbuf = (char *)tpalloc(“STRING”, NULL, 0); if (sndbuf == NULL){ error processing } ret = tpmcall(NULL, “TPMCALL”, sndbuf, 0, TPNOFLAGS); if (ret == NULL){ error processing } … }
Related Functions
tpcall(), tpgetsvglist(), tpmcallx()
The tpmcallx function is an API developed to support the extended features of a tpmcall(). Unlike existing functions, it waits until replies from all services of a COUSIN server group are received. In addition, a r_list has been added to a svglist structure, which stores responses concerning successes and failures. As well, several flags have been added.
Prototype
#include <usrinc/tmaxapi.h> struct svglistx* tpmcallx(char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
svc | The name of a service to be called. It must be provided by a Tmax application server program. |
data | A pointer to a buffer allocated by a tpalloc(). A buffer type and subtype must be supported by a svc. |
len | The length of data to be sent.
If data is NULL, len will be ignored. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOREPLY | Performs only a sending process. If this flag is set, a function operates similarly to a tpmcall(). |
TPBLOCK | Checks whether data was successfully sent to a CLH. |
TPNOTIME | If this flag is set, a function caller will wait indefinitely until a reply is received, ignoring a blocking timeout. |
Return Value
When an error occurs, a tpmcallx() will return a NULL and a tperrno will be set to an error code. Otherwise, a list of server groups that failed to be called will be returned in a svglist struct.
The following will be returned:
struct svglistx { int ns_entry; /* number of entries of s_list */ int nf_entry; /* number of entries of f_list */ int nr_entry; /* number of entries of r_list */ int *s_list; /* list of server group numbers */ int *f_list; /* list of tperrno of each server group */ int *r_list; /* list of tpurcode of each server group */ };
Member | Description |
---|---|
ns_entry | The number of server groups successfully called. |
nf_entry | The number of server groups that failed to be called. |
nr_entry | The number of server groups where a r_list was specified. |
s_list | A pointer to the serial numbers of server groups successfully called. |
f_list | A pointer to the serial numbers of server groups that failed to be called. |
r_list | A pointer to the serial numbers of server groups in which a tpurcode is specified. |
Error
When a tpmcallx() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A specified qname is not registered in Tmax. |
[TPEITYPE] | A svc does not support a data type or subtype. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
Example
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen, sndlen; struct svglistx svglist; struct svglistx *psvglist; int ret, i; psvglist = &svglist; if (argc != 2) { printf("Usage: toupper string\n"); exit(1); } if ( (ret = tmaxreadenv( "tmax.env","TMAX" )) == -1 ){ printf( "tmax read env failed\n" ); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf("tpstart failed[%s]\n",tpstrerror(tperrno)); exit(1); } if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("sendbuf alloc failed !\n"); tpend(); exit(1); } if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("recvbuf alloc failed !\n"); tpfree((char *)sndbuf); tpend(); exit(1); } strcpy(sndbuf, argv[1]); psvglist = tpmcallx("TOUPPER", sndbuf, 0, TPBLOCK); if(psvglist == NULL) { printf("tpmcall is failed[%s]\n", tpstrerror(tperrno)); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } printf("send data: %s\n", sndbuf); printf("ns_entry = %d\n", psvglist->ns_entry); printf("nf_entry = %d\n", psvglist->nf_entry); printf("nr_entry = %d\n", psvglist->nr_entry); for(i=0; i<psvglist->ns_entry; i++) printf("psvglist->s_list[%d] = %d\n", i, psvglist->s_list[i]); for(i=0; i<psvglist->nf_entry; i++) printf("psvglist->f_list[%d] = %d\n", i, psvglist->f_list[i]); for(i=0; i<psvglist->nr_entry; i++) printf("psvglist->r_list[%d] = %d\n", i, psvglist->r_list[i]); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Functions
tpcall(), tpgetsvglist(), tpmcall()
The tpnotify function sends an unsolicited message to a specified client from a server.
Prototype
#include <atmi.h> int tpnotify(CLIENTID *id, char *data, long len, long flags);
Parameter
Parameter | Description |
---|---|
id | A pointer to a client ID saved in a TPSVCINFO struct. |
data | A buffer must be allocated by a tpalloc() for a caller to deliver data. |
len | The length of data to be sent.
If data is NULL, len will be ignored. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPACK | A buffer must be allocated by a tpalloc(). |
TPNOBLOCK | Does not wait for a response. If a reply is received, a calling service will return it. If a TPNOBLOCK is not set, and there is no receivable response, a function caller will wait until a response is received. |
TPNOTIME | A function caller waits indefinitely until a response is received. Blocking timeouts are ignored. However, if a WinTmaxSend() is called within a transaction period, a timeout will be applied. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpnotify() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPENOENT] | A specified client does not exist or an unsolicited message handler is not configured. |
[TPETIME] | A timeout occurred when a calling service was in a transaction mode and the transaction was rolled back. If neither a TPNOTIME nor a TPNOBLOCK are set in a non-transaction mode, an error will occur. |
[TPEPROTO] | A tpnotify() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include “../fdl/demo_fdl.h” TOUPPER(TPSVCINFO* msg) { int i, n; char rdata[100]; FBUF *stdata; stdata=(FBUF *)msg->data; memset(rdata, 0x00, sizeof(rdata)); if (fbget(stdata, INPUT, rdata, 0) == -1){ printf(“fbget failed errno = %d\n”, fberror); } for (i = 0; i < msg->len; i++) { rdata[i] = toupper(rdata[i]); } if (fbput(stdata, OUTPUT, rdata, 0) == -1) printf(“fbput failed\n”); i = tpnotify(&(msg->cltid), (char*)stdata, 0, TPACK); printf(“i= %d\n”, i); tpreturn(TPSUCCESS, 0, (char *)stdata, 0, 0); }
The tppost function generates a specific event from a server or client and delivers a message. A tppost() notifies the occurence of an event to all clients and server processes that registered for the event by using the eventname in a tpsubscribe(). If required, a message can be delivered.
Prototype
# include <tmaxapi.h> int tppost(char *eventname, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
eventname | A string that ends with a NULL, and has up to a 15-character length. Wildcard or partial-matching is not supported. |
data | A pointer to a buffer for messages to be sent. Must be a buffer allocated by a tpalloc(). |
len | The length of a buffer to be sent. If data indicates a buffer that does not require a data length to be provided, a len will be ignored (0 is used by default). If data indicates a buffer that requires a data length, a len must not be 0. If data is NULL, a len will be ignored. |
flags | Currently, only a TPNOTIME can be used. |
Return Values
Value | Description |
---|---|
Positive Value | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tppost() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. For a client program, a network error is the most common error. |
[TPEOS] | An operating system error occurred. |
[TPEINVAL] | An invalid parameter. |
[TPENOENT] | When using a tpsubscribe(), this error indicates that a RQ, a server corresponding to a qname, or a svc of a TPEVCTL structure does not exist. |
[TPEPROTO] | When a tpsubscribe() is executed in a client, a ctl is not NULL. When a tpsubscribe() is executed in a server, a ctl is NULL. |
[TPETIME] | A timeout occurred. |
Related Functions
tpsetunsol(), tpsetunsol_flag(), tpgetunsol(), tpacall(), tpenq()
The tpputenv function applies a 'name= value' entered as a string to an environment variable. It modifies an existing environment variable if there are any, or adds a new environment variable if there is no environment variable.
This function is identical to a putenv() executable on a server side, and it is available both in a client and in a server. In a client, it modifies a value applied to an autoexec.bat file or adds a new one and in a server, it modifies a value applied to each shell configuration file or adds a new one if there is no existing value.
Prototype
#include <tmaxapi.h> int tpputenv(char *string)
Parameter
Parameter | Description |
---|---|
string | A value to be set in an environment variable. ("name=value") |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
A negative integer | A function call failed if an environment variable secured an insufficient amount of memory. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *SDLFI; SDLFI=tpgetenv(“SDLFILE”); if (SDLFI=NULL) ret=tpputenv(“SDLFILE=/tmax/sample/sdl/test.sdl”); if (ret<0) { error processing } SDLFI=tpgetenv(“SDLFILE”); printf (“tmax sdlfile : %s\n”,SDLFI); }
Related Function
tpgetenv()
The tpqstat function is used to get the data statistics accumulated in a current RQ. This function is available both in a server and a client. A RQ internally consists of three queues: a _fail queue, a _request queue, and a _ reply queue. A tpqstat( ) can get the data statistics stored in each of these queues, by using a flag value.
Prototype
# include <tmaxapi.h> int tpqstat (char *qname, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
flags | A target data type. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
0(TMAX_ANY_QUEUE) | Retrieves the statistics about all data stored in a _fail queue, _request queue, and _reply queue. |
1(TMAX_FAIL_QUEUE) | Retrieves the data statistics stored in a _fail queue. |
2(TMAX_REQ_QUEUE) | Retrieves the data statistics stored in a _request queue. |
3(TMAX_RPLY_QUEUE) | Retrieves the data statistics stored in a _reply queue. |
Return Values
Value | Description |
---|---|
-1 | A function call was successful. A tperrno is set to an error code. |
Error
When a tpqstat() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, when a qname is NULL, there will be no queue with a corresponding name, or a flag will be invalid. |
[TPEPROTO] | A tpqstat() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret, i; char *buf; if (argc!=2) { error processing } ret=tpstart((TPSTART_T *)NULL); if (ret==-1) {error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } strcpy(buf, argv[1]); data process… ret=tpenq(“RQ”, NULL, (char *)buf, strlen(buf), TPRQS); if (ret==-1) {error processing } printf(“qstat :”); for (i=0;i<4;i++) { ret=tpqstat(“rq”, i); if (ret==-1) {error processing } printf(“ %d”,ret); /* qstat : 1 0 0 1 */ } printf(“\n”); data process… ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) {error processing } printf(”qstat :”); for (i=0;i<4;i++) { ret=tpqstat(“rq”, i); if (ret==-1) {error processing } printf(” %d”,ret); /* qstat : 2 0 0 2 */ } printf(“\n”); tpfree((char *)buf); tpend(); }
Related Functions
tpenq(), tpdeq()
The tpqsvcstat function returns the data statistics for a specific service stored in a current queue. This function is available both in a server and a client. A RQ internally consists of three queues - a _fail queue, a _request queue, and a _ reply queue. A tpqstat( ) can get data statistics stored in each of these queues through a flag value.
A qname indicates the name of a RQ and a svc should be set to the name of a desired service. If a svc is set to NULL, a routine will be the same as a tpqstat().
Prototype
# include <tmaxapi.h> int tpqsvcstat (char *qname, char * svc, long flags )
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | Should be set to the name of a desired service. If a svc is set to NULL, a routine will be same as a tpqstat(). |
flags | A data statistic type. |
The following are possible flag values:
Flag | Description |
---|---|
0(TMAX_ANY_QUEUE) | Retrieves the statistics about all data stored in a _fail queue, _request queue, and _reply queue. |
1(TMAX_FAIL_QUEUE) | Retrieves the data statistics stored in a _fail queue. |
2(TMAX_REQ_QUEUE) | Retrieves the data statistics stored in a _request queue. |
3(TMAX_RPLY_QUEUE) | Retrieves the data statistics stored in a _reply queue. |
Return Value
Value | Description |
---|---|
A value other than -1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpqscvstat() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, when a qname is NULL, there will be no queue with a corresponding name, or a flag is invalid. |
[TPEPROTO] | A tpqsvcstat() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Related Functions
tpenq(), tpdeq(), tpqstat()
The tprealloc function reallocates a buffer pointed to by a ptr in bytes, and returns a pointer for a new buffer (when a buffer is changed).
Like a tpalloc(), a buffer size must be larger than the default size (1024 bytes). A buffer type is kept the same even after it is reallocated. When a function successfully returns a pointer, the returned pointer is used to refer to a reallocated buffer. At this time, a ptr cannot be used any more. If a reallocated buffer size is smaller than a previous buffer size, the original ptr content can not be ensured.
Some buffer types need to be initialized to be used. A tprealloc() re-initializes a re-allocated buffer and then returns it. Therefore, a buffer returned to a caller can be used immediately. If it fails to reinitialize a buffer, a tprealloc() will returns a NULL and data in a buffer pointed by a ptr will not be valid.
Prototype
# include <atmi.h> char * tprealloc (char *ptr, long size)
Parameter
Parameter | Description |
---|---|
ptr | A pointer to a buffer to be allocated. |
size | The size of a buffer to be allocated. |
Return Values
Value | Description |
---|---|
Buffer Pointer | A function call was successful and a proper buffer pointer is returned. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tprealloc() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a buffer pointed by a ptr is not the one allocated by a tpalloc(). |
[TPEPROTO] | A tprealloc() was called from an invalid state. |
[TPENOENT] | A buffer pointed to by a ptr was not allocated by a tpalloc(). |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *buf; buf=tpalloc(“STRING”,NULL,10); if (buf==NULL) { error processing } buf=tprealloc(buf,20); /* ok */ if (buf==NULL) { error processing } buf=”test”; buf=tprealloc(buf,30); /*error : TPEINVAL */ if (buf==NULL) { error processing } }
Related Functions
tpalloc(), tpfree(), tptypes()
This function cannot be used together with a malloc(), realloc(), or free() from a C library. For example, it is impossible to free a buffer allocated by a tprealloc() using a free().
Available in a server and a client. The tprecv function receives messages in an interactive communication. This is used to receive data sent from a partner in an interactive communication. A tprecv() can be used only by a program (on a server or a client) which does not have communication control.
Prototype
# include <atmi.h> int tprecv (int cd, char **data, long *len, long flags, long *revent)
Parameter
Parameter | Description |
---|---|
cd | Sets a connection to receive data. It is a descriptor returned by a tpconnect() or a TPSVCINFO parameter. |
data | Pointer to a buffer allocated by a tpalloc(). If a function successfully returns, a *data will point to received data. |
len | The length of data to be sent. If the value of a len is bigger than the total size of a buffer before calling it, the size of the buffer will be set to the value of len. If the value of a len is 0, no data will be received and neither *data nor a buffer, which a *data points to, will be changed. |
flags | Flag values are listed in the table below. |
revent | The event types returned to a revent are explained in the following table. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOCHANGE | If a received response buffer and a buffer type that a *data points to are not the same, the buffer type of a *data will be changed to a received response buffer type in a scope that a receiver can recognize. If a TPNOCHANGE flag is set, the buffer type that a *data points to will not be changed. A received response buffer type and subtype must be the same with those of the buffer that a *data points to. |
TPNOBLOCK | Does not wait for data. If there is receivable data the data will be returned. If a TPNOBLOCK flag is not set, and there is no receivable data, a caller will wait for data to arrived. |
TPNOTIME | A function caller waits infinitely until a response is received, and ignores block timeouts. If a tprecv() is used within a transaction timeout, a transaction time will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to TPGOTSIG. |
The following describes event types that are returned to a revent:
Event Type | Description |
---|---|
TPEV_DISCONIMM | A communication starter used a tpdiscon() to forcefully terminate a connection. This event is received by a communication subordinate. This event is also returned when a connection is terminated due to a communication error such as a server, node, or network error. Any data being sent may be lost. If two programs participate in the same transaction, the transaction will be rolled back. a cd used by an interactive communication will not be valid. |
TPEV_SENDONLY | A connected partner program gave up on a communication control. A TPEV_SENDONLY event receiver can send data but cannot receive any data until a receiver returns a control. |
TPEV_SVCERR | This event notifies a communication starter of an error that occurred while a communication subordinator executes a tpreturn(). The error can occur if an invalid parameter is passed to a tpreturn(), or a tpreturn() is called while a service maintains a connection to another subordinator. In these cases, a return code or a part of data cannot be used. An interactive connection will be terminated a cd will not be valid. If this event occurs during a receiver's transaction, the transaction will be rolled back. |
TPEV_SVCFAIL | This event notifies a communication starter of information that a service of a communication subordinator was terminated due to a failure. A tpreturn() was called using a TPFAIL as an argument. If a communication subordinator service has a communication control when calling a tpreturn(), a service cannot send data to a connected partner. A server process terminates an interactive connection when a service is terminated. Therefore, a cd will not be valid anymore. If this event occurs to a receiver transaction process, the transaction will be rolled back. |
TPEV_SVCSUCC | This event, which a communication starter receives, notifies that a communication subordinator service was terminated successfully. This event notifies a communication starter that a service of a communication subordinator was terminated successfully. A tpreturn() was called using a TPSUCCESS as an argument. |
Return Value
If the value of a revent is TREV_SVCSUCC or TREV_SVCFAIL, a tpurcode global variable that is delivered by a tpreturn() will be defined by an application. Otherwise, a -1 will be returned and a tperrno will be set to the value corresponding to a state. If an event has no error, a tprecv() will return a -1 and a tperrno will be set to [TPEEVENT].
Error
When a tprecv() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid cd. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPEEVENT] | An event occurred. Use a revent to find the event type. |
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, a *data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPEOS] | An operating system error occurred. |
[TPEOTYPE] | The type or subtype of an entered buffer is unknown to a caller, or a TPNOCHANGE flag was set but the type or subtype of a buffer pointed to by a *data did not match the type or subtype of an entered buffer. In this case, both the contents of a *data and a *len are not changed. If interactive communication is a part of a transaction, the transaction will be rolled back because a reply will be ignored. If an error occurred, the event for a cd will be ignored and an interactive communication state cannot be guaranteed. Therefore a caller must terminate an interactive communication. |
[TPEPROTO] | A tprecv() was called from an invalid state. For example, a tprecv() was called in a sender mode. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK are set. In these cases, a *data content and a *len are not changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPGOTSIG] | A signal was received when a TPSIGRSTRT was not set. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” main(int argc,char* argv[]) { int ret, cd; struct dat *buf; long revent, len; if (argc!=3) {error processing } ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct dat *)tpalloc(“STRUCT”, “dat”, 0); if (buf==NULL) { error processing } strcpy(buf->sdata, argv[1]); data process…. cd=tpconnect(“SERVICE”, buf, 0, TPSENDONLY); if (cd==-1) { error processing } strcpy(buf->sdata, argv[2]); data process…. ret=tpsend(cd, buf, 0,TPRECVONLY,&revent); if (ret==-1) { error processing } ret=tprecv(cd,(char**)&buf,&len,TPNOTIME,&revent); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpconnect(), tpdiscon(), tpsend()
The tpreissue function reissues a request in the fail queue of a RQ. This function is available for both a client and a server.
If a service fails due to network failure or error occurrences in a server program while carrying out RQ based services through a tpenq(), a service request will be accumulated in a fail queue. A tpreissue() function enables a failed service request to queue in a request queue again. After it is requeued, data in a request queue will be sent to an appropriate service and the results will be returned to a reply queue.
Prototype
#include <tmaxapi.h> int tpreissue(char *qname, char *filter, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
filter | Not currently available. All values are set to NULL |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpreissue() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, when a qname is set to NULL or a value has been set to filter or flag. |
[TPENOENT] | A RQ that corresponds to a qname does not exist. |
[TPESYSTEM] | A Tmax system error occurred due to a network failure. Detailed error information is recorded in a system log file. |
Related Functions
tpenq(), tpdeq()
The tpscmt function changes the settings of a commit in a configuration file. This function is available both in a server and a client.
Prototype
# include <tuxatmi.h> int tpscmt(long flags)
Parameter
Parameter | Description |
---|---|
flags | Input options:
|
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. |
Example
#include <stdio.h> #include <usrinc/tuxatmi.h> int main(int argc, char *argv[]) { ... ret = tpstart((TPSTART_T *)NULL); if (ret == -1) { error processing } ... ret = tpscmt(TP_CMT_COMPLETED); if (ret < 0){ error processing } ret = tpbegin(); if (ret < 0){ error processing } ... ret= tpcall(“SERVICE1”,(char*)buf, strlen(buf),(char **)&get,&rlen,TPNOFLAGS); if (ret == -1) { error processing } ... ret= tpcall(“SERVICE2",(char*)buf,strlen(buf),(char **)&get,&rlen,TPNOFLAGS); if (ret == -1) { error processing } ret = tpcommit(); if (ret < 0) { error processing } ... }
Available in a server and a client. The tpsend function sends data to a partner program in an interactive communication. A caller must have communication control.
Prototype
# include <atmi.h> int tpsend (int cd, char *data, long len, long flags, long *revent)
Parameter
Parameter | Description |
---|---|
cd | Sets a connection to receive data. It is a descriptor returned by a tpconnect() or a TPSVCINFO parameter. |
data | A buffer allocated by a tpalloc(). If no application data is received (for example, only a communication control was passed without any data), data can be NULL. The data type and subtype must be recognizable by a connected partner. |
len | A buffer length to receive. If data points to a buffer that does not need to be specified, a len will be ignored and 0 will be used. If data points to a buffer which must be specified, a len cannot be 0. |
flags | Flag values are listed in the table below. |
revent | If an event exists for a descriptor cd, a tpsend() will fail and data will not be received. The event type will be returned as a revent. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOBLOCK | If a blocking situation occurs, for example if an internal buffer is filled with messages to be sent, data and events will not be sent. If a tpsend() is called without setting a TPNOBLOCK flag or if a blocking state occurs, a caller will wait until either a transaction or a block timeout occurs or a state is resolved. |
TPNOTIME | A function caller waits for a response and infinitely ignores a block timeout. If a tpsend() is used within a transaction timeout, the transaction time will still apply. |
TPRECVONLY | A caller sends a communication control to a partner after receiving data. A caller cannot call a tpsend() until it receives a communication control again. A communication partner will receive a TPEV_SENDONLY event, which means a communication control will be received when receiving data using a tprecv(). A receiver cannot call a tprecv() until receiving a communication control from a partner. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to TPGOTSIG. |
The events that can be delivered to revent are as follows:
Event Type | Description |
---|---|
TPEV_DISCONIMM | A communication starter used a tpdiscon() to forcefully terminate a connection. This event is received by a communication subordinate and is returned when a connection is terminated due to a communication error such as server, node, or network error. |
TREV_SVCERR | This event is received by a communication starter and notifies that a communication subordinator performed a tpreturn() without a communication control being in a TPEV_SVCFAIL state. |
TREV_SVCFAIL | This event is received by a communication starter and notifies that a communication subordinator performed a tpreturn() without a communication control, and that a tpreturn() was called as a TPFAIL without data and that it was performed as a TPFAIL rval and had data with a NULL value. |
Return Value
If a revent is a TREV_SVCFAIL, a tpurcode global variable is set to a rcode value, which is delivered when calling a tpreturn().
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsend() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPEBADDESC] | An invalid cd. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEEVENT] | An event occurred. If an error occurs, data will not be sent and an event type will be returned as a revent. |
[TPEBLOCK] | A blocking state occured when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpsend() was called from an invalid state. For example, a tpsend() was called in a receiver mode. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” main(int argc, char* argv[]) { int ret, cd; struct dat *buf; long revent, len; if (argc!=3) {error processing } ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct dat *)tpalloc(“STRUCT”, “dat”, 0); if (buf==NULL) { error processing } strcpy(buf->sdata, argv[1]); data process…. cd=tpconnect(“SERVICE”, buf, 0, TPSENDONLY); if (cd==-1) { error processing } strcpy(buf->sdata, argv[2]); data process…. ret=tpsend(cd, buf, 0,TPRECVONLY,&revent); if (ret==-1) { error processing } ret=tprecv(&cd,(char**)&buf,&len,TPNOTIME,&revent); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpconnect(), tpdiscon(), tprecv(), tpreturn()
Available in a server. The tpsetsvctimeout function sets a service timeout in a server. If a service time is set using a tpsetsvctimeout(), a service request will wait for a response during the time set by this function. If a response was not received during the set time, a timeout error will occur and a service request will be returned as a service failure without waiting for a response.
Prototype
#include <tmaxapi.h> int tpsetsvctimeout (int sec, long flags)
Parameter
Parameter | Description |
---|---|
sec | Sets a service timeout in seconds. |
flags | Not currently supported. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsetsvctimeout() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <stdlib.h> #include <usrinc/tmaxapi.h> #include <usrinc/tdlcall.h> TOUPPER(TPSVCINFO *msg) { int i; if ( tpsetsvctimeout(10, 0) < 0 ) ; //error handle code printf("TOUPPER service is started!\n"); sleep(15); printf("INPUT : data=%s\n", msg->data); for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); printf("OUTPUT: data=%s\n", msg->data); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); }
Available in a server and a client. The tpset_timeout function sets a block timeout, a service limited time set in a server. If a timeout is set using a tpset_timeout(), the response for a service request will wait during the specified amount of time. If a response is not received during the specified amount of time, a timeout error will occur and the service request will be returned as a failure without waiting for a response.
A tpset_timeout() applies to service requests that were received after this function was called. The function is valid until a tpset_timeout() is called again, or a client or server process is terminated. If a tpset_timeout() is not used, a BLOCKTIME set in a Tmax configuration file will be used as a block timeout.
Prototype
#include <tmaxapi.h> int tpset_timeout (int sec)
Parameter
Parameter | Description |
---|---|
sec | Sets a block time in seconds. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpset_timeout() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *sndbuf, *rcvbuf; long sndlen, rcvlen; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } sndbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (sndbuf==NULL) {error processing }; rcvbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (rcvbuf==NULL) {error processing }; data process.... sndbuf=strlen(sndbuf); ret=tpset_timeout(4); if (ret==-1) { error processing } ret=tpcall(“SERVICE”, sndbuf, sndlen, &rcvbuf, &rcvlen, TPNOCHANGE); if (ret==-1) { error processing } data process.... tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
The tpsetfd function registers a socket fd in an external socket scheduler of a UCS process. This is used to turn on a socket fd, which uses a UCS type process. A UCS scheduler tests a message received in a socket fd as well as messages received in a TMM and a CLH. If a message is received in a user defined socket, a tpschedule() will return a normal result (UCS_USER_MSG) without a separate process. To know in which socket a message has been received, a tpistfd() must be used.
Prototype
#include <ucs.h> int tpsetfd (int fd)
Parameter
Parameter | Description |
---|---|
fd | Sets a socket fd to be registered. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsetfd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in the system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <usrinc/ucs.h> ... #define SERV_ADDR “168.126.185.129” #define SERV_PORT 1500 int fd_read(int, char *, int); extern int errno; int usermain(int argc, char *argv[]) { ... int listen_fd, n, newfd; struct sockaddr_in my_addr, child_addr; socklen_t child_len; buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ error processing } memset((void *)&my_addr, NULL, sizeof(my_addr)); memset((void *)&child_addr, NULL, sizeof(child_addr)); listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd == -1){ error processing } my_addr.sin_family = AF_INET; inaddr = inet_addr(SERV_ADDR); my_addr.sin_port = htons((unsigned short)SERV_PORT); if (inaddr != -1){ memcpy((char *)&my_addr.sin_addr, (char *)&inaddr, sizeof(inaddr)); } ret = bind(listen_fd, (struct sockaddr *)&my_addr, sizeof(my_addr)); if (ret == -1){ error processing } ret = listen(listen_fd, 5); if (ret == -1){ error processing } ret = tpsetfd(listen_fd); if (ret == -1){ error processing } ... while(1) { n = tpschedule(10); ... if (n == UCS_USER_MSG){ if (tpissetfd(listen_fd)) { child_len = sizeof(child_addr); newfd = accept(listen_fd, &child_addr, &child_len); if (newfd == -1){ error processing } ret = tpsetfd(newfd); if (ret == -1){ error processing } } if (tpissetfd(newfd)){ /* Reads a buffer from a socket */ fd_read(newfd, buf, 1024); ret = tpcall(“SERVICE”, (char *)buf, sizeof(buf), (char **)&buf, (long *)&rlen, TPNOFLAGS); if (ret == -1){ error processing } ... tpclrfd(newfd); close(newfd); } ... } return 1; }
Related Functions
tpclrfd(), tpissetfd()
The tpsleep function sleeps for a maximum time for a timeout and returns immediately when data arrives within that time. This function is available both in a server and a client.
Prototype
#include <tmaxapi.h> int tpsleep (struct timeval *timeout)
Parameter
A timeout is a pointer for a struct named timeval, which is composed as follows (See the <sys/time.h> file of a UNIX system).
struct timeval{ long tv_sec /* seconds unit */ long tv_usec /* 0.000001 (micro seconds) unit */ };
Return Value
Value | Description |
---|---|
Positive Value | Returned if data does not arrive by a set timeout time. |
0 | Returned if data arrives. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsleep() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret, cd; char *buf; struct timeval sl_time, *sleep; sl_time.tv_sec =3; sl_time.tv_usec=500000; sleep=&sl_time; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... cd=tpacall(“SERVICE”, buf, 20, TPNOFLAGS); if (cd==-1) { error processing } ret=tpsleep(sleep); /* 3.5초간 대기 */ if (ret==-1) { error processing } if (ret==0) printf(“waited 3.5sec\n”); ret=tpgetrply(&cd, &buf, &len, TPNOTIME); if (ret==-1) { error processing } data process.... tpfree((char *)buf); tpend(); }
Related Functions
tp_sleep(), tp_usleep(), tpacall(), tpbroadcast(), tpgetrply()
The tpspracall function calls a service for a specific server process that has a certain index among indexes which are obtained through a tpgetsprlist(). This function sends a message through asynchronous communication and immediately returns a reply without waiting for a result. A result can be received with a tpgetrply() or canceled with a tpcancel().
Prototype
#include <usrinc/tmaxapi.h> int tpspracall(char *svcname, int spri, char *data, long lenl, long flagsl);
Parameter
Parameter | Description |
---|---|
svcname | A service where data will be sent. |
spri | A process number where data will be sent. |
data | A pointer to the data of a service request, which should be a buffer previously allocated with a tpalloc( ) . The type and subtype of idata must be one of those supported by a svc. |
lenl | The length of data to send. |
flagsl | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpspracall() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A server process with a specified index number does not exist. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
.... main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long sndlen, rcvlen; int ret, cd; int starti = 0, endi = 0, spri = 0; if (argc != 2) { printf(“Usage: argv[1] string\n”); exit(1); } if ( (ret = tmaxreadenv( “tmax.env”,”TMAX” )) == -1 ){ printf(“<%-15s> tmaxreadenv fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf(“<%-15s> tpstart fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } if ((sndbuf = (char*)tpalloc(“CARRAY”, 0, 0)) == NULL) { printf(“<%-15s> sndbuf tpalloc fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } if ((rcvbuf = (char*)tpalloc(“CARRAY”, 0, 0)) == NULL) { printf(“<%-15s> sndbuf tpalloc fail [%s]”, __FILE__, tpstrerror(tperrno)); tpfree((char*)sndbuf); exit(1); } /* tpgetsprlist in client */ ret = tpgetsprlist(argv[1], 2, &starti, &endi, 0); if (ret < 0) { printf(“<%-15s> tpgetsprlist fail [%s]”, __FILE__, tpstrerror(tperrno) ); exit(1); } else { /*printf(“Received Message from Server : starti[%d], endi[%d]\n”, starti, endi);*/ } strcpy((char*)sndbuf, “tpspracall test”); /* tpspracall in client */ for(spri = starti; spri <= endi; spri++) { cd = tpspracall(argv[1], spri, sndbuf, strlen(sndbuf), 0); if(cd < 0) { printf(“<%-15s> tpsprcall fail [%s]”, __FILE__, tpstrerror(tperrno)); exit(1); } else { ret = tpgetrply(&cd, &rcvbuf, &rcvlen, 0); if(ret < 0) { printf(“Received Message from %d spri: tpgetrply fail[%s]\n”, spri, tpstrerror(tperrno)); } else { printf(“Received Message from %d spri: msg[%s], len[%d]\n”, spri, rcvbuf, rcvlen); } } } tpend(); }
The tpsprio function sets the priority for a following tpacall() to send. This function is available for both servers and clients. A set priority affects only a following sent request. Priority is a value which indicates the service precedence of a request message. It can vary from 0 to 100. The default value for each service is 50.
Using the tpsprio() and tpgprio() functions, a user can control the service priority for request messages.
Prototype
#include <tuxatmi.h> int tpsprio (int prio, long flags)
Parameter
Parameter | Description |
---|---|
prio | Any integer value between -50 and +50. A prio value plus a current priority will be the value that will be used for a following request. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsprio() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) {error processing }; ret=tpsprio(30,0); if (ret==-1) { error processing } ret=tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process.... ret=tpsprio(-20,0); if (ret==-1) { error processing } ret=tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpacall(), tpcall(), tpgprio()
The tpsetctxt function sets a current context. The way the function is used differs in a client program and a server program as follows:
Client Program
A client can assign a different previously created context to a current client using a function. Most ATMI functions are based on per-context. To know the current context of a client, the return value of a tpgetctxt() can be checked.
A client can use multiple contexts, but only one context is used at a time. For example, if a tpacall() is called in context1, tpgetrply() must be called in context1 even though another context has been used.
Server Program
A service thread processes a service by getting a context, but a user created thread does not have its own context. Most ATMI functions can work after getting a context. Therefore a user created thread must share a context with a service thread if required. A user created thread can share a context with other service threads by using a tpsetctxt().
A user created thread that calls a tpsetctxt() shares context information with a service thread. For example, if a service thread calls a tpacall(), after that it is possible for a user created thread to receive a response for a request through a tpgetrply().
A tpsetctxt() cannot be used in a service thread. A service thread has its own context by default, and cannot replace the context with other one. Therefore, if a service thread calls a tpsetctxt(), an error will be returned with a TPEPROTO error code.
If a user created thread shares a context with a service thread through this function, the user created thread must call a tpsetctxt (TPNULLCONTEXT) before the service thread calls a tpreturn(). In other words, at the time that the service thread calls tpreturn(), the context of the service thread must be changed not to be shared by other user created threads. If this is not kept, tpreturn() will fail and aTPESVCERR error code will be returned to the client. Therefore, the process flow between threads must be controlled through synchronization. The ctxtid parameter of a tpsetctxt() uses the Context-ID which that is retrieved by calling a tpgetctxt() from a service thread.
With consideration of the different ways how a function is written depending on the program, the basic information of a tpsetctxt() is as follows:
Prototype
#include <usrinc/atmi.h> int tpsetctxt(int ctxtid, long flags)
Parameter
Parameter | Description |
---|---|
ctxtid | Sets a current context at the time point of a function call. In a client program, new context IDs created using a tpstart() can be used. In a server program, the Context-ID of a service thread can be used. Other contexts such as a TPNULLCONTEXT can be used but not a TPINVALIDCONTEXT. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsetctxt() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A function was called from an invalid state. For example, a service thread called a function or a Context ID was delivered as a parameter that was invalid in a server program. |
[TPEINVAL] | An invalid parameter. A ctxid is set to 0 or TPINVALIDCONTEXT, or flags are set to non-zero. In a client program, a tpsetctxt() is called before the program calls a tpstart(). A buffer flag is not set to TPMULTICONTEXTS when this function is called before the tpstart() is called. This error occurs when a context ID is set to TPINVALIDCONTEXT or 0. |
[TPENOENT] | A ctxtid value is not a configurable context. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example - Client Program
int altContext(int id) { int i; int ret; ret = tpsetctxt(id, TPNOFLAGS); if (ret < 0) { printf(“\t[altContext]tpsetctxt fail[%d][%s]\n"tperrno, tpstrerror(tperrno)); tpfree((char *)tpinfo); return -1; } return 1; }
Example - Server Program
typedef param { int ctxtid; TPSVCINFO *svcinfo; } param_t; MSERVICE(TPSVCINFO *svcinfo) { pthread_t tid; param_t param; printf("MSERVICE service is started!"); tpgetctxt(¶m.ctxtid, TPNOFLAGS); param.svcinfo = svcinfo; pthread_create(&tid, NULL, THREAD_ROUTINE, ¶m); pthread_join(tid, NULL); printf("MSERVICE service is finished!"); tpreturn(TPSUCCESS, 0, svcinfo->data, 0L, TPNOFLAGS); } void *THREAD_ROUTINE(void *arg) { param_t *param; TPSVCINFO *svcinfo; param = (param_t *)arg; svcinfo = param->svcinfo; if (tpsetctxt(param->ctxtid, TPNOFLAGS) == -1) { printf("tpsetctxt(%d) failed, [tperrno:%d]", param->ctxtid, tperrno); return NULL; } tpcall("MTOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, TPNOFLAGS); if (tpsetctxt(TPNULLCONTEXT, TPNOFLAGS) == -1) { printf("tpsetctxt(TPNULLCONTEXT) failed, [tperrno:%d]", tperrno); return NULL; } return NULL; }
Related Function
tpgetctxt()
The tpstrerror function, available in both a server and a client, displays a message corresponding to an error number. When an error occurs while using Tmax APIs, a relevant error code will be specified in a tperrno, which is a global variable. A tpstrerror() displays messages about an error specified in a tperrno.
Prototype
# include <atmi.h> char *tpstrerror (int tperrno)
Parameter
Parameter | Description |
---|---|
tperrno | An error code that will display an error message. |
Return Value
Value | Description |
---|---|
Error Message | A message exists for an error code. |
NULL | A message does not exist for an error code. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char buf; TPSTART_T *tpinfo; tpinfo = (TPSTART_T *)tpalloc(“TPSTART”, NULL, sizeof(TPSTART_T)); if (tpinfo==NULL) { error processing } strcpy(tpinfo->dompwd, “tuxedo”); if (tpstart(tpinfo) == -1){ printf(“tpstart fail , err = %s\n”, tpstrerror(tperrno)); exit(1); } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... tpfree((char *) buf); tpend(); }
The tpsubqname function returns the name of a queue that corresponds to a sub queue number. This function is available both in a server and a client.
Prototype
# include <tmaxapi.h> char *tpsubqname(int type)
Parameter
The followings are names corresponding to a sub queue number. They are the same as those used in a tpqstat() and a tpqsvcstat().
Sub Queue Number | Description |
---|---|
0 | RQ_ANY |
1 | RQ_FAIL |
2 | RQ_REQ |
3 | RQ_RPLY |
Return Value
Value | Description |
---|---|
Sub Queue Name | Returned if there is a corresponding name. |
NULL | Returned if there is no corresponding name. |
The tpsubscribe function subscribes to an event or set of events named by an eventname. It is used to request a notification for an event when an event is posted. This function is available for both servers and clients.
Prototype
# include <tmaxapi.h> long tpsubscribe(char *eventname, char *filter, TPEVCTL *ctl, long flags)
Parameter
Parameter | Description |
---|---|
eventname | A string ending with NULL that has up to a 15-character length. A wildcard character or partial-matching is not supported. Only a name that matches an entire string can be registered. |
filter | Reserved for future-use. NULL must be set in this parameter. |
ctl | A structure that receives a message when an event occurs. It works differently depending on the subject of a tpsubscribe(). If a client used a tpsubscribe(), a ctl must always be NULL and a message will be delivered to a client as an unsolicited data type. Afterwards, the client will handle the received data using a tpsubscribe() or a tpgetunsol(). |
flags | Currently, only a TPNOTIME can be used. |
If a tpsubscribe() is executed by a server, a ctl must not be NULL and it should be configured as shown below:
struct tpevctl { long ctl_flags; long post_flags; char svc[XATMI_SERVICE_NAME_LENGTH]; char qname[RQ_NAME_LENGTH]; }; typedef struct tpevctl TPEVCTL;
Member | Description |
---|---|
ctl_flags | Not currently supported. Set to 0. |
post_flags | Not currently supported. Set to 0. |
qname | When using a qname, a message will be queued in a RQ via a tpenq (qname, NULL, data, len, TPNOFLAGS). |
svc | When using a svc, a message will be sent to a server in a similar manner to a tpacall (svc, data, len, TPNOREPLY) and a response from the server will be ignored. Only one qname or svc can be used at a time. |
Return Value
Value | Description |
---|---|
descriptor | A function call was successful and a descriptor to be used for a tpunsubscribe() is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsubscribe() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. For a client program, a network error is the most common error. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPEINVAL] | An invalid parameter. |
[TPENOENT] | A RQ or a server corresponding to a specified qname or svc of a TPEVCTL structure does not exist. |
[TPEPROTO] | A ctl is not NULL in a client and a server. |
[TPETIME] | A timeout occurred. |
Related Functions
tpsetunsol(), tpsetunsol_flag(), tpgetunsol(), tpacall(), tpenq()
The tptypes function provides information about the type and subtype of a buffer. This function is available both in a server and a client. A tptypes() function receives a pointer for a data buffer, and returns the type and subtype of the buffer.
Prototype
#include <atmi.h> long tptypes (char *ptr, char *type, char *subtype)
Parameter
Parameter | Description |
---|---|
ptr | Must indicate a buffer allocated by a tpalloc(). |
type, subtype | Types and subtypes will have type and subtype names of each buffer respectively for the string they indicate if they are not NULL. If names have a maximum length (8 characters for a type, and 16 characters for a subtype), a string could not end with a NULL. If there is no subtype, the arrangement indicated by a subtype will contain a NULL string ('''''). Only the first 8 bytes of a type and 16 bytes of a subtype have valid values. |
Return Value
Value | Description |
---|---|
Buffer Size | A function call was successful and a proper buffer pointer is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tptypes() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a buffer pointed to by a ptr is not allocated by a tpalloc(). |
[TPEPROTO] | A tptypes() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” main(int argc, char *argv[]) { int ret; struct sel_o *rcvbuf; char type[9], subtype[17]; long size; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct sel_o*)tpalloc(“STRUCT”,”sel_o”,0); if (buf==NULL) {error processing }; size =tptypes((char*)buf, type,subtype); if (size==-1) {error processing }; printf (“buf : size %d, type %s, subtype %s\n\n”, size, type, subtype); /*rcvbuf : size 1024, type STRUCT, subtype sel_o */ data process... tpfree((char *)buf); tpend(); }
Related Functions
tpalloc(), tpfree(), tprealloc()
The tpunsubscribe function removes an event subscription or a set of event subscriptions registered by a tpsubscribe() from a Tmax system's list of subscriptions. If all subscriptions are removed, a Tmax system will delete the table containing the events.
Prototype
# include <tmaxapi.h> int tpunsubscribe(long sd, long flags)
Parameter
Parameter | Description |
---|---|
sd | A return value received when registering for a subscription with a tpsubscribe(). |
flags | Currently, only a TPNOTIME can be used. |
Return Value
Value | Description |
---|---|
Positive Value | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tpunsubscribe() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. For a client program, a network error is the most common error. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPEINVAL] | An invalid parameter. |
[TPETIME] | A timeout occurred. |
Related Functions
tpsetunsol(), tpsetunsol_flag(), tpgetunsol(), tpacall(), tpenq()
The tuxgetenv function returns the value of an environment parameter registered under a name. In general, it acts in the same way as a getenv() function that can be used on a server. This function is available for both servers and clients, which returns a value applied to a autoexec.bat file in a client and returns a value applied to each shell configuration file in a server.
Prototype
#include <tuxfml.h> char *tuxgetenv(char *name)
Parameter
Parameter | Description |
---|---|
name | Specifies an environment variable to be returned. |
Return Value
Value | Description |
---|---|
A pointer for the current value of the environment variable. | Returned when a corresponding environment variable exists. |
NULL | Returned when a corresponding environment variable does not exist. |
Example
... #include <tuxinc/tuxatmi.h> int main(int argc, char *argv[]) { ... char hostAddr[20]; ... memset(hostAddr, NULL, sizeof(hostAddr)); memcpy(hostAddr, tuxgetenv(“TMAX_HOST_ADDR”), sizeof(hostAddr)); printf(“host address = %s\n”, hostAddr); ... }
Related Function
tuxputenv()
The tuxputenv function applies a 'name= value' entered as a string to an environment variable. This function is available for both servers and clients. It modifies an existing environment variable if there is any, or adds a new environment variable if there is no environment variable. This function is identical to a putenv() executable on a server side. In a client, a value applied to autoexec.bat file is modified, and in a server, a value applied to each shell configuration file is modified.
Prototype
#include <tuxfml.h> int tuxputenv(char *string)
Parameter
Parameter | Description |
---|---|
string | Enter a value to be specified in an environment variable. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
Negative Value | Returned if an environment variable does not secure enough memory to apply. |
Example
... #include <tuxinc/tuxatmi.h> int main(int argc, char *argv[]) { ... char hostAddr[20]; char envVal[20]; ... ret = tuxputenv(“A=10”); if (ret < 0){ printf(“tuxputenv fail...[%d]\n”, tperrno); } memset(envVal, NULL, sizeof(envVal)); memcpy(envVal, tuxgetenv(“A”), sizeof(envVal)); printf(“envVal = %s\n”, envVal); ... }
Related Function
tuxgetenv()
The tuxreadenv function loads environment variables from a file. This function is available for both servers and clients. To access a Tmax system, several environmental parameters should be registered first. By referring to registered environment parameters, a client can access a Tmax system by using a tpstart( ) function. Usually, UNIX defines a <.cshrc> in a csh and a <.profile> in a ksh, while DOS defines environment variables in a <autoexec.bat> file. If there are two or more systems to be accessed, a client can change which system to access depending on the situation. In this case, it is impossible to register information about two systems to environment variables, so a client has to register the variables to a file.
tuxreadenv() is a function to read information about an accessed system from a file, and to set a new value for an environment variable. This function should be executed before accessing a Tmax system, because the information required for accessing the system should be set to the environment variable.
Prototype
#include <tuxfml.h> int tuxreadenv (char *file, char *label)
Parameter
Parameter | Description |
---|---|
file | The name of a file where configuration information of an accessed system is stored. This file should be registered according to a prescribed text format. |
label | A descriptor of the configuration information registered in a file. In other words, this value identifies each system if information about two or more systems is registered to one file. |
Return Value
Value | Description |
---|---|
1 | Returned if data does not arrive until a sec time. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tuxreadenv() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | A file or label does not exist. |
Example
... #include <tuxinc/tuxatmi.h> int main(int argc, char *argv[]) { ... ret = tuxreadenv( “tmax.env”,”TMAX” ); if (ret == -1){ error processing } ret = tpinit((TPINIT *)NULL); if (ret == -1){ error processing } ... ret = tpcall(“SERVICE”, buf, 0, &buf, &rcvlen, TPNOFLAGS); if (ret == -1){ error processing } ... tpterm(); }
Related Function
tpstart()
For more information how to register environment variables to a file, refer to "Tmax Administrator's Guide".
The tx_begin function begins a global transaction, for which a function caller becomes a transaction mode. This function is available for both servers and clients. To start a transaction, a calling process must be first connected to a resource manager with a tx_open(), then, it will return a [TX_PROTOCOL_ERROR]. A tx_begin() function will fail if a caller is already in a transaction mode or a tx_open() is not called first.
Once a transaction begins, a calling process must call a tx_commit() or a tx_rollback() in order to complete a current transaction. There are also chaining transactions that do not need to call a tx_begin() directly in order to begin. For further information, see "3.1.86. tx_commit" and "3.1.88. tx_rollback".
Prototype
#include <tx.h> int tx_begin (void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. |
Error
When a tx_begin() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_OUTSIDE] | A transaction manager cannot start a global transaction because a current calling process is participating in external global transactions. The global transaction can be started after all outside jobs are complete. This error does not affect the participating transactions. |
[TX_PROTOCOL_ERROR] | A tx_begin() was called from an invalid state. For example, a caller is already in a transaction mode. This error does not affect current transactions. |
[TX_ERROR] | A transaction manager or a resource manager momentarily encountered an error while starting a transaction. When this error is returned, a caller is not in a transaction mode. Exact causes of the error depend on product characteristics. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. The manager can no longer execute jobs for an application program. When this error is returned, a caller is not in a transaction mode. Exact causes of the error differ depending on product characteristics. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.… ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } cd = tpconnect(“SERVICE”, buf, 20, TPRECVONLY); if (cd==-1) { error processing } ret = tprecv(cd, (char **)&buf, &len,TPNOFLAGS, &revent)}; if (ret < 0 && revent != TPEV_SVCSUCC) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_commit(), tx_open(), tx_rollback(), tx_set_transaction_timeout()
The tx_commit function commits a global transaction. This function is available for both servers and clients.
When a transaction_control property value is TX_UNCHAINED, a caller will not be in a transaction mode anymore when a tx_commit() returns. However, if the value is TX_CHAINED, the caller will remain in the transaction mode for a new transaction when the tx_commit() returns. For detailed information, see "3.1.90. tx_set_transaction_control".
Prototype
# include <tx.h> int tx_commit(void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_commit() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_NO_BEGIN] | Occurs only when a transaction_control property is a TX_CHAINED. A transaction was successfully committed, but new transactions cannot be started, and a caller will no longer be in a transaction mode. |
[TX_ROLLBACK] | A transaction is rolled back. If a transaction_control property is TX_CHAINED, a new transaction will begin. |
[TX_ROLLBACK_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. A transaction is rolled back, but new transactions cannot be started, and a caller is no longer in a transaction mode. |
[TX_HAZARD] | Portions of a transaction may be committed while others may be rolled back due to an error. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_HAZARD_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. Portions of a transaction are committed while others are rolled back. A new transaction cannot be started and a caller will no longer be in a transaction mode. |
[TX_PROTOCOL_ERROR] | A tx_commit() was called from an invalid state. For example, a caller was not in a transaction mode. a caller's status is not affected by the transaction. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. The caller's status related to the transaction is unknown. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.… ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } cd = tpconnect(“SERVICE”, buf, 20, TPRECVONLY); if (cd==-1) { error processing } ret = tprecv(cd, (char **)&buf, &len,TPNOFLAGS, &revent)}; if (ret < 0 && revent != TPEV_SVCSUCC) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_set_commit_return(), tx_set_transaction_control(), tx_set_transaction_timeout()
The tx_info function returns global transaction information. This function is available for both servers and clients. It notifies global transaction information through a structure indicated by info. It also returns a value informing whether a caller is in a transaction mode or not.
Prototype
#include <tx.h> int tx_info (TXINFO *info)
Parameter
If info is not NULL, a TXINFO structure indicated by an info will be global transaction information.
A TXINFO structure is composed as follows.
struct TXINFO { XID xid; COMMIT_RETURN when_return; TRANSACTION_CONTROL transaction_control; TRANSACTION_TIMEOUT transaction_timeout; TRANSACTION_STATE transaction_state; };
If a tx_info() is called in a transaction mode, a xid will be the current transaction branch ID, and a transaction_state will be the current transaction state. If a caller is not in a transaction mode, a xid will be a NULL XID (See <tx.h> for further information).
In addition, regardless of whether a caller is in transaction mode or not, when_return, transaction_control, and transaction_timeout will contain the current settings of a commit_return, transaction_control property, and a transaction timeout value in seconds.
A returned transaction timeout value is used when a next transaction begins. It may not be a timeout value for a caller's current global transaction, because the caller might have changed the transaction timeout by calling a tx_set_transaction_timeout() after a current transaction began. If info is NULL, a TXINFO structure will not be returned.
Continuous tx_info() calling within the same global transaction ensures provision of a XID of the same gtrid (global transaction identifier). However, it does not ensure a same bqual (local transaction identifier). Thus, XIDs may not be the same.
Return Value
Value | Description |
---|---|
1 | A caller is in a transaction mode and a function call was successful. |
0 | A caller is not in a transaction mode and a function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_info() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_PROTOCOL_ERROR] | A tx_info() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager encountered a critical error. The manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
#include <stdio.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { int ret; long len; char *buf; TXINFO info; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... ret=tx_begin(); if (ret<0) { error processing } ret=tpcall(“SERVICE”, buf, 20, (char **)&buf, &len, TPNOFLAGS); if (ret==-1) { error processing } if (tx_info(&info)==1) printf(“In transaction \n”); else printf(“Not in transaction \n”); if (strncmp(buf, “err”, 3)==0) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_open(), tx_set_commit_return(), tx_set_transaction_control(), tx_set_transaction_timeout()
The tx_rollback function is used to roll back a global transaction. This function is available for both servers and clients.
If a transaction_control property is TX_UNCHAINED, a caller will not be in a transaction mode any more when a tx_rollback() returns. If a transaction_control property is TX_CHAINED, however, a caller will remain in a transaction mode for a new transaction when a tx_rollback() returns. For detailed information about a transaction_control property, see "3.1.90. tx_set_transaction_control".
Prototype
#include <tx.h> int tx_rollback(void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_rollback() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. New transactions cannot be started, and a caller is no longer in a transaction mode. |
[TX_MIXED] | Portions of a transaction may be committed while others may be rolled back due to an error. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_MIXED_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. Portions of a transaction are committed while others are rolled back. A new transaction cannot be started and a caller will no longer be in a transaction mode. |
[TX_HAZARD] | Portions of a transaction may be committed while others may be rolled back due to an error. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_HAZARD_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. Portions of a transaction are committed while others are rolled back. A new transaction cannot be started and a caller will no longer be in a transaction mode. |
[TX_COMMITTED] | A transaction was committed independently. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_COMMITTED_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. A transaction was successfully committed, but new transactions cannot be started, and a caller will no longer be in a transaction mode. |
[TX_PROTOCOL_ERROR] | A tx_rollback() was called from an invalid state. For example, a caller was not in a transaction mode. A caller's status is not affected by a transaction. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of an error differ depending on product characteristics. A caller's status related to a transaction is unknown. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.… ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } cd = tpconnect(“SERVICE”, buf, 20, TPRECVONLY); if (cd==-1) { error processing } ret = tprecv(cd, (char **)&buf, &len,TPNOFLAGS, &revent)}; if (ret < 0 && revent != TPEV_SVCSUCC) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_set_transaction_control(), tx_set_transaction_timeout()
The tx_set_commit_return function sets a commit_return property with a when_return value. This function is available for both servers and clients.
This property determines the method how a tx_commit() function returns a control to a caller. A tx_set_commit_return() can be called regardless of whether a function caller is in a transaction mode. This setting is valid until it is changed as a tx_set_commit_return() is called again. Initial setting of a commit_return property depends on the situation when the function is executed.
Prototype
#include <tx.h> int tx_set_commit_return (COMMIT_RETURN when_return)
Parameter
Values available for when_return are as follows:
Configuration Value | Description |
---|---|
TX_COMMIT_DECISION _LOGGED | This flag causes a tx_commit() to return before the second phase of a Two-Phase Commit (2PC) protocol is completed after it was logged in a first phase. This allows a tx_commit() to respond to a caller more quickly. However, there is a danger that a transaction may have a heuristic result. In this case, a caller cannot understand the situation generated by the code returned from a tx_commit(). In normal cases, a transaction participant scheduled to commit a transaction in a first phase can normally commit a transaction in a second phase. In abnormal cases such as a network failure or a node fail lasting too long, it may be impossible to complete a second phase and a heuristic result may be resulted. A transaction manager can select this property not to be supported, using a parameter. At this time, a tx_commit() returns [TX_NOT_SUPPORTED], indicating that this property is not supported. |
TX_COMMIT_COMPLETED | This flag causes a tx_commit() to return after a 2PC protocol is completed. This setting shows a function caller return code indicating that a transaction produced a heuristic result or a probability. A transaction manager can select this property not to be supported, using a parameter. At this time a tx_commit() returns a [TX_NOT_SUPPORTED], indicating that this property is not supported. |
Return Value
When successfully completed, a tx_set_commit_return() returns a [TX_OK] of a value other than a negative value.
If a when_return is set to a TX_COMMIT_COMPLETED or a TX_COMMIT_DECISION_LOGGED, a function will return a [TX_NOT_SUPPORTED] instead of a negative value and a previously used commit_return property will still be valid. A transaction manager must set a when_return to either a TX_COMMIT_COMPLETED or a TX_COMMIT_DECISION_ LOGGED.
Error
When a tmax_chk_conn() fails to execute, a tperrno will be set to one of the following values, and a commit_return property will be unchanged.
Error Code | Description |
---|---|
[TX_EINVAL] | A when_return is not set to TX_COMMIT_COMPLETED or TX_COMMIT_DECISION_LOGGED. |
[TX_PROTOCOL_ERROR] | A tx_set_commit_return() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. The managers could no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. A caller's status, related to the transaction, is unknown. |
Example
#include <usrinc/tx.h> int main(int argc, char *argv[]) { int ret; long len; char *buf; ret = tpstart((TPSTART_T *)NULL); if (ret == -1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; ret = tx_set_transaction_timeout(5); if (ret < 0){ error processing } ret = tx_set_commit_return(TX_COMMIT_COMPLETED); if (ret < 0){ error processing } ret = tx_begin(); if (ret < 0){ error processing } data process.... ret = tpcall(“SERVICE1”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process... ret = tpcall(“SERVICE2”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process …. ret = tx_commit(); if (ret < 0) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tx_commit(), tx_open(), tx_info()
The tx_set_transaction_control function sets a transaction_control property with a control value. This function is available for both servers and clients.
This property determines whether to or not start a new transaction before a tx_commit() and a tx_rollback() returns to a caller. a tx_set_transaction_control() function can be called regardless of whether an application program is in a transaction mode or not. This setting is valid until it is changed as a tx_set_transaction_control() is called again.
Prototype
# include <tx.h> int tx_set_transaction_control(TRANSACTION_CONTROL control)
Parameter
Values available for control are as follows:
Configuration Value | Description |
---|---|
TX_UNCHAINED | The initial value of transaction_control property. Does not start a new transaction until a tx_commit() or a tx_rollback() is returned to a caller. In this case, a caller must execute a tx_begin() in order to begin a new transaction. |
TX_CHAINED | Allows a new transaction to start before a tx_commit() or a tx_rollback() is returned to a caller. |
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When tx_set_transaction_control() fails to execute, tperrno will be set to one of the following values and a previous transaction_control property will be unchanged.
Error Code | Description |
---|---|
[TX_EINVAL] | A control parameter is neither TX_UNCHAINED nor TX_CHAINED. |
[TX_PROTOCOL_ERROR] | A tx_set_transaction_control() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager encountered a critical error. The manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
#include <usrinc/atmi.h> #include <usrinc/tx.h> int main(int argc, char *argv[]) { int ret; long len; char *buf; ret = tpstart((TPSTART_T *)NULL); if (ret == -1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; ret = tx_set_transaction_timeout(5); if (ret < 0){ error processing } ret = tx_set_transaciont_control(TX_UNCHAINED); if (ret < 0){ error processing } ret = tx_begin(); if (ret < 0) { error processing } data process.... ret = tpcall(“SERVICE1”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process... ret = tpcall(“SERVICE2”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process …. ret = tx_commit(); if (ret < 0) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_commit(), tx_open(), tx_rollback(), tx_info()
The tx_set_transaction_timeout function sets a transaction_timeout property for a timeout value. This function is available for both servers and clients. This value indicates the time in which a transaction must be completed before a transaction timeout occurs. In other words, it is the interval between a tx_begin() and a tx_commit(), or a tx_begin() and a tx_rollback().
A tx_set_transaction_timeout() function can be called regardless of whether a function caller is in a transaction mode or not. If a tx_set_transaction_timeout() is called in a transaction mode, a new timeout value will be applied from a following transaction.
Prototype
# include <tx.h> int tx_set_transaction_timeout (TRANSACTION_TIMEOUT timeout)
Parameter
Parameter | Description |
---|---|
timeout | Specifies a time allowed until a transaction timeout occurs, in seconds. It can be set up to a maximum value of a long type defined for each system. Default setting of a transaction_timeout is 0, which means there is no timeout limit. |
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_set_transaction_timeout() fails to execute, tperrno will be set to one of the following values and a transaction_timeout value will be unchanged.
Error Code | Description |
---|---|
[TX_EINVAL] | An invalid timeout value. |
[TX_PROTOCOL_ERROR] | A tx_set_transaction_timeout() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
#include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { int ret; long len; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) {error processing }; ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } ret = tpcall(“SERVICE”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process …. ret = tx_commit(); if (ret < 0) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_commit(), tx_open(), tx_rollback(), tx_info()
The ulogsync function stores ‘ulog’ contents on a memory buffer to a <ulog.dat> file on physical disk by using a userlog().
Prototype
# include <userlog.h> int ulogsync(void)
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to nothing, even if an error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/userlog.h> void main(int argc, char *argv[]) { int ret, cd; long len; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... cd = tpacall(“SERVICE”, (char **)buf, 20, TPNOFLAGS); if (cd==-1) { error processing } ret=tpgetrply(&cd, &buf, &len, TPNOTIME); if (ret==-1){ error processing } ret=userlog(“ error : %s\n“, tpstrerror(errno)); if (ret==-1) { error processing } tpfree((char *)buf); ret=ulogsync(); if (ret==-1) { error processing } tpend(); }
The userlog function writes information required for programs to a <ulog.date> file. A user that writes information required to detect program logic errors during a program execution will mainly use this function.
A <ulog.date> file is created under a directory defined in a ULOGDIR item of a tmax configuration file. Both a client and a server can use this function, and their information is written on the same file.
Even though a userlog() function is called, data will not immediately be written in the file but instead it will be saved in a buffer up to a specific amount, to be written on the file. It is also possible to immediately write data from a buffer to a file, by using a ulogsync() function. A userlog() function uses the same format as a printf() function, which is provided by the C-language library. This means that it is possible to use each escape sequence character used in a printf() function as it is.
Bear in mind that the log file for a userlog() is stored under a ULOGDIR directory in a first function call and the location is not changed for following calls. A userlog() that a program calls first determines where a log will be stored. Therefore, as long as a userlong() is called just once, changes to a configuration file (ULOGDIR) of a client will not affect a file location.
Prototype
# include <userlog.h> int userlog(const char *fmt, ...)
Parameter
Parameter | Description |
---|---|
fmt | A character string to be logged. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to nothing, even when an error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/userlog.h> void main(int argc, char *argv[]) { int ret, cd; long len; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... cd = tpacall(“SERVICE”, (char **)buf, 20, TPNOFLAGS); if (cd==-1) { error processing } ret=tpgetrply(&cd, &buf, &len, TPNOTIME); if (ret==-1){ ret=userlog(“error no: %d, urcode : %d”, tperrno, tpurcode”); if (ret==-1) { error processing } data process.. tpfree((char *)buf); tpend(); }
The Userlog function writes to a 'ulog' file immediately without using a memory buffer. This function is available for both servers and clients. A UserLog() function includes a ulogsync() in it, and the ulogsync() function immediately writes data to a file when it is called. UserLog usage is the same as that of the userlog() function. Buffering size is limited to 8KB.
Prototype
# include <userlog.h> int UserLog (const char *fmt, ...)
Parameter
Parameter | Description |
---|---|
fmt | A character string to be logged. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to nothing, even when an error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/userlog.h> void main(int argc, char *argv[]) { int ret; long len; char *buf, *input; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... strcpy(input, buf); ret=tpcall(“SERVICE”, buf, 20, (char **)&buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process …. UserLog(“input %s -> output : %s\n”,input, buf); tpfree((char *)buf); tpend(); }
The tpremoteconnect function accesses a remote system through a TCP. If a "sec" parameter is given, this function will try to connect to a remote system for a specified time period. If it fails to connect within a given time period, a connection error will occur.
Prototype
#include <ucs.h> int tpremoteconnect(char *host, int portno, int sec)
Return Value
Value | Description |
---|---|
0 | A socket number. |
-1 | A function call failed. A tperrno is set to an error code. |
The _tmax_check_license function validates licenses in Anylink and OpenFrame.
Prototype
int _tmax_check_license(char *tmaxdir, int subprod);
Parameter
Parameter | Description |
---|---|
tmaxdir | The installation directory of a Tmax system ($TMAXDIR). |
subprod | Determines a product to be checked (either AnyLink or OpenFrame). |
The following is an example of defining a parameter used in a subprod:
#define SUB_PROD_ANYLINK 0x00200000 #define SUB_PROD_OPENFRAME 0x00400000
Return Value
Value | Description |
---|---|
1 | Returned if a license has already been issued. |
-1 | Returned if a license has not been issued yet. |
The tmax_event_handler function is a callback function triggered by a SLOG in situations where a SVRTYPE is set to EVT_SVR. This function is used to display more information on an occurred slog. When a slog event occurs, a _tmax_event_handler is called, including detailed information of logs in its arguments. It can be defined in a server program where a SVRTYPE is EVT_SVR. Only a single server can be specified per node.
The log level of an event handler can be specified with a –h option in the TMMOPT section of a NODE. For more information on the [–h] option, refer to the "Tmax Administrator's Guide".
Prototype
#include <usrinc/tmaxapi.h> int _tmax_event_handler(char *progname, int pid, int tid, char *msg, int flags);
Parameter
Parameter | Description |
---|---|
progname | The name of a program calling a event. |
pid | A process id |
tid | A thread id (for future use) |
msg | An event message |
flags | Not currently supported. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. |
Example
<Configuration File>
*DOMAIN tmax1 SHMKEY = 78650, MINCLH = 1, MAXCLH = 3, TPORTNO = 8650, BLOCKTIME = 30 *NODE Tmaxh4 TMAXDIR = "/data1/starbj81/tmax", APPDIR = "/data1/starbj81/tmax/appbin", PATHDIR = "/data1/starbj81/tmax/path", TLOGDIR = "/data1/starbj81/tmax/log/tlog", ULOGDIR = "/data1/starbj81/tmax/log/ulog", SLOGDIR = "/data1/starbj81/tmax/log/slog", TMMOPT = "-h i", SMSUPPORT = Y, SMTBLSIZE = 1000 *SVRGROUP svg1 NODENAME = "@HOSTNAME@" *SERVER evtsvr SVGNAME = svg1, SVRTYPE = EVT_SVR
<Server Program>
#include <stdio.h> #include <stdlib.h> #include <usrinc/atmi.h> #include <time.h> int tpsvrinit(int argc, char *argv[]) { printf(“[EVTHND] started\n”); return 1; } int svrdone() { printf(“[EVTHND stopped\n”]; return 1; ) int _tmax_event_handler(char *program, int pid, int tid, char *msg, int flags) { time_t t1; struct tm *tm; time(&t1); tm = localtime(&t1); printf(“[EVTHND] %s.%d.%02d%02d%02d:%s\n”, program, pid, tm->tm_hour, tm->tm_min, tm->tm_sec, msg); return 0; }
<Makefile.evt>
# Server makefile TARGET = $(COMP_TARGET) APOBJS = $(TARGET).o NSDLOBJ = $(TMAXDIR)/lib64/sdl.o LIBS = -lsvrevt -lnodb OBJS = $(APOBJS) $(SVCTOBJ) SVCTOBJ = $(TARGET)_svctab.o CFLAGS = -Ae +DA2.0W +DD64 +DS2.0 -O -I$(TMAXDIR) APPDIR = $(TMAXDIR)/appbin SVCTDIR = $(TMAXDIR)/svct LIBDIR = $(TMAXDIR)/lib64 # .SUFFIXES : .c .c.o: $(CC) $(CFLAGS) -c $< # # server compile # $(TARGET): $(OBJS) $(CC) $(CFLAGS) -L$(LIBDIR) -o $(TARGET) $(OBJS) $(LIBS) $(NSDLOBJ) mv $(TARGET) $(APPDIR)/. rm -f $(OBJS) $(APOBJS): $(TARGET).c $(CC) $(CFLAGS) -c $(TARGET).c $(SVCTOBJ): cp -f $(SVCTDIR)/$(TARGET)_svctab.c . touch ./$(TARGET)_svctab.c $(CC) $(CFLAGS) -c ./$(TARGET)_svctab.c # clean: •rm -f *.o core $(APPDIR)/$(TARGET)
The _tmax_main function is used for a user program containing a main. When creating a server process, a user program should not contain a main(). However, if a main() is contained in a library created by a user and cannot be modified, then the _tmax_main() function is provided to call and process a main() routine within a Tmax server library.
To use this function, create a <***.c> file in addition to a server program, create a main function in a file, call a _tmax_main() within a main function, and make sure the main() function is called within a Tmax server library instead of calling a main() in a user-created library.
Prototype
#include <usrinc/tmaxapi.h> int _tmax_main(int argc, char *argv[])
Parameter
Same functionality as a main() function.
Parameter | Description |
---|---|
argc | An array of a argv. |
argv | The list of arguments that a user specifies in a CLOPT section. |
Return Value
Same functionality as a main() function as an integer.
Example
The following are steps to use the function:
Create the following library and compile it:
#include <stdio.h> int main(int argc, char* argv[]) { printf(“my lib main called.\n”); }
Create a <libmysvr.so> file.
To use a main() within a Tmax server library without using a main in a user created library, create a <mysvr.c> file and create a main() in that file.
Call a _tmax_main() in the main(). The main() function will have 3 types which are a user created library, a Tmax server library and <mysvr.c>.However, when starting a Tmax system, the main() in <mysvr.c> will be the first to be called, so the main() function withinTmax server library will be called within this function when it is called. This means that the main() in the user created library will not be called.
#include <stdio.h> int main(int argc, char *argv[]) { printf(“My main is called\n”); _tmax_main(argc, (char **)argv); return 0; }
After creating an object file by compiling the <***.c> file, then it links with server program to make one single execution file.
The tmadmin function enables dynamic usage of statistical information, which can be retrieved through a tmadmin,which is a system admin tool, within a server process.
Prototype
# include <tmadmin.h> int tmadmin(int cmd, void *arg, int opt, long flags);
Parameter
Parameter | Description |
---|---|
cmd | The followings are available for a first argument, cmd: TMADM_DISCON, TMADM_CLIINFO, TMADM_QPURGE, TMADM_BOOT, TMADM_DOWN, TMADM_SUSPEND, TMADM_RESUME, TMADM_RESTAT, TMADM_SVC_STAT, TMADM_SPR_STAT, TMADM_SVR_STAT, TMADM_SVC_STAT_EX, TMADM_SPR_STAT_EX, TMADM_TMAX_INFO, TMADM_DOMAIN_CONF, TMADM_NODE_CONF, TMADM_SVG_CONF, TMADM_SVR_CONF, TMADM_SVC_CONF, TMADM_SMTRC |
arg | Specifies a point of a structure that is suitable for each cmd. A data buffer size and offset can be specified via an arg. |
opt | Specified an option flag for each cmd. The options are explained in the table below. |
flags | Not currently supported. |
The following are possible flag values that can be specified in an opt of each cmd.
TMADM_DISCON
Option Flag | Description |
---|---|
TPNOFLAGS | Does not abort if a client is requesting a service. |
TMADM_FFLAG | Aborts if a client is requesting a service |
TMADM_CLIINFO
Option Flag | Description |
---|---|
TPNOFLAGS | Passes all client information of a corresponding node. |
TMADM_SFLAG | Passes the number of all clients of a corresponding node. (arg -> header.num_left) |
TMADM_QPURGE
Option Flag | Description |
---|---|
TMADM_SFLAG | Purges a service queue. |
TMADM_VFLAG | Purges a server queue. |
TMADM_BOOT(TMADM_DOWN)
Option Flag | Description |
---|---|
TMADM_SFLAG | Boots or shuts down a server by using arg->args.name1 as a server name. |
TMADM_GFLAG | Boots or shuts down a server of a server group by using arg- >args.name2 as a server group name. |
TMADM_TFLAG | Boots or shuts down a tms for a server group by using rg- >args.name1 as a server group name. |
TMADM_SUSPEND(TMADM_RESUME)
Option Flag | Description |
---|---|
TMADM_SFLAG | Suspends or resumes a service. |
TMADM_VFLAG | Suspends or resumes a server. |
TMADM_RESTAT
Option Flag | Description |
---|---|
TMADM_VFLAG | Initializes the statistical information of a server. |
TMADM_AFLAG | Initializes the statistical information of all servers. |
TMADM_SVC_STAT (TMADM_SPR_STAT, TMADM_SVR_STAT)
Option Flag | Description |
---|---|
TPNOFLAGS | Passes all statistical information of a node. |
TMADM_SFLAG | Passes only the statistical information matched with a name specified in a arg -> header.opt_char. |
TMADM_CFLAG | Passes only the statistical information of a CLH which corresponds with a CLH number specified in a arg -> header.opt_int. |
TMADM_SVC_STAT_EX (TMADM_SPR_STAT_EX)
Option Flag | Description |
---|---|
TPNOFLAGS | Passes all statistical information of a node. fail_count, error_count, mintime, and maxtime have been added to the options of a TMADM_SVC_STAT (same as the -x option of the stat command in a tmadmin). |
TMADM_SFLAG | Passes only the statistical information matched with a name specified in a arg- >header.opt_char. |
TMADM_CFLAG | Passes only the statistical information of a CLH which corresponds with a CLH number specified in a arg -> header.opt_int. |
TMADM_SMTRC
Option Flag | Description |
---|---|
TPNOFLAGS | Uses a tmadm_smtrc structure. |
TMADM_AFLAG | Uses a tmadm_smtrcall structure. In addition to basic information, spri, reserved, curtime, svctime, ucputime, and scputime are additionally provided. |
TMADM_TMAX_INFO, TMADM_DOMAIN_CONF, TMADM_NODE_CONF, TMADM_SVG_CONF, TMADM_SVR_CONF, TMADM_SVC_CONF
Option Flag | Description |
---|---|
TPNOFLAGS | TPNOFLAGS is only available. |
Return Value
Value | Description |
---|---|
The number which is bigger than 0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmadmin() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a parameter type is NULL. This error can occur when values such as size, offset, and opt_char, contain an error. size, offset, and opt_char can be located in the member variables of a tmadmin_header, which is a structure member of a second argument. |
[TPENOREADY] | Occurs when using a TMADM_CFLAG in a TMADM_SVC_STAT /SPR_STAT/SVR_STAT command, and a corresponding CLH is ‘NOT READY’. This error can occur when no client exists. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPESVCFAIL] | Occurs when a function fails for reasons other than when TMADM_QPURGE, TMADM_BOOT/DOWN, and TMADM_SUSPEND/RESUME commands are TPEINVAL, TPEOS, and TPESYSTEM. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmadmin.h> SERVICE(TPSVCINFO *msg) { char cmd, *buf, *sndbuf; int len; long sndlen; cmd = msg->data[0]; switch (cmd) { case TMADM_TMAX_INFO: len = tmaxinfo(&buf); break; case TMADM_SVC_STAT: len = svcstat(&buf); break; case TMADM_SVC_STAT_EX: len = svcstatex(&buf); break; case TMADM_SPR_STAT: len = sprstat(&buf); break; case TMADM_SPR_STAT_EX: len = sprstatex(&buf); break; case TMADM_QPURGE: len = qpurge(&buf); break; default: len = -1; break; } if (len < 0){ error processing } sndbuf = (char *)tpalloc(“STRING”, NULL, len + 1); if (sndbuf==NULL) {error processing } memcpy(sndbuf, buf, len); sndlen = len; tpreturn(TPSUCCESS, 0, sndbuf, sndlen, TPNOFLAGS); } int qpurge(char **buf) { int n; /*n=tmadmin( TMADM_QPURGE, “TOUPPER”, TMADM_SFLAG, TPNOFLAGS);*/ n = tmadmin(TMADM_QPURGE, “toupper”, TMADM_VFLAG, TPNOFLAGS); if (n < 0){ error processing } ... } int tmaxinfo(char **buf) { struct tmadm_tmax_info *info; ... size = sizeof(struct tmadm_tmax_info) + (MAX_NODE - 1) * sizeof (struct tmadm_node_summary); info = (struct tmadm_tmax_info *) malloc(size); if (info == NULL)}{ error processing } memset(info, 0x00, size); info->header.version = _TMADMIN_VERSION; info->header.size = size; n = tmadmin(TMADM_TMAX_INFO, info, TPNOFLAGS, TPNOFLAGS); if (n < 0)}{ error processing } ... /* Summarize details of structure info and put it in *.buf. Returns *buf size.*/ } int svcstat(char **buf) { struct tmadm_svc_stat info; struct tmadm_svc_stat *stat; ... memset(&info, 0x00, sizeof(struct tmadm_svc_stat)); info.header.version = _TMADMIN_VERSION; info.header.size = sizeof(struct tmadm_svc_stat); n = tmadmin(TMADM_SVC_STAT, &info, TPNOFLAGS, TPNOFLAGS); if (n < 0){ error processing } svccount = info.header.num_entry + info.header.num_left; size = sizeof(struct tmadm_svc_stat)+ ((svccount - 1) * sizeof (struct tmadm_svc_stat_body)); stat = (struct tmadm_svc_stat *) malloc(size); if (stat == NULL){ error processing } memset(stat, 0x00, size); stat->header.version = _TMADMIN_VERSION; stat->header.size = size; n = tmadmin(TMADM_SVC_STAT, stat, TPNOFLAGS, TPNOFLAGS); if (n < 0){ error processing } ... /* Summarize details of structure info and put it in *.buf. Returns *buf size.*/ } int svcstatex(char **buf) { struct tmadm_svc_stat_ex info; struct tmadm_svc_stat_ex *stat; ... memset(&info, 0x00, sizeof(struct tmadm_svc_stat_ex)); info.header.version = _TMADMIN_VERSION; info.header.size = sizeof(struct tmadm_svc_stat_ex); n = tmadmin(TMADM_SVC_STAT_EX, &info, TPNOFLAGS, TPNOFLAGS); if (n < 0){ error processing } svccount = info.header.num_entry + info.header.num_left; size = sizeof(struct tmadm_svc_stat_ex)+ ((svccount - 1) * sizeof (struct tmadm_svc_stat_body_ex)); stat = (struct tmadm_svc_stat_ex *) malloc(size); if (stat == NULL){ error processing } memset(stat, 0x00, size); stat->header.version = _TMADMIN_VERSION; stat->header.size = size; n = tmadmin(TMADM_SVC_STAT_EX, stat, TPNOFLAGS, TPNOFLAGS); if (n < 0){ error processing } ... /* Summarize details of structure info and put it in *.buf. Returns *buf size.*/ } int sprstat(char **buf) { struct tmadm_spr_stat info; struct tmadm_spr_stat *stat; ... memset(&info, 0x00, sizeof(struct tmadm_spr_stat)); info.header.version = _TMADMIN_VERSION; info.header.size = sizeof(struct tmadm_spr_stat); n = tmadmin(TMADM_SPR_STAT, &info, TPNOFLAGS, TPNOFLAGS); if (n < 0){ error processing } sprcount = info.header.num_entry + info.header.num_left; size = sizeof(struct tmadm_spr_stat) + (sprcount - 1) * sizeof (struct tmadm_spr_stat_body); stat = (struct tmadm_spr_stat *) malloc(size); if (stat == NULL)}{ error processing } memset(stat, 0x00, size); stat->header.version = _TMADMIN_VERSION; stat->header.size = size; n = tmadmin(TMADM_SPR_STAT, stat, TPNOFLAGS, TPNOFLAGS); if (n < 0))){ error processing } ... /* Summarize details of structure info and put it in *.buf. Returns *buf size.*/ } int sprstatex(char **buf) { struct tmadm_spr_stat_ex info; struct tmadm_spr_stat_ex *stat; ... memset(&info, 0x00, sizeof(struct tmadm_spr_stat_ex)); info.header.version = _TMADMIN_VERSION; info.header.size = sizeof(struct tmadm_spr_stat_ex); n = tmadmin(TMADM_SPR_STAT_EX, &info, TPNOFLAGS, TPNOFLAGS); if (n < 0){ error processing } sprcount = info.header.num_entry + info.header.num_left; size = sizeof(struct tmadm_spr_stat_ex) + ((sprcount - 1) * sizeof (struct tmadm_spr_stat_body_ex)); stat = (struct tmadm_spr_stat_ex *) malloc(size); if (stat == NULL)}{ error processing } memset(stat, 0x00, size); stat->header.version = _TMADMIN_VERSION; stat->header.size = size; n = tmadmin(TMADM_SPR_STAT_EX, stat, TPNOFLAGS, TPNOFLAGS); if (n < 0))){ error processing } ... /* Summarize details of structure info and put it in *.buf. Returns *buf size.*/ }
The tmax_get_db_password function identifies the password of a username in a database that Tmax is currently connected to.
Prototype
#include <usrinc/tmaxapi.h> int tmax_get_db_passwd (char *svgname, char *passwd, int type)
Parameter
Parameter | Description |
---|---|
svgname | The name of server group that a password affects. Make sure that the server group is XA-compliant. |
passwd | A result is returned in a passwd in a second argument. Make sure to set the length of passwd to be long enough to contain necessary information. |
Type | The Type of DBMS that is currently being used. Set is to one of the following: ORACLE_TYPE | SYBASE_TYPE | INFORMIX_TYPE | DB2_TYPE. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
–1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_get_db_passwd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is invalid, a type is set to a value undefined in a usrinc/tmaxapi.h, or a type is set to INFORMIX_TYPE. |
[TPEITYPE] | A svgname is set to a NONXA server group, or OPENINFO information of a Tmax configuration file is incorrect. |
Example
<OPENINFO in a configuration file>
svg4 NODENAME = @HOSTNAME@, DBNAME = ORACLE, OPENINFO =“ORACLE_XA+Acc=P/scott/tiger+SesTm=60+Sqlnet=tmaxi1”, TMSNAME = tms_ora
<Server Program>
#include <stdio.h> ... SVC_GETPASSWORD( TPSVCINFO *msg ) { char passwd[30]; printf(“\n => use right..\n”); ret = tmax_get_db_passwd(“svg1”, passwd, ORACLE_TYPE); if(ret < 0) printf(“tmax_get_db_passwd fail[%s]\n”,tpstrerror(tperrno)); else printf(“\ntmax_get_db_passwd = %s\n”, passwd); tpreturn( TPSUCCESS, 0, rcvbuf, 0, 0 ); }
<Result>
tmax_get_db_passwd = tiger
Related Functions
tmax_get_db_usrname(), tmax_get_db_tnsname()
The tmax_get_db_tnsname function identifies the tnsname of a database to which Tmax is currently connected to.
Prototype
#include <usrinc/tmaxapi.h> int tmax_get_db_tnsname (char *svgname, char *tnsname, int type)
Parameter
Parameter | Description |
---|---|
svgname | Specifies the name of a server group for identifying its tnsname. Make sure the server group is XA-compliant. |
tnsname | A result is returned in a passwd in a second argument. Make sure to assign the length of passwd to be long enough to contain necessary information. |
Type | The Type of DBMS that is currently being used. Set is to one of the following: ORACLE_TYPE | SYBASE_TYPE | INFORMIX_TYPE | DB2_TYPE. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmax_get_db_tnsname() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is invalid, a type is set to a value undefined in a usrinc/tmaxapi.h, or a type is set to INFORMIX_TYPE. |
[TPEITYPE] | A svgname is set to a NONXA server group, or OPENINFO information of a Tmax configuration file is incorrect. |
Example
<OPENINFO in a configuration file>
svg4 NODENAME = @HOSTNAME@, DBNAME = ORACLE, OPENINFO = ORACLE_XA+Acc=P/scott/tiger+SesTm=60+Sqlnet=tmaxi1”, TMSNAME = tms_ora
<Server Program>
#include <stdio.h> ... SVC_GETTNSNAME( TPSVCINFO *msg ) { char tnsname[30]; printf(“\n => use right..\n”); ret = tmax_get_db_tnsname(“svg1”, tnsname, ORACLE_TYPE); if(ret < 0) printf(“tmax_get_db_tnsname fail[%s]\n”,tpstrerror(tperrno)); else printf(“\ntmax_get_db_tnsname = %s\n”, passwd); tpreturn( TPSUCCESS, 0, rcvbuf, 0, 0 ); }
<Result>
tmax_get_db_tnsname = tmaxi1
Related Functions
tmax_get_db_usrname(), tmax_get_db_tnsname()
The tmax_get_db_usrname function identifies the username of database to which Tmax is currently connected.
Prototype
#include <usrinc/tmaxapi.h> int tmax_get_db_usrname (char *svgname, char *usrname, int type)
Parameter
Parameter | Description |
---|---|
svgname | Specifies the name of a server group to identify its username. Make sure the server group is XA-compliant. |
usrname | A result is returned in a passwd in a second argument. Make sure to assign the length of passwd to be long enough to contain necessary information. |
Type | The Type of DBMS that is currently being used. Set is to one of the following: ORACLE_TYPE | SYBASE_TYPE | INFORMIX_TYPE | DB2_TYPE. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_get_db_usrname() fails to execute, tpernno is set to one of the following values.
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is invalid, a type is set to a value undefined in a usrinc/tmaxapi.h, or a type is set to INFORMIX_TYPE. |
[TPEITYPE] | A svgname is set to a NONXA server group, or OPENINFO information of a Tmax configuration file is incorrect. |
Example
<OPENINFO in a configuration file>
svg4 NODENAME = @HOSTNAME@, DBNAME = ORACLE, OPENINFO = ORACLE_XA+Acc=P/scott/tiger+SesTm=60+Sqlnet=tmaxi1”, TMSNAME = tms_ora
<Server Program>
#include <stdio.h> ... SVC_GETUSRNAME( TPSVCINFO *msg ) { char usrname[30]; printf(“\n => use right..\n”); ret = tmax_get_db_usrname(“svg1”, usrname, ORACLE_TYPE); if(ret < 0) printf(“tmax_get_db_usrname fail[%s]\n”,tpstrerror(tperrno)); else printf(“\ntmax_get_db_usrname = %s\n”, usrname); tpreturn( TPSUCCESS, 0, rcvbuf, 0, 0 ); }
<Result>
tmax_get_db_usrname = scott
Related Functions
tmax_get_db_passwd(), tmax_get_db_tnsname()
The tmax_get_svccnt function returns the number of services available on a server. It is mainly used to determine a buffer size for a tmax_get_svclist function when retrieving a service list.
Prototype
#include <usrinc/tmaxapi.h> int tmax_get_svccnt(void)
Return Value
Value | Description |
---|---|
The number of services | A function call was successful and the number of services available on its server is returned. |
The tmax_get_svclist function retrieves a list of services available on a server.
Prototype
#include <usrinc/tmaxapi.h> int tmax_get_svclist(char *buf, int bufsize)
Parameter
Parameter | Description |
---|---|
buf | Service name available on the server. |
bufsize | A returned value of tmax_get_svccnt() multiplied by XATMI_SERVICE_NAME_LENGTH. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When tmax_get_svclist() fails to execute, tperrno will be set to the following value:
Error Code | Description |
---|---|
[TPEINVAL] | A buffer size is smaller than (Number of
services x
XATMI_SERVICE_NAME_LENGTH ) or is
NULL. |
Example
<Server Program>
#include <stdio.h> #include <stdlib.h> #include <usrinc/tmaxapi.h> GETSVC(TPSVCINFO *msg) { int i; int len, ret, size; char *buf; char *ptr; printf(“GETSVC service is started!\n”); len = tmax_get_svccnt(); if (len < 0) { printf(“tmax_get_svccnt fail[%d]\n”, tperrno); tpreturn(TPFAIL, 0, 0, 0, 0); } printf(“SVCCNT = %d\n”, len); size = len * XATMI_SERVICE_NAME_LENGTH; buf = malloc(size); if (buf == NULL) { printf(“buf is NULL\n”); tpreturn(TPFAIL, 0, 0, 0, 0); } ret = tmax_get_svclist(buf, size); if (ret < 0) { printf(“tmax_get_svclist fail[%d]\n”, tperrno); tpreturn(TPFAIL, 0, 0, 0, 0); } for (i = 0; i < len; i++) { ptr = buf; printf(“%dth SVC[%s]\n”, i, ptr); buf += XATMI_SERVICE_NAME_LENGTH; } free(buf); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); }
The tmax_is_restarted function looks up the restart status of a Tmax AP Server Process. It is only available on a server to tell a server to restart after a server process failure. It can be called from a Tmax AP Server routine.
This function identifies a server restart by using one of the following three scenarios:
- AP Runtime Error (Abnormally closed)
- Timeout: tpreturn(TPEXIT)
- Restart after a tmdown -i -s AP
Description of the function is as follows:
Prototype
#include <usrinc/tmaxapi.h> int tmax_is_restarted(void);
Return Value
Value | Description |
---|---|
1 | Returned if a server restarted after a failure |
0 | Returned if a server wasn't yet restarted after a failure |
Example
<Server Program>
ISRESTARTED(TPSVCINFO *msg) { int ret; ret = tmax_is_restarted() if(ret == 1) printf(“restarted server process\n”); else printf(“normal server process\n”); tpreturn(TPSUCCESS, 0, (char *)NULL, 0, 0); }
The tmax_is_xa function displays whether a server which a process belongs to is XA compliant or not.
Prototype
#include <usrinc/tmaxapi.h> int tmax_is_xa(void);
Return Value
Return Value | Description |
---|---|
XA_MODE(1) | Returned if a server is implemented in a XA mode. |
NONXA_MODE(0) | Returned if a server is implemented in a NON-XA mode. |
Example
#include <stdio.h> SVC_XA( TPSVCINFO *msg ) { ... ret = tmax_is_xa(); if (ret < 0) printf(“\ntmax_is_xa func fail [%s]\n”, tpstrerror(tperrno)); if(ret == 1) strcpy(mode, « XA_MODE »); else if(ret == 0) strcpy(mode, “NONXA_MODE”); else strcpy(mode, “unknown”); printf(“ => [SVC_XA] result of tmax_is_xa() : %s\n\n”, mode); tpreturn( TPSUCCESS, 0, rcvbuf, 0, 0 ); }
The tmax_my_svrinfo function displays the system configuration of a server process. It displays static information, but a tmadmin() allows a user to check dynamic information.
Prototype
#include <tmaxapi.h> int tmax_my_svrinfo (TMAXSVRINFO*)
Parameter
The server processes registered in a Tmax configuration file contain hierarchical information such as a node name, a server group name, and a server name. A server group index, server index and a sequence number of a server process, are treated as unique values in a single node and can be displayed. A developer can use the information for various purposes such as process management and classification. The information can be derived from a TMAXSVRINFO structure defined in a <tmaxapi.h>. The following shows a TMAXSVRINFO structure.
typedef struct { int nodeno; /* node index */ int svgi; /* server group index;unique in the node */ int svri; /* server index; unique in the node */ int spri; /* server process index; unique in the node */ int spr_seqno; /* server process seqno ; unique in the server */ int min, max; /* min/max server process number */ int clhi; /* for RDP only, corresponding CLH id */ char nodename[TMAX_NAME_SIZE]; char svgname[TMAX_NAME_SIZE]; char svrname[TMAX_NAME_SIZE]; char reserved_char[TMAX_NAME_SIZE]; /* for more detail use tmadmin API */ } TMAXSVRINFO;
Member | Description |
---|---|
nodeno | A node index, which is a unique value in a single domain of a Tmax system. |
svgi | A unique value in a single node that indicates a server group index. |
svri | A unique value in a single node that indicates a server index. |
spri | A unique value in a single node that indicates a server process index. |
spr_seqno | The sequence number of a server process. |
min , max | The minimum and maximum number of processes specified in a Tmax configuration file. |
clhi | A field used in cases where a RDP server process indicates a CLH number which corresponds to a relevant RDP process. |
nodename | A node name configured in a Tmax configuration file. |
svgname | A server group name configured in a Tmax configuration file. |
svrname | A server name configured in a Tmax configuration file. |
reserved_char | Currently not used. For future use. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | Returned when a variable was not specified to save the information of a server process. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int n; TMAXSVRINFO *info; info = (TMAXSVRINFO *)malloc(sizeof(TMAXSVRINFO)); if (info == NULL) { tpreturn(TPFAIL, -1, NULL, 0, TPNOFLAGS); } n = tmax_my_svrinfo(info); }
Related Function
tmadmin()
The tmgetsmgid function supports a SysMaster trace function and returns the group id of a calling process. It enables a user to perform a system trace.
To execute the function, a SMSUPPORT in the NODE section of a configuration file should be set to Y. The (st -p -x) tmadmin tool also can be used to display the GID of a server process.
The structure of a GID is as follows. Once a function completes successfully, it will be returned with gid->gid1, gid->gid2, and gid->seqno.
Item | Description |
---|---|
GID1(4Byte) | The unique number of a client connected to a system. ( cli for WebtoB) Clients are classified with a domain id, a node id, a hth #, and a slot id. |
GID2 (4Byte) | Indicates a seq # by using its first three bytes and a unique product ID using the final byte. |
SEQNO (4Byte) | Indicates a branch # for synchronous message by using its first two bytes and seq # for all message by using its last two bytes. |
Prototype
#include <usrinc/tmadmin.h> int tmgetsmgid(tmax_smgid_t *gid);
Parameter
Parameter | Description |
---|---|
gid | A unique number for each client in a product. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A gid is set to NULL. |
Example
<svr02.c : TPNOFLAGS>
#include <stdio.h> #include <stdlib.h> #include <usrinc/atmi.h> #include <usrinc/tmadmin.h> #include “../sdl/demo.s” GETGID(TPSVCINFO *msg) { tmax_smgid_t smgid; int ret; char *buf; buf = (char *)tpalloc(“STRING”, NULL, 0); if(buf == NULL) tpreturn(TPFAIL, -1, NULL, 0, 0); ret = tmgetsmgid(&smgid); memcpy(buf, (char *)&smgid.gid1, 4); memcpy(buf+4, (char *)&smgid.gid2, 4); memcpy(buf+8, smgid.seqno, 4); tpreturn(TPSUCCESS, 0, (char *)buf, strlen(buf), 0); } SMTRACE(TPSVCINFO *msg) { struct tmadm_smtrc *smtrc; int max = 10, size; int gid1, gid2, n, i; struct smtrace *ptr; char *buf; buf = (char *)tpalloc(“CARRAY”, NULL, 0); if(buf == NULL) tpreturn(TPFAIL, -1, NULL, 0, 0); ptr = (struct smtrace *)msg->data; gid1 = ptr->gid1; gid2 = ptr->gid2; /* printf(“SMTRACE start: %x %x\n”, gid1, gid2); */ size = sizeof(struct tmadm_smtrc) + (max-1) * sizeof(struct tmadm_smtrc_body); smtrc = (struct tmadm_smtrc *)malloc(size); if(smtrc == NULL) { printf(“smtrc is null\n”); tpreturn(TPFAIL, -1, NULL, 0, 0); } memset(smtrc, 0x00, size); smtrc->header.version = _TMADMIN_VERSION; smtrc->header.size = size; smtrc->header.reserve_int[0] = gid1; smtrc->header.reserve_int[1] = gid2; n = tmadmin(TMADM_SMTRC, smtrc, TPNOFLAGS, TPNOFLAGS); if(n < 0) { free(smtrc); tpreturn(TPFAIL, -1, NULL, 0, 0); } /* printf(“smtrc->header.num_entry = %d\n”, smtrc->header.num_entry); */ for(i=0; i<smtrc->header.num_entry; i++) { sprintf(buf, “SMTRACE[%d] : gid[%x-%x-%x] seqno[%x] clhno[%x] status [%s] name[%s]\n”,i, gid1, gid2, ptr->seqno, smtrc->trc[i].seqno, smtrc->trc[i].clhno, smtrc->trc[i].status, smtrc->trc[i].name); } free(smtrc); tpreturn(TPSUCCESS, 0, (char *)buf, strlen(buf), 0); }
<svr02_a.c : TMADM_AFLAG>
#include <stdio.h> #include <stdlib.h> #include <usrinc/atmi.h> #include <usrinc/tmadmin.h> #include "../sdl/demo.s" GETGID_A(TPSVCINFO *msg) { tmax_smgid_t smgid; int ret; char *buf; buf = (char *)tpalloc("STRING", NULL, 0); if(buf == NULL) tpreturn(TPFAIL, -1, NULL, 0, 0); ret = tmgetsmgid(&smgid); memcpy(buf, (char *)&smgid.gid1, 4); memcpy(buf+4, (char *)&smgid.gid1, 4); memcpy(buf+8, smgid.seqno, 4); tpreturn(TPSUCCESS, 0, (char *)buf, strlen(buf), 0); } SMTRACE_A(TPSVCINFO *msg) { struct tmadm_smtrcall *smtrcall; int max = 10, size; int gid1, gid2, n, i; struct smtrace *ptr; char *buf; buf = (char *)tpalloc("CARRAY", NULL, 0); if(buf == NULL) tpreturn(TPFAIL, -1, NULL, 0, 0); ptr = (struct smtrace *)msg->data; gid1 = ptr->gid1; gid2 = ptr->gid2; /* printf("SMTRACE start: %x %x\n", gid1, gid2); */ size = sizeof(struct tmadm_smtrcall) + (max-1) * sizeof(struct tmadm_smtrcall_body); smtrcall = (struct tmadm_smtrcall *)malloc(size); if(smtrcall == NULL) { printf("smtrcall is null\n"); tpreturn(TPFAIL, -1, NULL, 0, 0); } memset(smtrcall, 0x00, size); smtrcall->header.version = _TMADMIN_VERSION; smtrcall->header.size = size; smtrcall->header.reserve_int[0] = gid1; smtrcall->header.reserve_int[1] = gid2; n = tmadmin(TMADM_SMTRC, smtrcall, TMADM_AFLAG, TMADM_AFLAG); if(n < 0) { free(smtrcall); tpreturn(TPFAIL, -1, NULL, 0, 0); } printf("smtrcall->header.num_entry = %d\n", smtrcall->header.num_entry); printf("smtrcall->header.num_left = %d\n", smtrcall->header.num_left); n = 0; for(i=0; i<smtrcall->header.num_entry + smtrcall->header.num_left; i++) { sprintf(buf+n, "SMTRACE[%d] : gid[%x-%x-%x] seqno[%x] clhno[%x] status[%s] name[%s] spri[%d] curtime[%ld], svctime[%ld], ucputime[%ld], scputime[%ld]\n", i, gid1, gid2, ptr->seqno, smtrcall->trc[i].seqno, smtrcall->trc[i].clhno, smtrcall->trc[i].status, smtrcall->trc[i].name, smtrcall->trc[i].spri, smtrcall->trc[i].curtime.tv_sec, smtrcall->trc[i].svctime.tv_sec, smtrcall->trc[i].ucputime.tv_sec, smtrcall->trc[i].scputime.tv_sec); n = n + strlen(buf); } free(smtrcall); tpreturn(TPSUCCESS, 0, (char *)buf, strlen(buf), 0); }
<svr01.c>
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmadmin.h> #include “../sdl/demo_sdl.h” SDLTOUPPER(TPSVCINFO *msg) { int i, ret, cd; struct smtrace *stdata; tmax_smgid_t smgid; char *buf; long rcvlen; buf = (char *)tpalloc(“CARRAY”, NULL, 0); ret = tmgetsmgid(&smgid); if(ret < 0) tpreturn(TPFAIL, -1, NULL, 0, 0); stdata = (struct smtrace *)msg->data; stdata->gid1 = smgid.gid1; stdata->gid2 = smgid.gid2; stdata->seqno = smgid.seqno; cd = tpacall(“SMTRACE”, msg->data, 0, 0); ret = tpgetrply(&cd, (char **)&buf, (long *)&rcvlen, 0); if(ret < 0) tpreturn(TPFAIL, -1, NULL, 0, 0); sleep(20); tpreturn(TPSUCCESS,0,(char *)buf, strlen(buf),0); }
< client.c>
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/tmadmin.h> #include “../sdl/demo.s” main(int argc, char *argv[]) { struct smtrace *sndbuf, *rcvbuf; long rcvlen, sndlen; int ret; if (tpstart((TPSTART_T *)NULL) == -1){ printf(“tpstart failed\n”); exit(1); } ... if (tpcall(“SDLTOUPPER”,(char *)sndbuf,0, (char **)&rcvbuf, &rcvlen, 0) == 1) { printf(“Can’t send request to service SDLTOUPPER =>\n”); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } printf(“rcvbuf = %s\n”, rcvbuf); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
See "Tmax Administrator's Guide" for detailed information about the tmadmin tool.
The tmget_smtrclog function stores logging data in a structure buffer. When saving data, the maximum number of logs is set. When displaying data, the number of saved data is saved.
Prototype
#include <usrinc/tmadmin.h> int tmget_smtrclog(void *handle, tmax_smtrclog_t *buf, int *count)
Parameter
Parameter | Description |
---|---|
handle | A pointer (msg->data) to data sent from a logging service. |
buf | A buffer used to retrieve logging data. |
count | Stores logging count. |
Logging information structure (tmax_smtrclog_t) is as follows:
< usrinc/tmadmin.h>
/* SysMaster Trace Log structure */ typedef struct { tmax_smgid_t gid; int clhno; char status[TMAX_NAME_SIZE]; char name[TMAX_NAME_SIZE]; int spri; int reserved; struct timeval curtime; struct timeval svctime; struct timeval ucputime; struct timeval scputime; } tmax_smtrclog_t;
Member | Description |
---|---|
gid | A SysMaster GID. |
clhno | A clh number requested. |
status[TMAX_NAME_SIZE] | A service status. |
name[TMAX_NAME_SIZE] | A service name. |
spri | A server process index. |
reserved | Currently not used. |
curtime | A current time. |
svctime | A service execution time. |
ucputime | A user CPU time. |
scputime | A system CPU time. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmget_smtrclog() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPESYSTEM] | A SysMaster or SysMaster log service was not configured in a node. |
[TPELIMIT] | An entered count is smaller than the number of actual data in a handle. |
Example
<svr.c>
#include <stdio.h> #include <stdlib.h> #include <usrinc/atmi.h> #include <usrinc/tmadmin.h> SMLOGSERVICE(TPSVCINFO *msg) { tmax_smtrclog_t *smtrclog; int ret, count=0, i; char *buf; smtrclog = (tmax_smtrclog_t *)tpalloc("CARRAY", NULL, 1024); if(smtrclog == NULL) { printf("smtrclog tpalloc fail [%s]\n", tpstrerror(tperrno)); } buf = (char *)tpalloc("STRING", NULL, 0); if(buf == NULL) tpreturn(TPFAIL, -1, NULL, 0, 0); memset(buf, 0x00, 1024); memset(smtrclog, 0x00, 1024); count = tmget_smtrclog_count((char *)msg->data); printf("\n###########################\n\n"); printf("tmget_smtrclog_count = %d\n", count); count = 100; ret = tmget_smtrclog(msg->data, smtrclog, &count); printf("count = %d\n", count); for(i=0; i<count; i++) { printf("smtrclog[%d].gid = %d-%d-%d\n", i, smtrclog[i].gid.gid1, smtrclog[i].gid.gid2, smtrclog[i].gid.seqno); printf("smtrclog[%d].clhno = %d\n", i, smtrclog[i].clhno); printf("smtrclog[%d].status = %s\n", i, smtrclog[i].status); printf("smtrclog[%d].name = %s\n", i, smtrclog[i].name); printf("smtrclog[%d].spri = %d\n", i, smtrclog[i].spri); printf("\n"); } printf("###########################\n\n"); strcpy(buf, "success\n"); tpreturn(TPSUCCESS, 0, (char *)buf, 0, 0); }
The tmget_smtrclog_count function returns the number of data to be logged.
Prototype
##include <usrinc/tmadmin.h> int tmget_smtrclog_count(void *handle)
Parameter
Parameter | Description |
---|---|
handle | A pointer (msg→data) to the data sent from a logging service. |
Return Value
Value | Description |
---|---|
The number of data currntly logged | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tmget_smtrclog_count() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. |
[TPESYSTEM] | A SysMaster or SysMaster log service was not configured in a node. |
Example
See the example of "3.2.14. tmget_smtrclog".
The tpadvertise function allows a server to advertise a service that it offers. A service name can be advertised using an advertise API. When advertising a service, a service name can be registered in each of the service name tables in CLH managed servers. When this service is called, a function referenced by a func will be executed. In summary, advertise enables a server process to advertise any new services provided by a server.
In Tmax versions prior to 5.0 SP1 Fix#4(r7000) and 5.0 SP2 Fix#1, only services registered in a configuration file could be advertised, and a new service could not be advertised and released. From the mentioned versions and subsequent versions, new services can be advertised and released.
The following describes the operation way for each service:
Classification | Description |
---|---|
Service registered in a configuration file | A service status is changed to runnable after a tpunadvertise was executed. If a tpadvertise was executed in another server, it will fail. |
Service registered with mksvr | A service status is changed to runnable after a tpunadvertise was executed. If a tpadvertise was executed in another server, it will fail. If all server processes have ended, services for which a tpadvertise was executed for are automatically removed. |
Newly registered service | A new service is registered. A service status is changed to runnable after a tpunadvertise is executed. If a tpadvertise is executed in another server, it will fail. If all server processes have ended, services for which a tpadvertise was executed for are automatically removed. |
SVCTIMEOUT and AUTOTRAN cannot be set for a newly registered service.
Prototype
#include <atmi/usrinc.h> int tpadvertise(char svcname, void (func)(TPSVCINFO *));
Parameter
Parameter | Description |
---|---|
svcname | The name of a service to be registered. |
(func)(TPSVCINFO *) | The name of a function to be called. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpadvertise() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | A service name is NULL, or a function is NULL. |
[TPELIMIT] | A service name exceeds a string length limit, or since the number of nodes reaches a MAXSVC of a node, a new service cannot be registered. |
[TPEMATCH] | A service is already being advertised by another function, or an attempt was made to register a service already registered in another server. |
[TPEPROTO] | A tpadvertise() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <usrinc/atmi.h> SVC2TN_NEWSVC1( TPSVCINFO *msg ) { ... } SVC2TN_NEWSVC2( TPSVCINFO *msg ) { ... } SVC2TN_1( TPSVCINFO *msg ) { int ret; char input[MAXLEN]; void (*func)(TPSVCINFO*); memset(input, 0x00, MAXLEN); strncpy(input, msg->data, msg->len); func = SVC2TN_NEWSVC1; ret = tpadvertise(input, func); if (ret < 0) { tpreturn(TPFAIL, 0, (char*)msg->data, msg->len, 0); } tpreturn(TPSUCCESS, 0, (char*)msg->data, msg->len, 0); }
For more information about advertise and unadvertise functions, refer to 'advertise/unadvertise' in the "Tmax Administrator's Guide".
The tpcancelctx function cancels a corresponding structure content among information saved using a tpsavectx(). Even when a tprelay() is not performed, if a service routine is terminated, a result will be returned normally.
A tpgetctx() can be used only in a service routine.
Prototype
#include <ucs.h> int tpcancelctx(CTX_T *ctxp);
Parameter
Parameter | Description |
---|---|
ctxp | Deletes a CTX_T structure saved in a library. |
The following is a CTX_T structure definition:
typedef struct { int version[4]; char data[CTX_USR_SIZE - 16]; } CTX_T;
Example
RELAY_SVC(TPSVCINFO *msg) { ..... ctxp = (CTX_T *)tpsavectx(); ..... ret=tpcancelctx(ctxp); if (ret<0) { error process routine } ..... tpreturn(TPFAIL, sqlca.sqlcode, NULL, 0, TPNOFLAGS); }
The tpchkclid function checks if a client corresponding to an ID is connected to a node where a server process resides in. When developing a RDP type server program, if a service routine stores a connected client ID and a usermain() routine sends a message to a tpsendtocli(), unnecessary errors can be prevented.
If a client is not directly connected to the node where a server process resides in a RDP type, a tpsendtocli() cannot be used.
Prototype
#include <tmaxapi.h> int tpchkclid(int clid)
Parameter
Parameter | Description |
---|---|
clid | A unique client number obtained with a tpgetclid(). |
Return Value
Value | Description |
---|---|
-2 | A client is not the client that is connected to a local node. |
-1 | A client is not connected. |
1 | A client is connected normally. |
Error
When a tpchkclid() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | A client is not connected in a local node or an invalid client number was entered. |
[TPENOREADY] | A client is not normally connected to a server. |
Example
int _discon(char **buf) { int clid, n; clid = tpgetclid(); n = tpchkclid(clid); if (n < 0) { printf(“Invalid Client\n”); return -1; } ... }
Related Function
tpgetclid()
The tpclrfd function turns off a socket fd in an internal fdset of a UCS-type process. It is used for scheduling an external socket in a UCS-type server process.
Prototype
#include <ucs.h> int tpclrfd (int fd)
Parameter
Parameter | Description |
---|---|
fd | The socket of an internal fdset to be turned off. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpclrfd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS]an | An operating system error occurred. |
Example
#include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <usrinc/ucs.h> …. #define SERV_ADDR “168.126.185.129” #define SERV_PORT 1500 int fd_read(int, char *, int); extern int errno; int usermain(int argc, char *argv[]) { ... int listen_fd, n, newfd; struct sockaddr_in my_addr, child_addr; socklen_t child_len; buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ error processing } memset((void *)&my_addr, NULL, sizeof(my_addr)); memset((void *)&child_addr, NULL, sizeof(child_addr)); listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd == -1){ error processing } my_addr.sin_family = AF_INET; inaddr = inet_addr(SERV_ADDR); my_addr.sin_port = htons((unsigned short)SERV_PORT); if (inaddr != -1){ memcpy((char *)&my_addr.sin_addr, (char *)&inaddr, sizeof(inaddr)); } ret = bind(listen_fd, (struct sockaddr *)&my_addr, sizeof(my_addr)); if (ret == -1){ error processing } ret = listen(listen_fd, 5); if (ret == -1){ error processing } tpsetfd(listen_fd); ... while(1) { n = tpschedule(10); ... if (n == UCS_USER_MSG){ if (tpissetfd(listen_fd)) { child_len = sizeof(child_addr); newfd = accept(listen_fd, &child_addr, &child_len); if (newfd == -1){ error processing } tpsetfd(newfd); } if (tpissetfd(newfd)){ /* Reads a buffer from a socket */ fd_read(newfd, buf, 1024); ret = tpcall(“SERVICE”, (char *)buf, sizeof(buf), (char **)&buf, (long *)&rlen, TPNOFLAGS); if (ret == -1){ error processing } ... ret = tpclrfd(newfd); if (ret == -1){ error processing } close(newfd); } ... } return 1; }
Related Function
tpissetfd()
The tpclrfd_w function turns a bit for a socket fd off in an internal writable FDSET used by a UCS-type process. It is used for scheduling an outside socket in a UCS-type server process. This function removes a socket FD given in an argument of a FDSET in a UCS-type server process.
A tpclrfd() removes a Readable FDSET, and this function turns a Writable FDSET off. A FD indicates a socket FD to be deleted from a Writable FDSET.
The tpissetfd_w(), tpsetfd_w(), and tpclrfd_w() functions enable scheduling of a user socket FD, which is connected to an external host/client, in the UCS scheduler of a tpschedule() / tpuschedule(). It also manages a TMM and a CLH. When a message is ready to be sent to a user-specified FD, a tpschedule() will return a UCS_USER_MSG. In order to check which socket of a message is ready to be sent, a tpissetfd_w() should be used. A socket FD related to macro functions, including tpissetfd(), tpsetfd(), tpclrfd(), tpissetfd_w(), tpsetfd_w(), and tpclrfd_w() are similar to FD_SET, FD_CLR, and FD_ISSET used in a general network program.
Prototype
#include <ucs.h> int tpclrfd_w (int fd)
Parameter
Parameter | Description |
---|---|
fd | The socket of an internal fdset to be turned off. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpclrfd_w() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
See the example of "3.2.37. tpissetfd", "3.1.72. tpsetfd", and "3.2.19. tpclrfd".
Related Functions
tpissetfd(), tpsetfd(), tpclrfd()
The tpforward function ends its own service processing, and forwards a client’s request to a svc service routine.
This function is called at the end of a service routine, which acts like a tpreturn(). Like a tpreturn(), a tpforward() must be called within a service routine controlled by a Tmax system to be correctly returned to the system.
This function forwards a service request to a service named svc using data. The service routine that forwards the request will not receive a reply. After forwarding the request, a service routine returns to the Tmax system. Then, the service can perform other operations. Because a tpforward() does not expect any response from a requester, it can forward a service request to any service without any particular errors.
If a service routine is in a transaction mode, the transaction can be completed only when the transaction originator completes the transaction by executing either a tx_commit() or a tx_rollback(). In other words, like a tpreturn(), a tpforward() does not complete a transaction. If a transaction is originated within a service routine that uses a tx_begin(), the transaction must be completed before a tpforward() is called, either by using a tx_commit() or a tx_rollback(). This means that all services connected by a tpforward() must be or not be in a transaction mode. The finally forwarded server process sends a reply to a client that requested the service first, using a tpreturn(). In other words, a tpforward() shifts the responsibility of sending a reply for a waiting requester, to another server process. This service is available even in between nodes.
A tpforward() must be called after a service routine receives replies for all services requested. The descriptors of unreceived replies are invalidated and a forward request is not transmitted. A tpforward() cannot be called in a interactive communication.
The following shows the tpforward function flow:
Prototype
# include <atmi.h> void tpforward (char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
svc | The name of a service to receive a buffer. |
data | If data is NULL, it must indicate a buffer that has been allocated with a tpalloc(). If a buffer is the same as the one transmitted to a service routine, ta Tmax system must handle this buffer. If a service routine writer attempts to release the buffer, this attempt will fail. However, if the buffer transmitted to a tpforward() is not the same as the one transferred at the time of calling the service, a tpforward() will release the buffer. |
len | A len is the length of data to be transmitted. If data indicates a buffer that does not require a specific length (e.g., a STRUCT Type buffer), len will be ignored and is set to 0. If data is NULL, len will be ignored and a request that has a data length of 0 will be transmitted. A service routine writer cannot regain control after calling a tpforward(), blocking transmission in the form that a TPSIGRSTRT is defined implicitly is used. Therefore, if a signal is generated during a tpforward() operation to stop an operation, processing will continued later. If a blocking condition is encountered, it will wait until a timeout occurs and then sends a service request. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
A service routine does not return any value to a Tmax system, that is, a caller. In other words, a service routine will be declared as void.
Error
When a tpforward() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESVCERR] | Occurs when an invalid buffer is used; a tpacall()/tpconnect() returns a cd; a tpforward() was used instead of a tpreturn() during interactive communication; a TPEV_DISCONIMM event occurred; or an XA operation (tx_begin(), tx_rollback(), and a tx_commit()) failed in a transaction mode. |
[TPETIME] | Occurs when a transaction timeout occurs during a service routine or while a service request is being transmitted. |
Example
#include <stdio.h> #include <usrinc/atmi.h> SWITCH(TPSVCINFO *msg) { int switch; char *buf; buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } strcpy(buf, msg->data); data process… if (switch>5) tpforward(“SERVICE1”, buf, 0, 0); else tpforward(“SERVICE2”, buf, 0, 0); }
Related Functions
tpalloc(), tpconnect(), tpreturn()
The tpgetctx function copies current client information to a CTX_T structure that was declared and allocated by a user. If a tpgetctx() is used, and if a tprelay() is not used to use information, a client will keep waiting for a response even after a service routine completes.
The information obtained by a tpgetctx() cannot be canceled with a tpcancelctx(), so a tprelay() must be used only in a service routine.
Prototype
#include <tmaxapi.h> int tpgetctx (CTX_T *ctxp)
Parameter
Parameter | Description |
---|---|
ctxp | Receives client information that was stored with a tpsavectx(), to a CTX_T structure. |
Example
RELAY_SVC(TPSVCINFO *msg) { CTX_T *ctxp; ctxp=(CTX_T *)malloc(sizeof(CTX_T); .... ret = tpgetctx(ctxp); if (ret<0) { error process routine } ..... }
The tpgetdbsessionid function gets RM session information. When processing RM session information within a service, RM session information can be obtained using a tpsetdbsessionid callback function and a session id can be obtained using a tpgetdbsessionid.
Prototype
#include <tmaxapi.h> char * tpgetdbsessionid(int flags);
Parameter
Parameter | Description |
---|---|
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
Currently connected session ID | A function call was successful. |
Example
#include <usrinc/tmaxapi.h> ... EXEC SQL include sqlca.h; EXEC SQL begin declare section; ... char h_ssid[20]; EXEC SQL end declare section; int tpsetdbsessionid(char dbsessionid[MAX_DBSESSIONID_SIZE], int flags) { EXEC SQL SELECT TO_CHAR(USERENV(‘sessionid’)) into :h_ssid FROM dual; if ( sqlca.sqlcode != 0 ){ printf( “getting session id fail = %d\n”,sqlca.sqlcode ); return -1; } printf(“RM session id = %s\n”, h_ssid); memset(dbsessionid, 0x00, MAX_DBSESSIONID_SIZE); strcpy(dbsessionid, h_ssid); return 0; } FDLINS( TPSVCINFO *msg ) { char *ssid; int ret; int flags = 0; printf(“ >>> current RM session id = %s\n”, h_ssid); ssid = tpgetdbsessionid(flags); tpreturn( ... ); }
The tpgetmaxsvr function returns a value of a MAX item, which is a maximum server process count defined in the SERVER section of a configuration file. This function only can get the maximum count of its own server processes.
Prototype
#include <tmaxapi.h> int tpgetmaxsvr(void)
Return Value
Value | Description |
---|---|
A positive number | A function call was successful and a positive value that is the maximum count of server processes is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetmaxsvr() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { char *buf; buf = msg->data; data process... printf(“maxsvr : %d\n”,tpgetmaxsvr()); data process... tpreturn(TPSUCCESS,0,buf, strlen(buf), 0); }
Related Function
tpgetminsvr()
The tpgetmaxuser function gets the maximum number of concurrent users of a node that a server process belongs to.
Prototype
#include <tmaxapi.h> int tpgetmaxuser(void)
Return Value
Value | Description |
---|---|
A positive number | A function call was successful and the maximum number of concurrent users of a node in its own server process that is being executed is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetmaxuser() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { char *buf; buf = msg->data; data process... printf(“maxusr : %d\n”,tpgetmaxusr()); data process... tpreturn(TPSUCCESS,0,buf, strlen(buf), 0); }
The tpgetminsvr function returns the minimum number of server processes defined in the SERVER section of a configuration file. Only the minimum number of processes that a server generated is returned with this function.
Prototype
#include <tmaxapi.h> int tpgetminsvr(void)
Return Value
Value | Description |
---|---|
A positive number | A function call was successful and the minimum number of server processes is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetminsvr() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { char *buf; buf = msg->data; data process... printf(“minsvr : %d\n”,tpgetminsvr()); data process... tpreturn(TPSUCCESS,0,buf, strlen(buf), 0); }
Related Function
tpgetmaxsvr()
The tpgetmynode function returns the name and number of a node.
Prototype
#include <tmaxapi.h> char *tpgetmynode(int *nodeno)
Parameter
Parameter | Description |
---|---|
nodeno | The name of a node is returned with a * char, and a node number is set to nodeno. |
Return Value
Value | Description |
---|---|
Node name | A function call was successful. |
NULL | A function call failed. A tperrno is not set to an error code even though an error occurred. |
Example
#include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int i, clid, n; char *nodename; ... for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); ... if (nodename == NULL){ error processing } nodename = tpgetmynode((int *)&n); if (nodename == NULL){ error processing } else { printf(“TOUPPER SERVICE node(%dth node) name = %s\n”, n, nodename); } ... tpreturn(TPSUCCESS,0,(char *)msg->data, 0,TPNOFLAGS); }
The tpgetmysvgno function is only available in a server and it queries the server group number of the group a server is member of. Generally, this function is used with tpcallsvg() or tpacallsvg() functions that requests services from a particular server group. This function enables services in the same server group to be called in a multi-server group environment grouped by a COUSIN.
Prototype
#include <usrinc/tmaxapi.h> int tpgetmysvgno(void);
Return Value
Value | Description |
---|---|
Group number | A function call was successful and the server group number of the server group that contains the service calling this API is returned. |
Example
<Server Program>
FDLTOUPPER1(TPSVCINFO *msg) { FBUF *sndbuf, *rcvbuf; int ret, i, mysvgno; char sndata[30], rcvdata[30]; char svc[XATMI_SERVICE_NAME_LENGTH]; sndbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)}; rcvbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0)) /* tpcallsvg (mysvgno) */ ret = func_tpcallsvg_myno(sndbuf, rcvbuf, msg->name); if(ret < 0) tpreturn(TPFAIL, 0, (char *)NULL, 0, 0); tpreturn(TPSUCCESS, 0, (char *)rcvbuf, 0, 0); } int func_tpcallsvg_myno(FBUF *sndbuf, FBUF *rcvbuf, char *svc) { int ret; char sndata[30], rcvdata[30]; long rcvlen; int svgno; strcpy(sndata, “starbj81”); ret = fbput(sndbuf, INPUT, sndata, 0); svgno = tpgetmysvgno(); ret = tpcallsvg(svgno, “FDLTOUPPER2”, (char *)sndbuf, 0, (char **)&rcvbuf, &rcvlen, 0); if(ret < 0) { printf("tpcallsvg[%s] failed![%d][%s]\n",svc,tperrno, tpstrerror(tperrno)); return -1; } fbprint(rcvbuf); fbinit(sndbuf, 1024); fbinit(rcvbuf, 1024); return 0; }
Related Functions
tpcallsvg(), tpacallsvg()
The tpgetmysvrid function returns a server process ID, which is a number given to a server process in the SERVER section of a configuration file. Even though numbers of same server processes are executed, different server process numbers are given. The return values start from 0, and increase by one. This function is available only in a service routine, which means it's only in a server process.
Prototype
#include <tmaxapi.h> int tpgetmysvrid(void)
Return Value
Value | Description |
---|---|
Positive number | A function call was successful and a value corresponding to a server process ID is returned as a positive number. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetmysvrid() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpgetmysvrid() was called from an invalid state. For example, from a client program. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { char *buf; buf = msg->data; data process... printf(“mysvr : %d\n”,tpgetmysvrid()); data process... tpreturn(TPSUCCESS,0,buf, strlen(buf), 0); }
The tpgetnodename function gets the name of a specified node.
Prototype
#include <tmaxapi.h> char *tpgetnodename(int nodeno)
Parameter
Parameter | Description |
---|---|
nodeno | Returns the name of a node that corresponds to a nodeno. |
Return Value
Value | Description |
---|---|
Node name | A function call was successful and a node name is returned. |
NULL | A function call failed. A tperrno is not set to an error code even though an error occurred. |
Example
#include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int i, clid, n; char *nodename; ... for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); nodename = (char *)tpgetnodename(n); if (nodename == NULL){ error processing } else { printf(“%dth node name(original node name) = %s\n”, n, nodename); } ... tpreturn(TPSUCCESS,0,(char *)msg->data, 0,TPNOFLAGS); }
The tpgetnodeno function gets a node number that corresponds to a nodename.
Prototype
#include <tmaxapi.h> int tpgetnodeno(char *nodename)
Parameter
Parameter | Description |
---|---|
nodename | Returns the node number that corresponds to a specified name. |
Return Value
Value | Description |
---|---|
Node number | A function call was successful and the number of a node is returned. |
-1 | A function call failed. A tperrno is not set to an error code even though an error occurred. |
Example
#include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int i, clid, n; char *nodename; ... for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); n = tpgetnodeno(“tmax”); if (n < 0){ error processing } else { printf(“%s’s node no(original node no) = %d\n”, “tmax”, n); } ... tpreturn(TPSUCCESS,0,(char *)msg->data, 0,TPNOFLAGS); }
The tpgetorgclh function returns the CLH to which a client is connected.
Prototype
#include <tmaxapi.h> int tpgetorgclh(int clid)
Parameter
Parameter | Description |
---|---|
clid | ID of the connected client. |
Return Value
Value | Description |
---|---|
CLH number | A function call was successful and a CLH number that a client is currently connected to is returned. |
-1 | A function call failed. A tperrno is not set to an error code even though an error occurred. |
Example
#include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int i, clid, n; ... for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); n = tpgetorgclh((int)*(msg->cltid.clientdata)); if (n < 0){ error processing } else { printf(”clh number = %d\n”, n); } ... tpreturn(TPSUCCESS,0,(char *)msg->data, 0,TPNOFLAGS); }
The tpgetornode function returns the node to which a client is connected.
Prototype
#include <tmaxapi.h> int tpgetorgnode(int clid)
Parameter
Parameter | Description |
---|---|
clid | ID of the connected client. |
Return Value
Value | Description |
---|---|
Node number | A function call was successful and the number of a node is returned. |
-1 | A function call failed. A tperrno is not set to an error code even though an error occurred. |
Example
#include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int i, clid, n; char *nodename; ... for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); n = tpgetorgnode((int)*(msg->cltid.clientdata)); if (n < 0){ error processing }else { printf(”original node number = %d\n”, n); } ... tpreturn(TPSUCCESS,0,(char *)msg->data, 0,TPNOFLAGS); }
The tpgetpeer_ipaddr function returns a peer's IP address (node) after a connection is established with a Tmax system. This function can obtain a peer's IP address only in cases where a client directly calls for a service.
If a service call is made indirectly, for example, the service a client calls is passed to or makes a call to another service, a garbage value may be entered.
Prototype
#include <tmaxapi.h> int tpgetpeer_ipaddr(struct sockaddr *name, int *namelen)
Parameter
Parameter | Description |
---|---|
name | A struct where an address is stored. In an IPv6 protocol environment, a struct sockaddr_in6 structure is used to check address information. The struct sockaddr_storage structure is available both in an IPv4 and IPv6 environment. |
namelen | First initialized to a space size allocated with a name, and then has a value corresponding to an actual name size later. |
Return Value
Value | Description |
---|---|
Socket address | A function call was successful and a peer's socket address is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetpeer_ipaddr() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPINVAL] | An invalid parameter. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <usrinc/atmi.h> #inlcude <usrinc/tmaxapi.h> ... DELETE(TPSVCINFO *msg) { struct sockaddr_in cli; char ipAddr[16]; int cli_len, ret; data process... memset((char *)&cli, 0, sizeof(cli)); ret = tpgetpeer_ipaddr((struct sockaddr *)&cli, &cli_len); if (ret == -1){ error processing } else { memcpy(ipAddr, inet_ntoa(cli.sin_addr), 16); } printf(“ip = %s , port = %d\n”, ipAddr, ntohs(cli.sin_port)); data process... tpreturn(TPSUCCESS, 0, 0, 0, 0); }
Example - IPv6 protocol environment
#include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <usrinc/atmi.h> #inlcude <usrinc/tmaxapi.h> ... DELETE(TPSVCINFO *msg) { struct sockaddr_storage cli_saddr; struct sockaddr_in *cli_sin4; struct sockaddr_in6 *cli_sin6; char ipaddrbuf[INET6_ADDRSTRLEN]; const char *ipaddr = NULL; int cli_len, ret; int portno; data process... memset((char *)&cli_saddr, 0, sizeof(cli_saddr)); cli_len = sizeof(cli_saddr); ret = tpgetpeer_ipaddr((struct sockaddr *)&cli_saddr, &cli_len); if (ret == -1){ error processing } else { if (cli_saddr.ss_family == AF_INET) { cli_sin4 = (struct sockaddr_in *)&cli_saddr; ipaddr = inet_ntop(AF_INET, &(cli_sin4->sin_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin4->sin_port); } else if (cli_saddr.ss_family == AF_INET6) { cli_sin6 = (struct sockaddr_in *)&cli_saddr; ipaddr = inet_ntop(AF_INET6, &(cli_sin6->sin6_addr), ipaddrbuf, sizeof(ipaddrbuf)); portno = ntohs(cli_sin6->sin6_port); } if (ipaddr == NULL) ipaddr = "unknown"; } printf(“ip = %s , port = %d\n”, ipaddr, portno); data process... tpreturn(TPSUCCESS, 0, 0, 0, 0); }
Related Functions
tpgetpeername(), tpgetsockname(), tpstart()
The tpgetsvcname function gets the name of the service using index. The parameter is defined using the service index value in cltid.clientdata[3] of TPSVCINFO in the Loss service routine which is called when the reply message is discarded. This function is only available in Tmax server, not in Tmax client. As the returned buffer is internal static buffer, you should copy it to additional buffer to use without changing the contents of the buffer.
Prototype
#include <tmaxapi.h> char* tpgetsvcname(int svc_index)
Parameter
Parameter | Description |
---|---|
svc_index | A service index value. |
Return Value
Value | Description |
---|---|
Service name | A function call was successful and the address of a buffer where a service name is stored is returned. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetsvcname() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | A svc_index transmitted an invalid range. |
[TPENOENT] | The svc name of a relevant svc_index does not exist. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SVC01(TPSVCINFO *msg) { int i; printf("\nSVC01 service is started!\n"); printf("INPUT : data=%s\n", msg->data); for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); printf("OUTPUT: data=%s\n", msg->data); sleep(10); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); } LOSS_SVC(TPSVCINFO *msg) { long svcindex; char *svcname; printf("\nLOSS_SVC service is started!\n"); printf("INPUT : data = %s\n", msg->data); printf("TPERROR : %d\n", msg->cltid.clientdata[1]); printf("TPURCODE : %d\n", msg->cltid.clientdata[2]); svcindex = msg->cltid.clientdata[3]; printf("SVC INDEX Of Discarded Message : %ld\n", svcindex); svcname = tpgetsvcname((int)svcindex); if(NULL == svcname) { printf("tpgetsvcname is failed!!\n"); } else { printf("SVC Name Of Discarded Message : %s\n", svcname); } tpreturn(TPSUCCESS, 0, (char*)msg->data, 0, 0); }
The tpgetsvrseqno function returns a serial number for server processes among same servers. This number is used to identify more than one operating server process with regard to MIN and MAX values in the SERVER section of a Tmax configuration file. Return values start with 0, and increase by one according to the number of operating server processes.
For example, assuming that there are five server processes operating in 'svr1', serial numbers will be given from 0 to 4 respectively. If a server process corresponding to the serial number 3 is closed, a service routine will have the server process 3 again when the server is restarted through a tmboot -s or a autorestart.
Prototype
#include <tmaxapi.h> int tpgetsvrseqno(void)
Return Value
Value | Description |
---|---|
A positive number larger than 0 | A function call was successful and a positive number which corresponds to the serial number of server processes is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetsvrseqno() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { char *buf; printf(“\nINPUT : %s\t processing svr no : %d\n”, msg->data, tpgetsvrseqno()); data process.... tpreturn(TPSUCCESS, buf, 0, ); }
The tpissetfd function is used to check if data is received in a socket fd in a UCS process. It is used for scheduling an external socket in a UCS-type server process.
Prototype
#include <ucs.h> int tpissetfd (int fd)
Parameter
Parameter | Description |
---|---|
fd | An internal fd of a fdset to be tested. |
Return Values
Value | Description |
---|---|
A positive number | A message was received. |
0 | A message was not received. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpissetfd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <usrinc/ucs.h> ... #define SERV_ADDR “168.126.185.129” #define SERV_PORT 1500 int fd_read(int, char *, int); extern int errno; int usermain(int argc, char *argv[]) { ... int listen_fd, n, newfd; struct sockaddr_in my_addr, child_addr; socklen_t child_len; buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ error processing } memset((void *)&my_addr, NULL, sizeof(my_addr)); memset((void *)&child_addr, NULL, sizeof(child_addr)); listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd == -1){ error processing } my_addr.sin_family = AF_INET; inaddr = inet_addr(SERV_ADDR); my_addr.sin_port = htons((unsigned short)SERV_PORT); if (inaddr != -1) memcpy((char *)&my_addr.sin_addr, (char *)&inaddr, sizeof(inaddr)); ret = bind(listen_fd, (struct sockaddr *)&my_addr, sizeof(my_addr)); if (ret == -1){ error processing } ret = listen(listen_fd, 5); if (ret == -1){ error processing } tpsetfd(listen_fd); ... while(1) { n = tpschedule(10); ... if (n == UCS_USER_MSG){ if (tpissetfd(listen_fd)) { child_len = sizeof(child_addr); newfd = accept(listen_fd, &child_addr, &child_len); if (newfd == -1){ error processing } tpsetfd(newfd); } if (tpissetfd(newfd)){ /* Reads a buffer from a socket */ fd_read(newfd, buf, 1024); ret = tpcall(“SERVICE”, (char *)buf, sizeof(buf), (char **)&buf, (long *)&rlen, TPNOFLAGS); if (ret == -1){ error processing } ... tpclrfd(newfd); close(newfd); } ... } } return 1; }
Related Functions
tpissetfd(), tpsetfd()
The tpissetfd_w function tests a fdset used by a UCS-type process to check if there is any data to be sent to a socket fd specified in a parameter. A tpissetfd() checks for a Readable FDSET and a Writable FDSET. FD is the socket FD value to be checked in a writable FDSET.
Prototype
#include <ucs.h> int tpissetfd_w(int fd)
Parameter
Parameter | Description |
---|---|
fd | An internal fd of a fdset to be tested. |
Return Value
Value | Description |
---|---|
Positive number | Returned when a message arrives. |
0 | Returned when a message does not arrive. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpissetfd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Related Functions
tpissetfd(), tpsetfd()
The tpprechk function is a user callback routine to check the status of a RM. This function is called before a client makes a connection to a Tmax system. All other initialization process should be processed in a tpsvrinit(). If a blocking condition occurs within a tpprechk routine, a service will have a READY status and a server will have a NOREADY status. A process can be terminated using the -i option of a tmdown.
If not using a tpprechk(), and if a blocking condition occurs while checking a RM status in a tpsvrinit routine, a service will be scheduled until a reply returns, so a client should also wait until a service timeout expires. To prevent this, a tpprechk() is called before a tpsvrinit() to check whether a RM is ready or not.
Prototype
#include <tmaxapi.h> int tpprechk(void)
Return Value
Value | Description |
---|---|
Positive number | A function call was successful. |
Negative number | A function call failed. Restart server. |
The tpregcb function sets a routine that receives a response for an asynchronous UCS request from a server. This routine is used when a UCS type process receives a response from a server program. It is used instead of a tpgetrply() in a UCS-type server process.
Prototype
# include <ucs.h> int tpregcb (UcsCallback)
Parameter
Parameter | Description |
---|---|
UcsCallback | Sets a Callback function that handles a response for an asynchronous request in a UCS. |
Value
Return Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpregcb() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
... #include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/ucs.h> void reply_receive(UCSMSGINFO *reply); DUMMY(TPSVCINFO *msg) { data process …. } int usermain(int argc, char *argv[]) { int ret; char *buf ret = tpregcb(reply_receive); if (ret == -1){ error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process… while(1) { ... tpschedule(3); cd = tpacall(“SERVICE”, buf, strlen(buf), TPNOFLAGS); if (cd < 0) { error processing } ... } } void reply_receive(UCSMSGINFO *reply) { printf(“data....%s\n”, reply->data); }
Related Function
tpunregcb()
The tprelay function is available only in a UCS server process. It can be used in multiple nodes. When a client requests a service, this function requests another service with information about the client. Since the service called by the function notices that it was called by the client, not the function, it returns a result to the client.
A service execution result can be sent to a client that called for a request, so a fast response can be induced with a simple structure in a UCS process. In general, this function is useful when processing a service, because it is integrated with an external application which is a program routine that can obtain results after calling a service two or three times.
If a server process is terminated after saving client information using a tpsavcctx() or a tpgetctx() but before a request is sent to another service using a tprelay(), an error response will be sent to a service caller automatically. For more information about error responses, refer to the CTX_EREPLY option in the SERVER section of an environment configuration. These operations are supported for Tmax versions v5.0 SP2 or later. In earlier versions, an error response will not be sent to a service caller.
Prototype
#include <ucs.h> int tprelay(char *svc, char *data, long len, long flags, CTX_T *ctxp);
Parameter
Parameter | Description |
---|---|
svc | A service name registered in a Tmax configuration file. |
data | Data to be transmitted when a service is called. If data is not NULL, it must indicate a buffer that has been allocated with a tpalloc(). |
len | The length of data to be sent. It must be specified for CARRAY, X_OCTET, and Structure array Types. |
flags | Not currently supported. Set to TPNOFLAGS. |
ctxp | An information structure retrieved through a tpgetctx() or a tpsavectx(). |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tprelay() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a ctxp is NULL or an incorrect buffer was used. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
Example
... #include <stdio.h> #include <usrinc/ucs.h> CTX_T *ctx = NULL; DUMMY(TPSVCINFO *msg) { data process …. } usermain(int argc, char *argv[]) { int ret, i; char *rcvbuf, *sndbuf; long sndlen; rcvbuf = (char *)tpalloc(“CARRAY”,NULL, 1024); if (rcvbuf == NULL){ error processing } i = 0; while(1) { tpschedule(1); if (ctx != NULL) { i++; if ((sndbuf = (char *)tpalloc(“CARRAY”,NULL, 1024)) == NULL) { error processing } else { ... ret = tprelay(“TPRETURN”, sndbuf, sndlen, 0, ctx); if (ret==-1) { error processing } data process... ctx = NULL; tpfree(sndbuf); } } } } int RELAY(TPSVCINFO *rqst) { ... ctx = tpsavectx(); tpreturn(TPSUCCESS, 0, rqst->data, rqst->len, 0); }
Related Functions
tpreturn(), tpforward()
The tpresumetx function resumes a currently terminated global transaction. A terminated global transaction can be resumed using a tpresume API such as a tpresumetx(), or a tpsuspendxt().
Prototype
#include <usrinc/tmaxapi.h> int tpresumetx(TRANID *tranid, int flags)
Parameter
Parameter | Description |
---|---|
tranid | A pointer to TRANID structure. It should be same as the pointer structure used when calling a tpresumetx(), or a tpsuspendxt() |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpresumetx() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | A traid is NULL, or flags are not TPNOFLAGS. |
[TPEPROTO] | A transaction cannot be resumed. |
[TPETRAN] | A transaction failed to restart. |
Related Function
tpsuspendtx()
The tpreturn function means the completion of a service routine. It works the same as a return sentence in the C language. When a tpreturn() is called, a service routine is returned to a Tmax system. To return a service routine correctly to a Tmax system, call a tpreturn() within a service routine.
A tpreturn() function sends a reply message for a service. If a program to receive a reply is waiting with a tpcall(), tpgetrply(),or tprecv(), the reply will be transferred through a receiver's buffer after a tpreturn() is successfully called.
A tpreturn() also allows interactive services to terminate interactive communication. A service routine cannot call a tpdiscon() directly. To ensure a correct result, a program connected to an interactive service should not to call a tpdiscon(). Rather, it must wait for a completion notification from an interactive service, for example, an event like a TPEV_SVCSUCC or a TPEV_SVCFAIL transmitting with a tpreturn().
If a service routine is in a transaction mode, and a client or service that called a service does not start a transaction explicitly (if tx_begin is not used), then a tpreturn will be committed or rolled back as a part of a transaction when tpreturn is TPSUCCESS. A service can be called to multiply as a part of a same transaction (global transaction), therefore, it is will not be completely committed or rolled back until a transaction beginner calls either a tx_commit or a tx_rollback to complete a transaction.
A tpreturn() function must be called after all replies are received from services requested by a service routine. Otherwise, a [TPESVCERR] error or a TPEV_SVCERR event will be returned to the program that communicated with a service routine that depended on the service characteristics. Replies that are not received are automatically ignored by a Tmax system. In addition, the descriptors used for these replies will also be invalidated.
A tpreturn() function must be called after all connections that began from a service used for interactive communication are ended. Otherwise, either a [TPESVCERR] error or a TPEV_SVCERR event will be returned to the program that communicated with a service routine that depended on the service characteristics. In addition, a forcible disconnection event, such as a TPEV_DISCONIMM, will be transferred to a service and all items that are connected to the service.
In an interactive communication, if a service routine does not have communication control when it calls a tpreturn(), two results may happen:
If a service routine calls a tpreturn() with a rval of a TPFAIL and data is NULL, a TPEV_SVCFAIL event will be transferred to a communication starter.
When a tpreturn() is called in other ways, a TPEV_SVCERR event will be transferred to a communication starter. Because an interactive service must have only one interactive communication that does not start from a service, a Tmax system knows the descriptor to which data or an event that is to be transmitted. For this reason, a descriptor is not transferred to a tpreturn() as a parameter.
Prototype
# include <atmi.h> void tpreturn (int rval, long rcode, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
rval | The values available for a rval are explained in the following table. If a rval is not explained in the table, it will be considered as TPFAIL. |
rcode | The return code a rcode defines in an application program can be transmitted to a program that receives a service reply. This code will be transmitted, regardless of a rval value, as long as a reply can be transmitted to a client successfully. The client is considered to have received a reply successfully in the following cases: A receiving call was a success or a reply was returned through a [TPSVCFAIL], or the client received either a TPEV_SVCSUCC or a TPEV_SVCFAIL event. A rcode value is transferred to a receiver with a tpurcode global variable. |
data | Reply data to be sent. If it is not NULL, it must indicate a buffer that was allocated by tpalloc() before. If the buffer is the same as the one transferred to the service routine, the Tmax systems will handle it. Therefore, the service routine writer does not need to take care of whether to or not to free the buffer. Indeed, if a user attempts to free the buffer, the attempts will fail. However, if the buffer transferred with tpreturn() is not the same as the one transferred along with the service request, the tpreturn() will free the buffer. |
len | Data length to be sent. If data indicates a buffer that does not require specifying the length, the len will be ignored (0 is used in general). But if data indicates a buffer that needs to specify the length, the len must not be 0. If data is NULL, the len is ignored. In this case, if the program that calls the service is waiting for a reply, the reply without any data will be transmitted. If no reply is expected, the tpreturn() will free the data and returns without transmitting any reply, accordingly. |
flags | Not currently supported. Set to 0. If the service is an interactive type, data would not be transferred in the following two cases: The interactive service was already disconnected when tpreturn( ) is called. That is, the caller receives TPEV_DISCONIMM event. In this case, the tpreturn() simply ends the service routine and if it is in a transaction mode, it will roll back the current transaction. In this case, the caller's data cannot be transferred. If the caller does not have the communication control, either TPEV_SVCFAIL or TPEV_SVCERR event will be transferred to the communication starter as mentioned earlier. Regardless of the event that the communication starter receives, no data is transferred. If the communication starter receives the TPEV_SVCFAIL event, the return code could be used as a tpurcode variable of the starter. |
The following values are available for the rval parameter.
rval Value | Description |
---|---|
TPSUCCESS | The service is successfully completed. If data exists and no error occurs during tpreturn() execution, the data will be transmitted. If the caller is in a transaction mode, a part of this transaction will be determined as it can be committed. It allows the other services belonging to the transaction to be committed if all of them are successfully completed and ready for commit. But the transaction will be rolled back if any of them fails. Note that calling the tpreturn() does not mean to complete the entire transaction. In addition, if there is any waiting reply or inter active connection or a job performed within the service tries to roll back the transaction, the message will be sent as a failure even though the caller has returned TPSUCCESS. That is, the receiver of the reply will receive [TPESVCERR] error or TPEV_SVCERR event. Note that, if transaction is rolled back within a service routine, rval is set to TPFAIL. If TPSUCCESS returns in an interactive, TPEV_SVCSUCC even will occur. |
TPFAIL | .The service is ended due to an error in an application program. The error is returned to the program that receives the reply. That is, the call to receive the reply fails and the receiver receives [TPSVCFAIL] value or TPEV_SVCFAIL event. This value cannot sent data. If the caller is in a transaction mode and is autotransaction, tpreturn() will roll back the transaction. The transaction might have already been determined to be rolled back. |
TPEXIT | When a service is returned, this flag is used to forcibly terminate the server process. The process closed via tpexit() can be restarted through TMM. |
TPDOWN | Similar to TPEXIT, but the process terminated through TPDOWN is not restarted using TMM. |
TMSUCCESS | Same as TPSUCCESS. |
TMFAIL | Same as TPFAIL. |
Return Value
The service routine does not return any value to the caller, that is, the Tmax systems. It is a rule that the service routine returns with tpreturn(). If the service routine returns using return sentence of C language, rather than using the tpreturn() , the server will return a service error to the service requester. In addition, connection that has been kept for interactive communication is disconnected forcibly and all the replies that are waiting asynchronously waiting are ignored.
If the server is in a transaction mode, the transaction will be rolled back. In addition, if tpreturn() is used outside the service routine, it will simply return without performing anything.
Error
Since tpreturn() ends a service routine, if an error occurs while a parameter is being processed, it cannot be not transferred to the service routine, the caller.Errors are sent as follows.
Classification | Description |
---|---|
Synchronous and Asynchronous communication | tperrno is set to [TPESVCERR] for a program that receives a service result through tpcall() or tpgetrply(). |
Interactive communication | Generates a TPEV_SVCERR event for the program that uses tpsend() or tprecv(). |
Example
#include <stdio.h> #include <usrinc/atmi.h> SERVICE1(TPSVCINFO *msg) { char *buf; long len; buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processsing } buf=msg->data; data process.... ret=tpcall(“SERVICE2”, buf, sizeof(buf), &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process.... if (buf !=”SUCCESS”) { printf(“svc fail..\n”); tpreturn (TPFAIL, -1, NULL,0,0); } else { tpreturn(TPSUCCESS, 0, msg->data, msg->len, 0); } }
Related Functions
tpalloc(), tpcall(), tpconnect(), tpdiscon(), tpgetrply(), tprecv(), tpsend()
The tpsavectx function manages client information in a UCS process. This function is used along with a tprelay(), which forwards a request to another service. It works in the same way as a general service program, which calls for other services as a tpforward(). Consequently, a called service sends a processing result to a client.
A tpsavectx() function can be used to communicate with an external process that has heterogeneous protocols that are time-consuming and can block channels.
The function can be used in the following format:
Client → svc1 → svc2(service, tpsavectx) → External Channel Client ← svc3 ← svc2(usermain, tprelay) ← External Channel
A client makes a service request to svc1.
svc1 calls svc2 using a tpforward (...TPNOREPLY).
svc2 is a service which runs in a UCS process, and it calls a tpsavectx() in a service routine to save client information to communicate with an external system.
A result is sent to a usermain and forwarded to svc3 via a tprelay(). svc3 considers that svc2 has called it via a tpforward(), so it finally sends a result to the client.
In this process, because svc1 calls a service via a tpforward with a flag set to TPNOREPLY, it can prevent channel congestion. This enables a large numbers of clients to be handled with a small number of processes. Additionally, a single UCS process can act as both a sending and receiving process. It can organize a relatively simple system with efficient system management.
Prototype
#include <ucs.h> CTX_T * tpsavectx(void)
Return Value
Value | Description |
---|---|
CTX_T | A function call was successful. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tpsavectx() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpsavectx() must be used within a service routine. Otherwise, TPEPROTO will be returned. Accordingly, it cannot be used with a tpsvrinit() or a tpsvrdone(). |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. The error occurred during memory allocation. |
Example
... #include <stdio.h> #include <usrinc/ucs.h> CTX_T *ctx = NULL; usermain(int argc, char *argv[]) { int ret, i; char *rcvbuf, *sndbuf; long sndlen; rcvbuf = (char *)tpalloc(“CARRAY”,NULL, 1024); if (rcvbuf == NULL){ error processing } i = 0; while(1) { tpschedule(1); if (ctx != NULL) { i++; if ((sndbuf = (char *)tpalloc(“CARRAY”,NULL, 1024)) == NULL) { error processing } else { ... ret = tprelay(“TPRETURN”, sndbuf, sndlen, 0, ctx); if (ret==-1) { error processing } data process... ctx = NULL; tpfree(sndbuf); } } } } int RELAY(TPSVCINFO *rqst) { ... ctx = tpsavectx(); tpreturn(TPSUCCESS, 0, rqst->data, rqst->len, 0); }
Related Functions
tpreturn(), tpforward(), tprelay()
The tpschedule function waits for data to be received in a UCS-type server process. It is available only in a UCS-type server process. A tpschedule() sleeps until a maximum timeout value and returns data immediately when data is received.
A tpschedule() function is returned after a corresponding service is automatically executed when data is received. Therefore, a user must not execute any service after data is received.
Note that this is an UCS-type service program, so a service will be performed unconditionally by systems.
Prototype
#include <ucs.h> int tpschedule(int timeout)
Parameter
Parameter | Description |
---|---|
timeout | The amount of time to wait in seconds.
|
Return Value
Value | Description |
---|---|
Positive Integer | A function was performed successfully so data will be received. |
-1 | Data was not received until a timeout or an error occurred due to a function execution failure. If data was not received until a timeout, -1 will be returned and the number 13 error (TPETIME) will be set in a tperrno. In other cases, an error code will be set in a tperrno. |
Error
When a tpschedule() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
[TPETIME] | Data was not received before a timeout. |
[TPEPROTO] | A tpschedule() was called from an invalid state. For example, a tpschedule() was called within a service. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/ucs.h> int usermain(int argc, char *argv[]) { ... while(1) { ... tpschedule(3); ret = tpcall(“SERVICE”, (char *)buf, strlen(buf), (char **)&buf, (long *)&rlen, TPNOFLAGS); if (ret == -1) { error processing} ... } }
Related Functions
tpsleep(), tp_sleep(), tp_usleep()
This function is available in a server. The tpsendtocli function sends an unrequested message to a specified client. While a tpbroadcast() function sends an unrequested message to any client connected to a Tmax systems, this function sends a message only to a client that has requested a service provided by a server process.
Prototype
# include <tmaxapi.h> int tpsendtocli (int clid, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
clid | A unique client number obtained with a tpgetclid(). |
data | A buffer allocated by a tpalloc(). If data indicates a buffer that does not require a specific length, a len is ignored (0 is used in general). If data indicates a buffer that needs to have a length specified, a len must not be 0. In addition, when data is NULL, a len will be ignored. |
len | A buffer length to be transmitted. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOFLAG(0) | Messages must be received by a client. However it might take a long time for a client to receive a requested result if a client cannot process received messages fast enough. |
TPUDP | This flag does not mean that data communication with a client is UDP. When a caller transmits data, it is impossible to transfer the data because the internal buffer that the data is transmitted to is filled with messages to be transferred. This flag means that data may be discarded in that situation. In other words, it means that data might be lost similarly to a communication in a UDP. |
TPFLOWCONTROL | Checks the status of a client to decide whether another request message can be sent or not. If there are too many accumulated messages, a tpsendtocli() will return a value of -1 and a tperrno will be set to TPEQFULL. This flag is used to reduce the load of a Tmax system. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsendcli() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid clid. |
[TPEPROTO] | A tpsendcli() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
[TPEQFULL] | A duplicate message exists. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> SERVICE(TPSVCINFO *msg) { int ret, clid; char *buf; buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } strcpy(buf, msg->data); data process…. clid = tpgetclid(); if (clid==-1) { error processing } ret=tpsendtocli(clid, (char *)buf, 0, 0); if (ret==-1) { error processing } tpreturn(TPSUCCESS, 0, 0, 0); }
Related Function
tpbroadcast()
The tpsetdbsessionid function is a callback function that is used to configure RM session information to avoid the inconvenience of processing RM session information in a service.
Prototype
#include <usrinc/tmaxapi.h> int tpsetdbsessionid (char dbsessionid[MAX_DBSESSIONID], int flags);
Parameter
Parameter | Description |
---|---|
dbsessionid | A developer creates this routine then gets and stores an id value in a dbsessionid. A Tmax engine calls a tpsetdbsessionid routine every time it connects to a RM to update a session id to the latest and internally manage it. |
flags | Not currently supported. Set to TPNOFLAGS. |
Example
#include <usrinc/tmaxapi.h> ... EXEC SQL include sqlca.h; EXEC SQL begin declare section; ... char h_ssid[20]; EXEC SQL end declare section; int tpsetdbsessionid(char dbsessionid[MAX_DBSESSIONID_SIZE], int flags) { EXEC SQL SELECT TO_CHAR(USERENV(‘sessionid’)) into :h_ssid FROM dual; if ( sqlca.sqlcode != 0 ){ printf( “getting session id fail = %d\n”,sqlca.sqlcode ); return -1; } printf(“RM session id = %s\n”, h_ssid); memset(dbsessionid, 0x00, MAX_DBSESSIONID_SIZE); strcpy(dbsessionid, h_ssid); return 0; } FDLINS( TPSVCINFO *msg ) { ... }
The tpsuspendtx function suspends a currently running global transaction in order to start a new transaction. Resources of a suspended transaction will keep an ACTIVE status. For example, if a transaction timeout occurs, a transaction will be rolled back. A suspended transaction can be resumed using a ttpresumetx() or a tpsuspendxt().
Prototype
#include <usrinc/tmaxapi.h> int tpsuspendtx(TRANID *tranid, int flags)
Parameter
Parameter | Description |
---|---|
tranid | A pointer to a TRANID structure that should be assigned by developer. It is set to a current transaction ID. |
flags | Not currently supported. Set to TPNOFLAGS. |
Example
SVC_TRAN( TPSVCINFO *msg ) { str sndbuf; char *rcvbuf; char tmp[4096]; int cd, ret; long rlen; /********************************************************* TSR(Transaction Suspend and Resume) - TPTRANID Structure *********************************************************/ TPTRANID *tranid = (TPTRANID *)malloc(sizeof(struct tptranid)); sndbuf = (str)msg->data; rcvbuf=(char *)tpalloc(“STRING”, NULL, 4096); h_empno = sndbuf->empno; h_sal = sndbuf->sal; strcpy( h_ename, sndbuf->ename ); strcpy( h_job , sndbuf->job ); strcpy( h_date , sndbuf->date ); ret = tx_begin(); cd = tpcall(“ORGTRAN1”, (char *)msg->data, msg->len, (char **)&rcvbuf, (long *)&rlen, 0); strcpy(tmp, rcvbuf); /********************************************************* TSR(Transaction Suspend and Resume) - Suspend is Started *********************************************************/ Ret = tpsuspendtx(tranid, 0) cd = tpcall(“NEWTRAN”, (char *)msg->data, msg->len, (char **)&rcvbuf, (long *)&rlen, 0); strcat(tmp, rcvbuf); /******************************************************** TSR(Transaction Suspend and Resume) - Resume is Started ********************************************************/ ret = tpresumetx(tranid, 0); cd = tpcall(“ORGTRAN2”, (char *)msg->data, msg->len, (char **)&rcvbuf, (long *)&rlen, 0); ret = tx_commit(); tpreturn( TPSUCCESS, 0, rcvbuf, strlen(rcvbuf), 0 ); }
A routine called when a service timeout occurs. When a service timeout occurs, a server program will automatically call a tpsvctimeout() function. If a user redefines a function, a relevant function will be called.
If a SVCTIMEOUT occurs in a xa_commit() or a xa_rollback() stage for a tx_commit() or a tx_rollback() execution, a tperrno will be set to TPETRAN for this functions referance.
Prototype
# include <tmaxapi.h> void tpsvctimeout(TPSVCINFO *msg)
Parameter
Parameter | Description |
---|---|
msg | A message used when calling a service where a timeout occurred. |
Return Value
A tpsvctimeout() is designed to perform the actions required in a service timeout. There is no return value and no errors can occur.
Example
#include <stdio.h> #include <usrinc/atmi.h> SERVICE(TPSVCINFO *msg) { ... tpreturn(TPSUCCESS,0,(char *)msg->data, 0,TPNOFLAGS); } void tpsvctimeout(TPSVCINFO *msg) { ... tpreturn(TPFAIL, TPETIME, (char *)buf, sizeof(buf), TPNOFLAGS); }
The tpsvrdone function sets a routine to be executed when a UCS-type server process is terminated. A separate main of Tmax application server program, i.e., the main() provided by the Tmax systems calls tpsvrdone() before ending a process after finishing all service request handling. When this routine is executed, a server process will still be a part of Tmax but the process will not provide service. It is possible to execute a Tmax communication or define a transaction within the tpsvrdone() routine.
If the tpsvrdone() is keeping an interactive connection, is waiting for asynchronous replies, or returns during a transaction mode, Tmax will disconnect the interactive connection, ignore the asynchronous replies that have been waiting, and stop the transaction. Then, the server will be terminated immediately.
If a program does not provide a tpsvrdone() routine, a default routine provided by Tmax can be called instead. If a server belongs to a server group that processes transactions, the default tpsvrdone() routine will call tx_close() and userlog() to notify that a server will be terminated. If either tpreturn() or tpforward() are called within tpsvrdone(), a routine will simply return without performing any operations.
Prototype
# include <tmaxapi.h> int tpsvrdone(void)
Return Value
A tpsvrdone() is a function used to perform necessary jobs before a developer ends a server process. Due to this, it does not have a return value and an error cannot be generated.
Example
#include <stdio.h> #include <usrinc/atmi.h> EXEC SQL INCLUDE sqlca.h; SERVICE(TPSVCINFO *msg) { int ret, cd; char *buf; EXEC SQL begin declare section; …. EXEC SQL end declare section; EXEC SQL CONNECT : scott IDENTIFIED BY : tiger; buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process…. cd=tpgetclid(); if (cd==-1) { error processing } ret=tpsendtocli(cd, buf, 0, TPNOFLAGS); if (ret==-1) { error processing } data process.... tpsvrdone(); } void tpsvrdone() { printf(“ Sevice end\n”); EXEC SQL COMMIT WORK RELEASE; }
Related Functions
tx_close(), tpsvrinit()
The tpsvrdown function is used to properly terminate a UCS-type server process. A UCS-type server process is generally used for communication with an external system. Banking systems are an example. If an error occurs in an external system that communicates with a banking system, this function will terminate a UCS-type server process so that a service call is no longer sent to that external system. This can prevent unnecessary resource usage and also reduce overloading external systems.
Prototype
#include <ucs.h> int tpsvrdown(void)
Return Value
A tpsvrdown() is used to perform necessary jobs before a developer ends a server process, so it does not have a return value.
Example
... #include <usrinc/atmi.h> #include <usrinc/ucs.h> int usermain(int argc, char *argv[]) { count=0; ... while(1) { ... tpschedule(3); cd = tpacall(“SERVICE”, buf, strlen(buf), TPNOREPLY); if (cd < 0) { error processing } ... if (count == 10) tpsvrdown(); } } void reply_receive(UCSMSGINFO *reply) { printf(“data....%s\n”, reply->data); }
Related Functions
tpsvrinit(), tpsvrdone()
The tpsvrinit function processes an initialization of a service routine. This function is called for initializing the main procedure of a Tmax application server program. This routine is called after a server process is executed but no service request has been processed. It is possible to execute Tmax communications or define a transaction within the tpsvrinit() routine.
If the application program does not provide tpsvrinit(), default routine provided by the Tmax is called instead. If the server belongs to a server group that processes transactions, tpsvrinit() calls tx_open() and userlog(), to inform that the server has started successfully.
Command line parameters (CLOPT) of an application program can be transferred to the server, to be processed by tpsvrinit(). See CLOPT item of SERVER section of tmax configuration file. The parameters are transferred through argc and argv.
As getopt() is used within the Tmax server main, optarg, optind and opterr are used for parameter parsing and error detection within the tpsvrinit() .
Prototype
# include <tmaxapi.h> int tpsvrinit (int argc, char **argv)
Parameter
Parameter | Description |
---|---|
argc | The number of command line parameters. |
argv | A command line parameter. |
Return value
Value | Description |
---|---|
0 | A function call was successful. |
Negative number | A function call failed. No service requests are received and a server process is terminated without generating an error. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> EXEC SQL INCLUDE sqlca.h; tpsvrinit(int argc, char **argv) { EXEC SQL begin declare section; char user_name[30]; char user_passwd[30]; EXEC SQL end declare section; EXEC SQL CONNECT scott IDENTIFIED BY tiger; return(0); } SERVICE(TPSVCINFO *msg) { int ret, cd; char *buf; buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... cd=tpgetclid(); if (cd==-1) { error processing } ret=tpsendtocli(cd, buf, 0, TPNOFLAGS); if (ret==-1) { error processing } data process.... printf(“ Sevice end\n”); EXEC SQL COMMIT WORK RELEASE; tpreturn(TPSUCCESS, buf, strlen(buf), 0); }
Related Functions
tx_open(), tpsvrdone()
The tpsvrthrdone function is provided only by Multithread and Multicontext servers. A MultiThread and a MultiContext server terminates service threads before performing a tpsvrdone when a server process is terminated. If this function is defined, a service thread will call this function automatically when it is terminated. Developers needs to write a routine to process required jobs before a thread is terminated. In this function, a Tmax communication or a transaction can be performed. If a function is returned without completing jobs, all incomplete jobs will be ignored when a thread is terminated.
A client can allocate other previously created context to a current client using a function. Most ATMI functions are per-context based. A client can use multiple contexts, but only one context is used at a time. For example, if context1 calls a tpacall(), context1 must be set as the current context at the moment of calling a tpgetrply() to perform a tpgetrply() normally even when other context was used. For more information, refer to "3.2.50. tpsvrdone".
Prototype
# include <tmaxapi.h> int tpsvrthrdone(void)
Return Value
A tpsvrthrdone() is written by a developer to perform necessary jobs before terminating a server process. This function neither has any return value nor generates an error.
Example
Refer to example in the tpsvrthrinit() topic.
Related Function
tpsvrthrinit()
The tpsvrthrinit function is provided only by Multithread and Multicontext servers. A Tmax server provides a tpsvrinit function that performs an initialization process when a server process starts. Multithread and Multicontext servers provide an initialization function for each thread when a thread is created for service threads managed by a thread pool after a tpsvrinit function is called.
A thread pool works according to MINTHR and MAXTHR fields, so when a server process initially starts, the same number of service threads will be created as the number set in MINTHR and they will call a tpsvrthrinit(). After that, if there are no idle service threads in a thread pool, service threads will be created as needed up to a value set as a MAXTHR. If MINTHR is 0, no service threads will be created when a process starts, so only a upsvrinit() will be called and the process will wait until a service request is received.
This function is processed after a tpsvrinit() is called and before each thread handles a service request. The same parameters with those delivered to a tpsvrinit() are delivered. These parameters are set in a CLOP field in the SERVER section of a configuration file. When writing this function, a user must remember that the parameters delivered to a spsvrinit() and a tpsvrthrinit() must be the same. For more information, refer to "3.2.52. tpsvrinit".
Prototype
# include <tmaxapi.h> int tpsvrthrinit (int argc, char **argv)
Parameter
Parameter | Description |
---|---|
argc | The number of command line parameters. |
argv | A command line parameter. |
Return Value
When performing an initialization using a tpsvrthrinit(), if a process fails, a user will return -1. After a server process calls a tpsvrthrinit(), if -1 is returned, the server process will cancel the starting process and will be terminated.
Value | Description |
---|---|
0 | A function call was successful. |
Negative number | A function call failed. |
Example
#include <stdio.h> #include <pthread.h> #include <usrinc/atmi.h> void tpsvrthrinit(int argc, char **argv) { param_t *param; param = get_threadspecificdata(); if (pthread_create(¶m->tid, NULL, THREAD_ROUTINE, (void *)param) != 0) { printf("user_create_thread failed\n"); return -1; } pthread_mutex_init(¶m->mutex, NULL); pthread_cond_init(¶m->cond, NULL); return 0; } void tpsvrthrdone() { void *ret; param_t *param; param = get_threadspecificdata(); param->state = EXIT; pthread_cond_signal(¶m->cond); pthread_join(param->tid, &ret); pthread_mutex_destroy(¶m->mutex); pthread_cond_destroy(¶m->cond); printf("user_create_thread destroyed\n"); } SERVICE(TPSVCINFO *msg) { param_t *param; param = get_threadspecificdata(); ... ret = tpgetctxt(¶m->ctxtid, TPNOFLAGS); ret = pthread_cond_signal(¶m->cond); ... } void *THREAD_ROUTINE(void *arg) { param_t *param; param = (param_t *)arg; while(1) { pthread_mutex_lock(¶m->mutex); { pthread_cond_wait(¶m->cond, ¶m->mutex); if (param->state == EXIT) break; if (tpsetctxt(param->ctxtid, TPNOFLAGS) == -1) { printf("tpsetctxt(%d) failed, [tperrno:%d]", param->ctxtid, tperrno); return NULL; } tpcall("MTOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, TPNOFLAGS); ... if (tpsetctxt(TPNULLCONTEXT, TPNOFLAGS) == -1) { printf("tpsetctxt(TPNULLCONTEXT) failed, [tperrno:%d]", tperrno); return NULL; } ... } pthread_mutex_unlock(¶m->mutex); } return NULL; }
Related Funciton
tpsvrthrdone()
The tptsleep function waits for the arrival of a server process termination event to be sent from a TMM. If a client must wait within a tpprechk() call back routine, a tptsleep() should be periodically called to perform a tmdown normally.
Prototype
#include <usrinc/tmaxapi.h> int tptsleep(struct timeval *timeout)
Parameter
Parameter | Description |
---|---|
timeout | A timeout for a termination event. This timeout value is the same as that of the select() system call. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. |
Example
int tpprechk(void) { struct timeval timeout; int ret; timeout.tv_sec = 5; timeout.tv_usec = 0; while(1) { ret = tptsleep(&timeout); ... } return 0; }
The tpunadvertise function unadvertises a service that is provided by a server process from a server. A specific service name can be advertised and unadvertised.
When a server process advertises a new service that is provided by a server, the service name will be advertised in a service name table which is managed by a CLH for each server. When unadvertising a service, its name will be unadvertised from the table. If an unadvertised service is called, the tpunadvertise function will receive a TPENOENT error.
The following describes the functionality of each service:
Classification | Description |
---|---|
Service registered in a configuration file | A service status is changed to UNADV. If a service is called, a TPENOENT error will be received. |
Service registered with mksvr | A service status is changed to UNADV. If a service is called, a TPENOENT error will be received. If all processes in a server have ended, the service will be automatically removed. |
Newly registered service | A service status is changed to UNADV. If a service is called, a TPENOENT error will be received. If all processes in a server have ended, the service will be automatically removed. |
Prototype
#include <atmi/usrinc.h> int tpunadvertise(char *svcname);
Parameter
Parameter | Description |
---|---|
svcname | A service name to be unadvertised. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpunadvertise() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | A svcname is NULL. |
[TPENOENT] | A service does not exist. |
[TPELIMIT] | The length of a svcname exceeds a specified length. |
[TPEPROTO] | A tpunadvertise() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <usrinc/atmi.h> SVC2TN_2( TPSVCINFO *msg ) { int ret; char input[MAXLEN]; memset(input, 0x00, MAXLEN); strncpy(input, msg->data, msg->len); ret = tpunadvertise(input); if (ret < 0) { tpreturn(TPFAIL, tperrno, (char*)msg->data, msg->len, 0); } tpreturn(TPSUCCESS, 0, (char*)msg->data, msg->len, 0); }
The tpunregcb function is used to reset a routine that receives a response for an asynchronous request. It is used in a UCS-type server process.
Prototype
#include <ucs.h> int tpunregcb (void)
Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpunregcb() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
... #include <usrinc/atmi.h> #include <usrinc/ucs.h> void reply_receive(UCSMSGINFO *reply); int usermain(int argc, char *argv[]) { ... ret = tpregcb(reply_receive); if (ret == -1){ error processing } ret = tpunregcb(); if (ret == -1){ error processing } while(1) { ... tpschedule(3); cd = tpacall(“SERVICE”, buf, strlen(buf), TPNOFLAGS); if (cd < 0) { error processing } ... } } void reply_receive(UCSMSGINFO *reply) { printf(“first reply receive\n”); printf(“data....%s\n”, reply->data); }
See also
tpregcb()
The tpuschedule function waits for data to be received in a UCS-type server process. It is available only in UCS-type server processes. A tpuschedule() will sleep until a maximum timeout value is reached and will return data immediately when data is received.
Prototype
#include <ucs.h> int tpuschedule (int timeout)
Parameter
Parameter | Description |
---|---|
timeout | The amount of time to wait in microseconds.
|
Return Value
Value | Description |
---|---|
0 | Data was not received before a timeout. |
Positive integer | Data was received before a timeout. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpuschedule() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
... #include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/ucs.h> int usermain(int argc, char *argv[]) { ... while(1) { ... tpuschedule(3000000); ret = tpcall(“SERVICE”, (char *)buf, strlen(buf), (char **)&buf, (long *)&rlen, TPNOFLAGS); if (ret == -1) { error processing } ... } }
Related Function
tpschedule()
The tx_close function closes a connection with resource managers.
A x_close() function closes a connection between a caller and all resource managers. Because this function is used in place of calling a specific connection closing functions for each resource manager, an application program does not need to use specific connection closing calls for each resource manager, since that may cause a problem in portability. As the connection closing method varies with each resource manager, information required to close connections to individual resource managers must be prepared by each resource manager respectively.
A tx_close() function must be called when an application process no longer participates in a global transaction. If a caller is in a transaction mode, a tx_close() function call will fail and return a [TX_PROTOCOL_ERROR] which closes connections with a resource manager.
Prototype
# include <tx.h> int tx_close(void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful and the connections to all resource managers connected to a process are closed. |
Negative number | A function call failed. A tperrno is set to an error code. |
Error
When tx_close() fails to execute, one of the following values is returned.
Error Code | Description |
---|---|
[TX_PROTOCOL_ERROR] | A tx_close() was called from an invalid state. For example, a caller was in a transaction mode. No connections with a resource manager are closed. |
[TX_ERROR] | A transaction manager or a resource manager momentarily encountered an error. Exact causes of the error depend on product characteristics. All available connections with resource managers are closed. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
…. int tpsvrinit(int argc, char *argv[]) { int ret; ret = tx_close(); if (ret < 0){ error processing } ret = tx_open(); if (ret < 0){ errror processing } } int tpsvrdone() { int ret; ret = tx_close(); if (ret < 0) { error processing } }
Related Function
tx_open()
The tx_open function opens a connection with its related resource manager. As this function is called internally, a user does not need to manually use it. As connection opening methods varies with each resource manager, a tx_open() causes a transaction manager to transfer specific connection information for each resource manager to the resource manager related with the caller.
A tx_open() function opens a connection between an application program and all resource managers. Because this function is used in place of calling a specific connection opening function for each resource manager, an application program does not need to use specific connections to open a call for each resource manager, since that may cause a problem in portability. As connection opening methods varies with each resource manager, each resource manager must prepare information required to open connections with individual resource managers respectively. When an application program accesses an unconnected resource manager, a specific error for a resource will be returned. A tx_open() function must successfully return before a process participates in a transaction.
Once a tx_open() returns successfully, it does not matter whether another tx_open()function is called, until a tx_close() is called. Once an application program is connected with resource managers, a transaction manager will return successful calls only without re-connecting with any other resource manager even if a tx_open() is called again. A tpopen() is the same as a tx_open().
Prototype
# include <tx.h> int tx_open(void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. The caller has been connected to part of or all resource managers. |
Negative number | A function call failed. A tperrno is set to an error code. |
Error
When a tx_open() fails to execute, one of the following values is returned.
Error Code | Description |
---|---|
[TX_ERROR] | A transaction manager or a resource manager momentarily encountered an error. An application program is not connected with any resource manager. Exact causes of the error differ depend on product characteristics. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of the error differ depend on product characteristics. |
Example
int tpsvrinit(int argc, char *argv[]) { int ret; ret = tx_close(); if (ret < 0){ error processing } ret = tx_open(); if (ret < 0){ errror processing } } int tpsvrdoen() { int ret; ret = tx_close(); if (ret < 0){ error processing } }
Related Function
tx_close()
The gettpurcode function returns a urcode that is set in a urcode service. The function is used to get a second argument value of a tpreturn() from a client. The value can be used as an additional communication method between a client and a service program. For example, it can be used to return a corresponding error number for a client for a specific error handling routine.
Prototype
#include <atmi.h> long gettpurcode(void)
Return Value
Returns a urcode.
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char* argv[]) { char *buf; long len; int ret; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret==-1) {error processing } printf(“urcode from SERVICE Return: %d”, gettpurcode()); data process.... tpend(); }
For more information about a gettpurcode, refer to "Tmax Programming Guide (Dynamic Library)".
The tpchkunsol function is used by a client to trigger checking for unsolicited messages. A client should call function handling for unsolicited message after issuing a tpsetunsol(), tpcall() or tpacall(). Accordingly, a call to this function allows a user to check whether there are any unsolicited message in advance before calling a tpcall() or tpacall().
Prototype
#include <usrinc/tmaxapi.h> int tpchkunsol(void)
Return Value
Value | Description |
---|---|
The number of messages | A function call was successful and the number of unsolicited messages sent is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpchkunsol() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occurs if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEPROTO] | To call a tpchkunsol(), the flag of a TPSTART_T structure in a tpstart() or a tpsetunsol_flag should be set to TPUNSOL_HND. If this flag is not set, a call will fail with a [TPEPROTO] error. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/ucs.h> #include <usrinc/tmaxapi.h> void get_unsol(char *data, long len, long flag) { printf(“unsolicited data = %s\n”, data); } int main(int argc, char *argv[]){ char *sndbuf; char *rcvbuf; long rcvlen; int RecvCnt = 0; TPSTART_T *tpinfo; tpinfo = (TPSTART_T *)tpalloc(« TPSTART », NULL, sizeof(TPSTART_T)); if (tpinfo == NULL) { printf(“tpalloc failed !<-tpinfo\n”); exit(1); } strcpy(tpinfo->usrname, “starbj81”); strcpy(tpinfo->cltname, “client”); if(tpstart((TPSTART_T *)tpinfo) == -1) { fprintf(stderr, “tpstart error\n”); exit(1); } tpsetunsol_flag(TPUNSOL_HND); tp_sleep(5); if(tpsetunsol(get_unsol) == TPUNSOLERR) printf(“tpsetunsol failed..\n”); RecvCnt = tpchkunsol(); if(RecvCnt < 0) printf(“tpchkunsol failed\n”); else printf(“Received Unsol Data Count : %d\n”, RecvCnt); if((sndbuf = (char *)tpalloc(“CARRAY”, NULL, 1024)) == NULL) error processing if((rcvbuf = (char *)tpalloc(“CARRAY”, NULL, 1024)) == NULL) error processing if((cd = tpcall(“LOGIN”, sndbuf, 1024, (char **)&rcvbuf, (long *)&rcvbuf, 0)) == -1) error processing printf(“After tpacall() received Message from server:%s\n”, rcvbuf); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Functions
tpsetunsol(), tpsetunsol_flag()
The tpend function disconnects a client from a Tmax system. If a client is in a transaction mode, a transaction will be rolled back automatically. If a tpend() is returned successfully, a caller will not communicate with any other programs and will not participate in any transactions. Maintained interactive connections will be terminated immediately.
If a tpend() is called more than once (if called again after already being disconnected from a Tmax system), a -1 value will be returned without affecting a system.
Prototype
# include <atmi.h> int tpend (void)
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpend() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpend() was called from an invalid state. For example, a caller is a server or a tpend() was called after being disconnected. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen, sndlen; int ret; ret=tpstart((TPSTART_T *)NULL) if (ret==-1) {error processing } buf = (char *)tpalloc(“STRING”, NULL, 0) if (buf=NULL) { error processing } data process … ret=tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process … printf(“ data: %s\n”, buf); tpfree((char *)buf); tpend(); }
Related Function
tpstart()
The tpgethostaddr function checks a connectivity status to a Tmax System from a Tmax Client or looks up the IP/PORT information of a Tmax system.
Prototype
#include <tuxatmi.h> int tpgethostaddr(int *ip, int *port, long flags);
Parameter
Parameter | Description |
---|---|
ip | Specifies an IP address of a client. As an IP address is the s_addr field in a sockaddr_in struct, to change into a dot format, a inet_ntoa() should be used. |
port | Specifies port information of a client. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
GET_SVR_CON | Only checks for Tmax connectivity. |
GET_CUR_IP | Gets the IP and PORT information of a connected server. |
Return Value
Value | Description |
---|---|
- 1 | Not connected to a Tmax System. |
1 | Connected to a Primary Tmax System. |
2 | Connected to a Backup Tmax System. |
The tpgetunsol function processes a message that was received unilaterally without a client request. The message is sent through a tpbroadcast(), tpsendtoci(), tppost() from a sender.
All messages received before calling a tpgetunsol() will be ignored. To receive unrequested messages through a tpgetunsol(), a TPUNSOL_POLL or a TPUNSOL_HND must be set when connecting to a Tmax system through a tpstart(). If a tpgetunsol() is called from a program, a client will receive an unrequested message from a server because a flag has been changed to TPUNSOL_POLL internally even though the flag of a tpstart() was initially set to TPUNSOL_IGN.
Prototype
#include <tmaxapi.h> int tpgetunsol (int type, char **data, long *len, long flags)
Parameter
Parameter | Description |
---|---|
type | A message type delivered from a server. The types are UNSOL_TPPOST, UNSOL_TPBROADCAST, and UNSOL_TPSENDTOCLI. |
data | A pointer to a delivered message. If this is a buffer type or subtype that is not known by a client, "data" cannot be used. |
len | The total length of a message. |
flags | Determines whether to block a message. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | A caller waits for a reply in a blocking state. |
NOCHANGE | In general, if a received response buffer and the buffer type pointed to by a *data do not match, the *data buffer type will be changed to a received response buffer in a scope that a receiver can recognize. If this is set, the buffer type pointed to by a *data cannot be changed. A received response buffer type and subtype must match those of a buffer pointed to by a *data. |
TPNOTIME | A function caller must wait indefinitely until a response is received. Blocking a timeout will be ignored. If a tpgetrply() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and tperrno will be set to TPGOTSIG. |
TPGETANY | Ignores a cd as an input value and returns any receivable responses. A cd will become a caller descriptor for a returned response. If there is no response, a tpgetrply() will wait until a response is received. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetunsol() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpgetunsol() was called from an invalid state. A tpstart() will not be executed, and a TMAX_ACTIVATE_AUTO_TPSTART will be set to N. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <string.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... while(1) { ret=tp_sleep(2); if (ret==-1) { error processing } if (ret==0) printf(“nothing happened\n”); else { ret=tpgetunsol(UNSOL_TPSENDTOCLI, (char **)&buf, &len, TPNOCHANGE); if (ret==-1) { error processing } printf(“received data : %s\n”, buf); } data process.... if (strncmp(buf, “end”, 3)==0) break; } data process.... tpfree(buf); tpend(); }
Related Functions
tpbroadcast(), tpsetunsol(), tpstart(), tpend()
The tpinit function connects a client to a Tmax system. This function is used to apply a function used in Tuxedo to a Tmax system as it is used in Tuxedo. This function is the same as a tpstart() function.
Prototype
#include <tuxatmi.h> int tpinit (TPINIT *tpinfo)
Parameter
Parameter | Description |
---|---|
tpinfo | An option to use authentication information and multi context. |
Return Value
See "3.3.10. tpstart".
Example
#include <stdio.h> #include <tuxinc/tuxatmi.h> int main(int argc, char *argv[]) { char *buf; long len; int ret; ret = tpinit((TPINIT *)NULL); if (ret == -1){ error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf == NULL){ error processing } strcpy(buf, argv[1]); ret = tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret == -1){ error processing } printf(“data: %s\n”, buf); tpfree(buf); tpterm(); }
Related Function
tpstart()
The tpreset function is used to close a current connection immediately, though sometimes a TPESYSTEM error will occur in a client module. Since such an error is almost a network error, it is better to reconnect to a Tmax system. A tpreset() function is recommended for such cases.
So, first close the connection using tpreset(), then request service again or connect to Tmax system.
Prototype
# include <tmaxapi.h> int tpreset (void)
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpreset() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; ret=tpstart((TPSTART_T *)NULL); if (ret==-1){ if (tperrno=TPESYSTEM) { printf (“system error \n”); ret=tpreset(); if (ret==-1) { error process } tpend(); exit(1); } error processing.... } data process.. tpend(); }
The tpsetunsol function is available in a client. It sets a routine that processes unrequested and received messages. How a system receives unrequested messages is determined by each application and can be changed by each client.
Any unrequested messages received by Tmax libraries before a tpsetunsol() is called will be ignored. A tpsetunsol() that is called by a NULL function pointer is also ignored. The function pointer delivered by a call must be suitable for a parameter definition.
Prototype
# include <atmi.h> Unsolfunc *tpsetunsol (void ( *disp ) ( char *data, long len, long flags ) )
Parameter
Parameter | Description |
---|---|
data | Points to a received type buffer. If there is no data, a DATA can be NULL. If a buffer type or subtype of a DATA are unknown by a client, data cannot be recognized. An application cannot delete a DATA, instead a system deletes it and nullify a data area to return. |
len | Data length |
flags | Not currently supported. |
Return Value
Value | Description |
---|---|
Pointer / NULL | A function call was a success.
|
TPUNSOLERR | A function call failed. An error code will be set in tperrno. |
Error
When a tpsetunsol() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpsetunsol() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” void get_unsol(char *data, long len, long flags) { printf(“get unsolicited data = %s\n”, data); data process.... } void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } ret=tpsetupsol_flag(TPUNSOL_HND); if (ret==-1) { error processing } ret=tpsetunsol(get_unsol); if (ret==TPUNSOLERR) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process... ret=tpcall(“SERVICE”, buf, 20, (char **)&buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tpstart(), tpend(), tpgetunsol()
The tpsetunsol_flag function sets a notification message reception flag. This function resets a flag value used for connecting with Tmax systems by using a tpstart() function.
Prototype
# include <atmi.h> int tpsetunsol_flag (int flag)
Parameter
Parameter | Description |
---|---|
flag | Input options:
|
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed because a flag was not set to an acceptable flag. A tperrno will not be set to an error code. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” void get_unsol(char *, long, long); void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } ret=tpsetupsol_flag(TPUNSOL_HND); if (ret==-1) { error processing } ret=tpsetunsol(get_unsol); if (ret==TPUNSOLERR) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process... ret=tpcall(“SERVICE”, buf, 20, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process... tpfree((char *)buf); tpend(); } void get_unsol(char *, long, long); { printf(“get unsolicited data.\n”); data process.... }
Related Funciton
tpstart()
The tpstart function connects a client to a Tmax system. Before using ATMI functions to process service requests or transactions, a client must use a tpstart() to connect to a Tmax system.
Before a tpstart() is called, if another ATMI function (tpalloc() or tpcall(), etc) is called, a tpstart(NULL) will be called internally. To not use this operation, the TMAX_ACTIVATE_AUTO_TPSTART environment variable can be set to N. In such case if another ATMI function is called, a TPEPROTO error will occur without calling a tpstart(NULL) internally. If a tpstart() is returned successfully, a client can send an initial service request or can define a transaction. After connecting to a Tmax system successfully, if a tpstart() is called again, a TPEPROTO error will occur. To connect to a Tmax system using a tpstart(), the IP and port number of the server in which the Tmax system is installed are required.
The following describes environment variables required to find server information.:
Variable Name | Description |
---|---|
TMAX_HOST_ADDR | The IP address of a node to which a client is to be connected. This variable is used for a client to be internally connected to a server system when a tpstart() is called. |
TMAX_HOST_PORT | The port number of a node to which a client is to be connected. This variable is used together with a TMAX_HOST_ADDR for a client to be internally connected to a server system when a tpstart() is called. The value of this variable must be defined in a TPORTNO in a Tmax configuration file. When both a client and a server reside in a node, a more effective way to process a client request is to use a domain socket rather than a TCP/IP socket. In this case, a PATHDIR can be specified instead of using a value defined in a TPORTNO. See the TPORNO item in the DOMAIN and NODE sections of a Tmax configuration file. |
TMAX_BACKUP_ADDR | Specifies another Tmax systems node in preparation against a fault in the node that contains the address of a TMAX_HOST_ADDR. A client first attempts a connection to the node with the address of the TMAX_HOST_ADDR. If the connection to the node fails, the client will attempt to connect to the node with the address found in a TMAX_BACKUP_ADDR. |
TMAX_BACKUP_PORT | The Tmax system port number of a node with a TMAX_BACKUP_ADDR address. |
TMAX_CONNECT_TIMEOUT | Specifies a timeout value for connecting to a Tmax system in micro-seconds. (e.g.:3.5) |
Prototype
#include <atmi.h> int tpstart (TPSTART_T *tpinfo )
Parameter
A tpinfo is a pointer for a TPSTART_T structure. This structure uses a TPSTART buffer type, and this buffer must be allocated by a tpalloc() before a tpstart() is called. It is desirable that an allocated buffer is freed with a tpfree() after a tpstart() function is called. A client transfers necessary information with a structure type tpinfo, at the time of connecting systems. A tpinfo parameter contains client information, a notification message handling state, and security information.
A tpinfo can be set to NULL. In this case, the string length for a cltid, dompwd, usrname, and usrpwd will be given as 0. In this situation Tmax security features will not be used and flags will not be chosen.
The following shows a TPSTART_T structure.
struct TPSTART_T{ char cltid[MAXTIDENT+2]; /* Client name (tpbroadcast())*/ char dompwd[MAX_PASSWD_LENGTH+2]; /*Password for system access security*/ char usrname[MAXTIDENT+2]; /*Account for user authentication security*/ char usrpwd[MAX_PASSWD_LENGTH+2]; /*Password for user authentication security*/ int flags; /*Unrequested message type and system access method*/ } ;
Member | Description |
---|---|
cltid | A string ending with a NULL value that has up to a 30-character length. A cltid is a name defined by an application program and is used to specify a client to which a tpbroadcast() will send unrequested messages. |
dompwd | Controls system access in the security steps provided by Tmax. It registers a password for an account set to an OWNER item of the DOMAIN section of a Tmax configuration file. |
usrname | Used for user authentication in the security steps provided by Tmax. A usrname must be an account registered in the passwd file of a Tmax system. |
usrpwd | The password for an account. When user authentication security is established, a client can be connected to Tmax systems and use the services provided by the system, by registering a usrname and a usrpwd. See the SECURITY item of a DOMAIN section in a tmax configuration file for the details of security settings. |
flags | Used to enable a specific function of a client when connecting to a Tmax system. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPUNSOL_POLL | Receives unrequested messages. |
TPUNSOL_HND | Sets a function that receives unrequested messages. For more information, refer to "3.3.8. tpsetunsol". |
TPUNSOL_IGN | Ignores unrequested messages. If not set, a TPUNSOL_IGN is set by default. |
TPMULTICONTEXTS | Must be set when multithread or multicontext functions are used. |
TPTCPNODELAY | Prevents a Tmax system from using the Nagle algorithm for connecting to a system. |
Return Value
Value | Description |
---|---|
0 or 1 | A function call was successful and 0 to a primary host is returned as well as a 1 to a backup host. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpstart() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a tpinfo is NULL or not a pointer for a TPSTART_T. |
[TPEITYPE] | A tpinfo is not a pointer for a TPSTART_T structure. |
[TPEPROTO] | A tpstart() was called from an invalid state. For example, a tpstart() was called in a server program, or it was called after a connection was already established. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Environment variables may be invalid. For example, a connection failed because a TMAX_HOST_ADDR or TMAX_HOST_PORT was invalid. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; TPSTART_T *tpinfo; tpinfo = (TPSTART_T *)tpalloc(“TPSTART”, NULL, sizeof(TPSTART_T)); if (tpinfo==NULL) { error processing } strcpy(tpinfo->cltname, “cli1”); strcpy(tpinfo->usrname, “navis”); strcpy(tpinfo->dompwd, “tmax”); tpinfo->flags = TPUNSOL_HND; ret=tpstart(tpinfo); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; ret=tpcall(“SERVICE”, buf, 20, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process.... tpfree((char *) buf); tpend(); }
Related Funciton
tpend()
The tpterm function terminates connection with Tmax systems. This function is the same as tpend() function.
Prototype
#include <tuxatmi.h> int tpterm(void)
Return Value
See "3.3.3. tpend".
Example
... #include <tuxinc/tuxatmi.h> int main(int argc, char *argv[]) { int ret; long len; char *buf; ret = tpinit((TPINIT *)NULL); if (ret == -1){ error processing } buf=tpalloc(“STRING”, NULL, 0); If (buf==NULL) { error processing } data process.... ret = tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret == -1){ error processing } data process... ret = tpterm(); if (ret ==–1){ error processing } }
Related Function
tpend()
The tptobackup function connects a client to a Tmax backup system. A tpstart is a function that clients use to connect to Tmax systems. At this time if it is impossible to connect a server because the state of the server is abnormal, a client will automatically attempt to connect to a backup system. Conversely, a tptobackup() is a function used to connect directly to a backup system, so it is used when a user wants to connect to a backup system at their discretion.
A tptobackup() function does not receive a TPSTART_T as an argument, and cannot connect to a system that requires security. Therefore, it is impossible to connect a backup system with this function if a security related item is set in a configuration file. In order to receive unsolicited messages, a flag must be changed so as to receive the messages using a tpsetunsol_flag() function. TMAX_BACKUP_ADDR and TMAX_BACKUP_PORT should be registered in a system configuration file (e.g. .profile on Korn Shell) in order to use a tptobackup().
Prototype
#include <tmaxapi.h> int tptobackup(void)
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tptobackup() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tptobackup() was called from an invalid state. For example, a tptobackup() was called in a server program, or it was called after a connection was already established. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Environment variables may be invalid. For example, a connection failed because a TMAX_BACKUP_ADDR or TMAX_BACKUP_PORT was invalid. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { tpputenv(“TMAX_BACKUP_ADDR=xxx.xxx.xxx.xxx”); tpputenv(“TMAX_BACKUP_PORT=xxxx”); tptobackup(); data process.... tpend(); }
The chk_extpong_msg function checks a message received from a remote server when checking a ping. This function is called at an interval set by a set_extping_msg().
Prototype
int chk_extpong_msg(msg_header_t *hp, char *data, int len)
Parameter
Parameter | Description |
---|---|
hp | A message header received when checking channel health. |
data | A received message body. |
len | A received message body length. |
Return Value
Value | Description |
---|---|
Positive Number | A function call was successful. |
Negative Number | A function call failed. |
0 | A PING message does not exist. |
Example
int chk_extpong_msg(msg_header_t *hp, char *data, int len) { msg_body_t *body; char data2[15]; body = (msg_body_t *)data; printf(“chk_extpong_msg : data = %s\n”, body->data); return 1; }
Caution
To use a chk_extpong_msg(), the following must be added to a <register.c> file.
#if !defined(_TCPGW_VERSION_OLD) && !defined(_TCPGW_VERSION_1) #&& !defined(_TCPGW_VERSION_2) #if defined(_TCPGW_USE_EXTPING) _tcpgw_regfn(19, NULL); _tcpgw_regfn(20, NULL); _tcpgw_regfn(21, set_extping_msg); _tcpgw_regfn(22, chk_extpong_msg); _tcpgw_regfn(23, NULL); _tcpgw_regfn(24, reset_extping_msg); /* Reconfiguration */ #else _tcpgw_regfn(19, set_ping_msg); _tcpgw_regfn(20, chk_pong_msg); _tcpgw_regfn(21, NULL); _tcpgw_regfn(22, NULL); _tcpgw_regfn(23, reset_ping_msg); /* Reconfiguration */ _tcpgw_regfn(24, NULL); #endif #else _tcpgw_regfn(19, NULL); _tcpgw_regfn(20, NULL); _tcpgw_regfn(21, NULL); _tcpgw_regfn(22, NULL); _tcpgw_regfn(23, NULL); _tcpgw_regfn(24, NULL); #endif
The reset_extping_msg function is periodically called to reconfigure a ping message in a TCP/IP gateway.
Prototype
int reset_extping_msg(msg_header_t *hp, char *data, int len)
Parameter
Parameter | Description |
---|---|
hp | A message header received when checking channel health. |
data | A message body to reconfigure. |
len | A nessage body length. |
Return Value
Value | Description |
---|---|
Positive Number | A function call was successful. |
Negative Number | A function call failed. |
Example
int reset_extping_msg(msg_header_t *hp, char *data, int len) { hp->len = 10; data = “reset_msg”; printf(“reset_extping_msg : data = %s\n”, data); return 1; }
Caution
To use a reset_extping_msg(), the following must be added to a <register.c> file.
#if !defined(_TCPGW_VERSION_OLD) && !defined(_TCPGW_VERSION_1) # && !defined(_TCPGW_VERSION_2) #if defined(_TCPGW_USE_EXTPING) _tcpgw_regfn(19, NULL); _tcpgw_regfn(20, NULL); _tcpgw_regfn(21, set_extping_msg); _ _tcpgw_regfn(22, chk_extpong_msg); _tcpgw_regfn(23, NULL); _tcpgw_regfn(24, reset_extping_msg); /* Reconfiguration */ #else _tcpgw_regfn(19, set_ping_msg); _tcpgw_regfn(20, chk_pong_msg); _tcpgw_regfn(21, NULL); _tcpgw_regfn(22, NULL); _tcpgw_regfn(23, reset_ping_msg); /* Reconfiguration */ _tcpgw_regfn(24, NULL); #endif #else _tcpgw_regfn(19, NULL); _tcpgw_regfn(20, NULL); _tcpgw_regfn(21, NULL); _tcpgw_regfn(22, NULL); _tcpgw_regfn(23, NULL); _tcpgw_regfn(24, NULL); #endif
The set_extping_msg function configures a message to be sent when checking a ping to a local or remote server.
Prototype
int set_extping_msg(msg_header_t *hp, char *data, int len, int *interval, int *binterval, int *timeout, int *mode);
Parameter
Parameter | Description |
---|---|
hp | A message header received when checking channel health. |
data | A nessage body to send. |
len | A message body length. |
interval | The health check cycle for a main channel. If it is set to 0, a health check will not be performed. |
binterval | A pointer to an Interval to check a main channel in a backup channel mode. If it is set to 0, the main channel is not checked. |
timeout | The maximum time to check a channel in seconds. If a channel is not checked within a specified time, the function will end due to a failure. |
mode | Set to one of the following:
|
Return Value
Value | Description |
---|---|
Positive Number | A function call was successful. |
Negative Number | A function call failed. |
Example
int set_extping_msg(msg_header_t *hp, char *data, int len, int *interval, int *binterval, int *timeout, int *mode) { msg_body_t *body; body = (msg_body_t *)data; memset(body->data, 0x00, 52); memcpy(body->data, “tmax50”, 7); body->data[51] = 0; printf(“set_extping_msg : data = %s\n”, body->data); hp->len = 7; *interval = 10; *binterval = 20; *timeout = 100; mode = 0; / OUTBOUND CHANNEL */ return 1; }
Caution
To use a set_extping_msg(), the following must be added to a <register.c> file.
#if !defined(_TCPGW_VERSION_OLD) && !defined(_TCPGW_VERSION_1) #&& !defined(_TCPGW_VERSION_2) #if defined(_TCPGW_USE_EXTPING) _tcpgw_regfn(19, NULL); _tcpgw_regfn(20, NULL); _tcpgw_regfn(21, set_extping_msg); _tcpgw_regfn(22, chk_extpong_msg); _tcpgw_regfn(23, NULL); _tcpgw_regfn(24, reset_extping_msg); /* Reconfiguration */ #else _tcpgw_regfn(19, set_ping_msg); _tcpgw_regfn(20, chk_pong_msg); _tcpgw_regfn(21, NULL); _tcpgw_regfn(22, NULL); _tcpgw_regfn(23, reset_ping_msg); /* Reconfiguration */ _tcpgw_regfn(24, NULL); #endif #else _tcpgw_regfn(19, NULL); _tcpgw_regfn(20, NULL); _tcpgw_regfn(21, NULL); _tcpgw_regfn(22, NULL); _tcpgw_regfn(23, NULL); _tcpgw_regfn(24, NULL); #endif
For more information about TDL functions, refer to "Tmax Programming Guide (Dynamic Library)".
The latest version of a dynamic module function is called. This dynamic module function must have a long funcname(void *args) signature. A tdlcall function works only when the version of a TDL configuration file(tdl.cfg) is set to 1 or 2. Dynamic modules are loaded when a tdlcall() is called, and to prevent performance deterioration, they are recycled unless an update (tdlupdate) is required.
Prototype
#include <tdlcall.h> int tdlcall(char *funcname, void *args, long *urcode, int flags)
Parameter
Parameter | Description |
---|---|
funcname | The name of dynamic module. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
args | An argument to a dynamic module function being called. |
urcode | A return value from a dynamic module function. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS will be set. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error in an environment configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
The tdlcall2 function calls the latest version of a dynamic module using a library name and function name as a key. This dynamic module must have a long funcname(void *args) signature. Other than the use of a library name and function name as a key, this function is identical to a tdlcall() function.
A dynamic module function must have a long funcname(void *args) signature. This function is available only when the version of a TDL configuration file (tdl.cfg) is set to 3.
Prototype
#include <tdlcall.h> int tdlcall2(char *libname, char *funcname, void *args, long *urcode, int flags)
Parameter
Parameter | Description |
---|---|
libname | The library name of a dynamic module. (Maximum size : TDL_FUNCNAME_SIZE – 1) |
funcname | The function name of a dynamic module. (Maximum size : TDL_FUNCNAME_SIZE – 1) |
args | An argument to a calling dynamic module function. |
urcode | A return value from a dynamic module function. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, TDL_NOFLAGS is set. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
The tdcall2s function calls the latest version of a dynamic module using a library name and a function name as a key. This dynamic module must have a long funcname(void *input, void *output) signature.
Other than the use of a library name and a function name as a key, this function is identical to a tdlcall() function. This function is available only when the version of a TDL configuration file (tdl.cfg) is set to 3.
Prototype
#include <tdlcall.h> int tdlcall2s(char *libname, char *funcname, void *input, void *output, long *urcode, int flags)
Parameter
Parameter | Description |
---|---|
libname | The library name of a dynamic module. (Maximum length: TDL_FUNCNAME_SIZE – 1). |
funcname | The function name of a dynamic module. (Maximum length: TDL_FUNCNAME_SIZE – 1). |
input | An input buffer pointer to a calling dynamic module function. |
output | An output buffer pointer to a calling dynamic module function. |
urcode | The return value from a dynamic module function. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS is set. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
The tdcall2v function calls the latest version of a dynamic module using a library name and a function name as a key. This dynamic module must have a long funcname(int argc, char *argv[]) signature.
Other than the use of a library name and a function name as a key, this function is identical to a tdlcall() function and is available only when the version of a TDL configuration file (tdl.cfg) is set to 3.
Prototype
#include <tdlcall.h> int tdlcall2v(char *libname, char *funcname, int argc, char *argv[], long *urcode, int flags)
Parameter
Parameter | Description |
---|---|
libname | The library name of a dynamic module. (Maximum Length : TDL_FUNCNAME_SIZE – 1) |
funcname | The function name of a dynamic module.(Maximum Length : TDL_FUNCNAME_SIZE – 1) |
argc | The number of arguments for a dynamic module function. |
argv | An argument vector for a dynamic module function.. |
urcode | A return value from a dynamic module function. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS is set. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
The tdlcallva function calls the latest version of a dynamic module using a function name as a key. A parameter is sent as-is for a dynamic function module that has an unfixed prototype. Delivered arguments must all have a <void *> pointer type. In a dynamical module function, all delivered parameters must be created as <void *> pointer types.
This function can be used when VERSION=1 or VERSION=2 is specified in a TDL configuration file(tdl.cfg).
Prototype
#include <tdlcall.h> int tdlcallva(char *funcname, long urcode, int flags, int rettype, void *retval, int argc, …);
Parameter
Parameter | Description |
---|---|
funcname | The library name of a dynamic module. (Maximum Length : TDL_FUNCNAME_SIZE – 1) |
urcode | Unlike the other tdlcall() functions, a urcode is used only when sending a global sequence number. |
flags | If set to a TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS will be set. |
rettype | The return type of a dynamic module function to be called. Available values for this parameter are explained in the table below. |
retval | A pointer to a buffer to store return values of a dynamic module function. |
argc | The number of arguments for a dynamic module function. Currently, the maximum available number of arguments is 10. |
... | Enters parameters to be sent to a dynamic module function as a variable argument. A pointer (void*) type of parameters must be sent. |
Values for return type
Parameter | Description |
---|---|
TDL_VA_CHAR | The returned type of a dynamic module function is a char type. |
TDL_VA_SHORT | The returned type of a dynamic module function is a short type. |
TDL_VA_INT | The returned type of a dynamic module function is an integer type. |
TDL_VA_LONG | The returned type of a dynamic module function is a long type. |
TDL_VA_FLOAT | The returned type of a dynamic module function is a short type. |
TDL_VA_DOUBLE | The returned type of a dynamic module function is a short type. |
TDL_VA_PVOID | The returned type of a dynamic module function is a void * type. |
TDL_VA_VOID | The returned type of a dynamic module function is a void type. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
Example
Dynamic module call
int myfunc(double *a, double *b, double *c) { double sum; return (int)(((double)(*a) + (double)(*b) + (double)(*c))/3); } char * myfunc2(int *type) { char *msg; switch (*type) { case 1: msg = “foo”; break; case 2: msg = “bar”;break; } return msg; }
Program to be called
#include <tdlcall.h> int main(int argc, char *argv[]) { int n; long urcode; int retval; double a, b, c; int type; char *retmsg; urcode = tdlgetseqno(); a = 2.5; b = 3.0; c = 3.5; if ((n = tdlcallva2(“mylib001”, “myfunc”, urcode, TDLTRAN, TDL_VA_INT, &retval, 3, &a, &b, &c)) != TDL_OK) { error processing; } type = 1; if ((n = tdlcallva2(“mylib001”, “myfunc2”, urcode, TDLTRAN, TDL_VA_PVOID, &retmsg, 1, &type)) != TDL_OK) { error processing; } }
The tdlcallva2 function calls the latest version of a dynamic module using a library and function name as a key. A parameter is sent as-is for a dynamic function module that has an unfixed prototype. Delivered arguments must all have a <void *> pointer type. In a dynamical module function, all delivered parameters must be created as <void *> pointer types.
Other than the use of a library and function name as a key, this function is identical to a tdlcalva() function. It is available when VERSION=3 is specified in a TDL configuration file (tdl.cfg).
Prototype
#include <tdlcall.h> int tdlcallva2(char *libname, char *funcname, long urcode, int flags, int rettype, void *retval, int argc, …);
Parameter
Parameter | Description |
---|---|
libname | The library name of a dynamic module. (Maximum Length : TDL_FUNCNAME_SIZE – 1) |
funcname | The function name of a dynamic module.(Maximum Length : TDL_FUNCNAME_SIZE – 1) |
urcode | Unlike other tdlcall() functions, it is used only when sending a global sequence number. When not using a global sequence number, set this parameter to 0. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS will be set. |
rettype | The return type of a dynamic module function to be called. Available values for this parameter are explained in the table below. |
retval | A pointer to a buffer to store the return value of a dynamic module function. |
argc | The number of arguments for a dynamic module function. Currently, the maximum available number of arguments is 10. |
... | Enters parameters to be sent to a dynamic module function as a variable argument. A pointer (void*) type of parameters must be sent. |
Return Type
Item | Description |
---|---|
TDL_VA_CHAR | The returned type of a dynamic module function is a char type. |
TDL_VA_SHORT | The returned type of a dynamic module function is a short type. |
TDL_VA_INT | The returned type of a dynamic module function is an int type. |
TDL_VA_LONG | The returned type of a dynamic module function is a long type. |
TDL_VA_FLOAT | The returned type of a dynamic module function is a short type. |
TDL_VA_DOUBLE | The returned type of a dynamic module function is a short type. |
TDL_VA_PVOID | The returned type of a dynamic module function is a void * type. |
TDL_VA_VOID | The returned type of a dynamic module function is a void type. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
The tdlcreate function creates a class instance using a Class Factory in the latest version of a dynamic module. It uses a library name, a namespace, and a class name as keys. It can be used when a VERSION is set to 4 in a tdl.cfg TDL configuration file.
To use a Class Factory in a dynamic module, a user must implement a callback function in a long tdlcreate_cb(char *namespace, char *classname, void *args, void *object) format. A callback function creates an actual class instance using arguments which are passed from a tdlcreate() and sends a reference of an instance to an object.
A user must destroy an instance using a tdldestroy() if the instance is no longer used. Although the version of a dynamic module is changed by using a tdlupdate(), an instance that is created using a tdlcreate() will operate for an old version of a dynamic module before being destroyed using a tdldestroy(). To use an instance for a new dynamic module, call a tdldestroy() and then call a tdlcreate().
To use a Class Factory, the following tdlcreate_cb() callback function needs to be implemented in a dynamic module:
Prototype
#include <tdlcall.h> int tdlcreate(char *libname, char *namespace, char *classname, void *args, void *object, long *urcode, int flags)
Parameter
Parameter | Description |
---|---|
libname | A dynamic module library name. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
namespace | A namespace. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
classname | The name of a class where an instance is created. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
args | Passes user-defined data to a tdlcreate_cb() callback function. |
object | Pointer to a variable for saving the reference of a class instance which is created through a tdlcreate_cb() callback function. |
urcode | A return value of a tdlcreate_cb() callback function. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS is set. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
Callback Function Prototype
long tdlcreate_cb(char *namespace, char *classname, void *args, void *object)
Parameter
Parameter | Description |
---|---|
namespace | A namespace received from a tdlcreate(). |
classname | A name of a class where an instance received from a tdlcreate() is created. |
args | User-defined data. |
object | A pointer to a variable for saving a reference of a class instance that is created through a callback function. |
The tdldestroy function destroys a class instance using a Class Factory in the latest version of a dynamic module. It uses a library name, a namespace, and a class name as keys. It can be used when a VERSION is set to 4 in a tdl.cfg TDL configuration file.
To use a Class Factory in a dynamic module, a user must implement a callback function in a long tdldestroy_cb(char *namespace, char *classname, void *args, void *object) format. The callback function destroys an actual class instance using arguments which are passed from a tdldestroy().
A user must destroy an instance using a tdldestroy() if the instance is no longer used. Although the version of a dynamic module is changed through a tdlupdate(), an instance which is created using a tdlcreate() operates for the old version of a dynamic module before being destroyed using a tdldestroy(). To use an instance for the new dynamic module, call a tdldestroy() and then call a tdlcreate().
Prototype
#include <tdlcall.h> int tdldestroy(char *libname, char *namespcae, char *classname, void *args, void *object, long *urcode, int flags)
Parameter
Parameter | Description |
---|---|
libname | A dynamic module library name. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
namespace | A nmespace. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
classname | The name of a class where an instance is created. (Maximum length: TDL_FUNCNAME_SIZE – 1) |
args | Passes user-defined data to a tdlcreate_cb() callback function. |
object | Passes a reference of a class instance to be destroyed by a tdldestroy_cb() callback function. This must be an object that is created using a tdlcreate(). |
urcode | A return value of a tdlcreate_cb() callback function. |
flags | If set to TDLTRAN, a global sequence number must be passed using a urcode. If unspecified, a TDL_NOFLAGS is set. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_OPEN_ERROR | An error was returned with dlopen(). |
TDL_SYM_ERROR | An error was returned with dlsym(). |
TDL_CLOSE_ERROR | An error was returned with dlclose(). |
TDL_SYSTEM_ERROR | An error with another system function calls. |
TDL_INT _ERROR | An error with an internal library. |
TDL_ENOFUNC | Cannot find a target module or function. |
TDL_ENV_ERROR | An error with an environment variable configuration. |
TDL_VER_ERROR | A version mismatch between the versions of a TDL shared memory and a configuration file (tdl.cfg). |
TDL_ARG _ERROR | An error in an argument. |
TDL_ENOLIB | Cannot find a target library. |
TDL_TRAN_ERROR | An error while checking version consistency. |
TDL_EINACTIVE | A module is temporarily inactive. |
To use a Class Factory, the following tdldestroy_cb() callback function must be implemented in a dynamic module.
Callback Function Prototype
long tdldestroy_cb(char *namespace, char *classname, void *args, void *object)
Parameter
Parameter | Description |
---|---|
namespace | A namespace received from a tdldestroy(). |
classname | The name of a class where an instance received from a tdldestroy() will be destroyed. |
args | User-defined data. |
object | The reference of a class instance to be destroyed through a callback function. |
The tdlend function stops maintaining Explicit Version Consistency.
Prototype
#include <tdlcall.h> int tdlend(void)
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_TRAN _ERROR | A tdlstart() has been carried out before calling a tdlstart(). See "3.5.1. tdlcall" for detailed information. |
The tdlerror function converts a tdlcall function error to a character string. If an error occurred in a previous tdlcall() function call, detailed information will be obtained about the error in a string format. A pointer returned from this function is a pointer to a static variable that may change on a following call to a tdlcall().
To maintain content of this variable, the content should be copied to another variable.
Prototype
#include <tdlcall.h> char* tdlerror(int retval)
Parameter
Parameter | Description |
---|---|
retval | A return value from a previous tdlcall() function call. |
Return Value
Value | Description |
---|---|
dlopen fail | Returned when receiving a TDL_OPEN_ERROR as a return value of a tdlcall(). |
dlsym fail | Returned when receiving a TDL_SYM_ERROR as a return value of a tdlcall(). |
dlclose fail | Returned when receiving a TDL_CLOSE_ERROR as a return value of a tdlcall(). |
etc system call error | Returned when receiving a TDL_SYSTEM_ERROR as a return value of a tdlcall(). |
TDL lib internal error | Returned when receiving a TDL_SYSTEM_ERROR as a return value of a tdlcall(). |
funcname not found | Returned when receiving a TDL_ENOFUNC as a return value of a tdlcall(). |
environment not found | Returned when receiving a TDL_ENV_ERROR as a return value of a tdlcall(). |
shared version mismatch | Returned when receiving a TDL_VER_ERROR as a return value of a tdlcall(). |
invalid arguments | Returned when receiving a TDL_ARG_ERROR as a return value of a tdlcall(). |
library not found | Returned when receiving a TDL_ENOLIB as a return value of a tdlcall(). |
transaction error | Returned when receiving a TDL_TRAN_ERROR as a return value of a tdlcall(). |
inactive function | Returned when receiving a TDL_EINACTIVE as a return value of a tdlcall(). |
The tdlresume function resumes a temporarily suspended Explicit Version Consistency.
Prototype
#include <tdlcall.h> int tdlresume(int sd)
Prototype
Parameter | Description |
---|---|
sd | A descriptor from a tdlsuspend(). |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_TRAN _ERROR | A sd is not a valid value. See "3.5.1. tdlcall" for detailed information. |
The tdlstart function starts maintaining Explicit Version Consistency.
Prototype
#include <tdlcall.h> int tdlstart(void)
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_TRAN _ERROR | A tdlstart() was been carried out before calling a tdlstart(). See "3.5.1. tdlcall" for detailed information. |
The tdlsuspend function temporarily suspends maintaining explicit version consistency and a SD (suspend descriptor) is returned. There may be a maximum of 8 simultaneous SDs.
Prototype
#include <tdlcall.h> int tdlsuspend(void)
Return Value
Value | Description |
---|---|
0 or greater value | A function call was successful. |
TDL_TRAN _ERROR | Not in Explicit Version Consistency mode. See "3.5.1. tdlcall" for detailed information. |
The tdlgetseqno function gets a global sequence number and returns it as a return value.
Prototype
#include <tdlcall.h> unsigned int tdlgetseqno(void)
Return Value
Value | Description |
---|---|
0 or greater value | A function call was successful. |
0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The tdlclose function initializes a reference count of a module to 0 or releases a module from memory.
Prototype
#include <tdlcall.h> int tdlclose(char *name, int flags)
Parameter
Parameter | Description |
---|---|
name | A module name. |
flags | If set to 0, the reference count of a module is set to 0 and the module will not be released from memory. If set to TDLCLOSE_HARD, the module will be released from memory by a dlclose(). |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
TDL_ENOLIB | A module does not exist. |
When a module is called first through a tdlcall(), a certain period of time is consumed because it needs to search for a hashtable in shared memory as well as load libraries to memory. To prevent a delay, a tdlload function can perform a search for a hashtable and load libraries before calling a tdlcall(). It can also save module information in a local cache.
If VERSION=1 or VERSION=2 is set in TDL configuration file(tdl.cfg), tdlload() will be used. If VERSION=3 is set, tdlload2() will be used and if VERSION=4 is set, tdlload3() will be used.
Prototype
#include <tdlcall.h> int tdlload(char *funcname, int flags)
Parameter
Parameter | Description |
---|---|
funcname | The name of a function to be loaded. |
flags | Not current supported. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
TDL_ENOFUNC | An argument is NULL or does not exist in a hashtable. |
TDL_OPEN_ERROR | Failed to load a dynamic library in a hashtable to memory. |
TDL_SYSTEM_ERROR | Failed to allocate system resources for creating a local cache. |
The tdlload2 function is the same as a tdlload. For more information, refer to "3.5.16. tdlload".
Prototype
#include <tdlcall.h> int tdlload2(char *libname, char *funcname, int flags)
Parameter
Parameter | Description |
---|---|
libname | The name of a library to be loaded. |
funcname | The name of a function to be loaded. |
flags | Currently not used. |
Return Value
Since return values of a tdlload2() are the same as those of a tdlload(), refer to "3.5.16. tdlload".
The tdlinit function initially sets shared memory.
Prototype
#include <tdlcall.h> int tdlinit(int flags)
Parameter
Parameter | Description |
---|---|
flags | Currently not used. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
Value less than 0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The tdldone function initializes shared memory.
Prototype
#include <tdlcall.h> int tdldone(int flags)
Parameter
Parameter | Description |
---|---|
flags | Currently not used. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
Value less than 0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The tdlfind function searches for a module index. It is used when a VERSION is set to 1 or 2 in a tdl.cfg TDL configuration file.
Prototype
#include <tdlcall.h> int tdlfind(char *funcname, int flags)
Parameter
Parameter | Description |
---|---|
funcname | The name of a function to be found. |
flags | Currently not used. |
Return Value
Value | Description |
---|---|
0 or greater value | A function call was successful. |
Value less than 0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The tdlfind function searches for a module index. It is used when a VERSION is set to 3 in a tdl.cfg TDL configuration file.
Prototype
#include <tdlcall.h> int tdlfind2(char *libname, char *funcname, int flags)
Parameter
Parameter | Description |
---|---|
libname | The name of a library to be found. |
funcname | The name of a function to be found. |
flags | Currently not used. |
Return Value
Value | Description |
---|---|
0 or greater value | A function call was successful. |
Value less than 0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The tdlstat function displays TDL statistics. It is used when a VERSION is set to 1 or 2 in a tdl.cfg TDL configuration file. It is required to set a MONITOR to Y in a configuration file.
Prototype
#include <tdlcall.h> int tdlstat(char *funcname, struct timeval svc_time, struct timeval cpu_time)
Parameter
Parameter | Description |
---|---|
funcname | The name of a function for which statistics are collected. |
svc_time | A variable where service time among statistics is saved. |
cpu_time | A variable where CPU time among statistics is saved. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
Value less than 0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The tdlstat2 function displays TDL statistics. It is used when a VERSION is set to 3 in a tdl.cfg TDL configuration file. It is required to set a MONITOR to Y in a configuration file.
Prototype
#include <tdlcall.h> int tdlstat2(char *libname, char *funcname, struct timeval svc_time, struct timeval cpu_usrtime, struct timeval cpu_systime)
Parameter
Parameter | Description |
---|---|
libname | The name of a library for which statistics are collected. |
funcname | The name of a function for which statistics are collected. |
svc_time | A variable where service time among statistics is saved. |
cpu_usrtime | A variable where user CPU time among statistics is saved. |
cpu_systime | A variable where system CPU time among statistics is saved. |
Return Value
Value | Description |
---|---|
TDL_OK | A function call was successful. |
Value less than 0 | A function call failed. Detailed error information can be checked by using a "3.5.10. tdlerror". |
The WinTmaxAcall function, available in a client in a Windows system environment, performs the same functions as a tpacall() in a multi threaded environment. It creates a new thread and invokes a tpstart() → tpacall() → tpgetrply() in the thread. After calling a tpgetrply(), it invokes a SendMessage(wHandle, msgType, (UINT) &MSG, tperrno).
Prototype
# include <tmaxapi.h> int WinTmaxAcall(TPSTART_T *sinfo, HANDLE wHandle, unsigned int msgtype, char *svc, char *sndbuf, int len, int flags)
Parameter
Parameter | Description |
---|---|
sinfo | The structure that is used when sending client information to a Tmax system. Identical to the parameter of a tpstart(). |
wHandle | A Windows Handler used to receive a messages. |
msgtype | An arrival message. Generally, a WM_USER is freely defined by a developer. Specify a service name registered in a svc Tmax configuration file. |
svc | A service to send a request. |
sndbuf | Data to be sent when calling a service. If not null, it must use a buffer allocated using a tpalloc(). |
len | The length of data to be sent. It must be specified for CARRAY, X_OCTET, and Structure array types. |
flags | Identical to the flags of a tpacall(). |
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | If a tpacall was used without flags, a normal result will be returned even if a called service does not exist in a svc or an invalid result is returned. If a tpacall() is called using a TPBLOCK, a service state can be checked if it is normal or not. |
TPNOTRAN | If a service does not support transactions in a transaction mode, flags must be set to a TPNOTRAN for a tpacall() to be called in the transaction mode. If a tpacall() caller requests a svc service by setting a TPNOTRAN in a transaction mode, a svc service will be executed by being excluded from the transaction mode. When calling a tpacall() within a transaction mode, a call will still affected by a transaction timeout even if a tpacall() is set to TPNOTRAN. In other words, calling a tpacall that is set as a TPNOTRAN after a transaction timeout will fail except when calling a tpacall that has been set as a TPNOTRAN|TPNOREPLY. If a service with a flag set to a TPNOTRAN fails, this does not affect a caller's transaction. |
TPNOREPLY | If a tpacall() is used to send a service request, a tpacall will return immediately without waiting for a response. A client can retrieve results by using a tpgetrply() with a descriptor returned by a tpacall(). If a TPNOREPLY is set, a response for a service request will not be received. If set to a TPNOREPLY, a tpacall() will return a 0 if a service is called normally. If a function caller is in a transaction mode, a TPNOREPLY must be set along with a TPNOTRAN. In case of a TPNOREPLY, to check if a service state is normal or not, a TPBLOCK also must be set. If a TPBLOCK is not set, an error will not be returned even a service is NRDY. |
TPNOBLOCK | Upon encountering a blocking condition with this flag, for example, an internal buffer is filled with messages to be transmitted, a service request will fail. When calling a tpacall() function without setting a TPNOBLOCK flag, if a blocking condition is encountered, a function caller must wait until blocking is released or a timeout (transaction timeout or blocking timeout) occurs. |
TPNOTIME | A function caller must wait indefinitely until a response is received and blocking timeouts are ignored. If a tpacall() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful. A returned descriptor is used to receive a response for a sent service request. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxAcall() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. For a structure, this error occurs when the structure is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests was reached. Service requests from a caller cannot be sent. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A WinTmaxAcall() was called from an invalid state. For example, a TPNOREPLY was called in a transaction mode, but a TPNOTRAN was not set. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPEOS] | An operating system error occurred. |
Example
... #include <usrinc/tmaxapi.h> #define WM_WINTMAX_RECV WM_USER + 1 ... BEGIN_MESSAGE_MAP(CWinTmaxAcall2TestDlg, CDialog) ... ON_MESSAGE(WM_WINTMAX_RECV, OnWinTmaxAcall) ... END_MESSAGE_MAP() BOOL CWinTmaxAcall2TestDlg::OnInitDialog() { CDialog::OnInitDialog(); ... ret = tmaxreadenv(“tmax.env”, “TMAX”); if (ret == -1){ AfxMessageBox(“tmaxreadenv fail...”); return FALSE; } return TRUE; // return TRUE unless you set the focus to a control } void CWinTmaxAcall2TestDlg::OnOK() { ... GetDlgItemText(IDC_EDIT1, m_Input); lstrcpy((LPTSTR)buf, (LPCTSTR)m_Input.operator const char *()); ... buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ AfxMessageBox(“buf alloc fail...”); return FALSE; } ret = WinTmaxAcall((TPSTART_T *)NULL, m_hWnd, WM_WINTMAX_RECV, “TOUPPER”, buf, 0, TPNOFLAGS); if (ret == -1){ error processing } } LRESULT CWinTmaxAcall2TestDlg::OnWinTmaxAcall(WPARAM wp, LPARAM lp) { char msg[100]; memset(msg, 0x00, 100); TPSVCINFO *get = (TPSVCINFO *)wp; if (lp < 0){ error processing } ... SetDlgItemText(IDC_EDIT2, get->data); return 0; }
Related Functions
tpacall(), WinTmaxAcall2()
The WinTmaxAcall2 function, available in a client in a Windows system environment, performs the same function as a tpacall() in a multi thread environment. It issues a new thread and invokes a tpstart() → tpacall() → tpgetrply() in the thread. After calling a tpgetrply(), it delivers received data to a specified Callback function.
Prototype
# include <tmaxapi.h> int WinTmaxAcall2(TPSTART_T *sinfo, WinTmaxCallback fn, char *svc, char *sndbuf, int len, int flags)
Parameter
Parameter | Description |
---|---|
sinfo | The structure used when sending information about a client to a Tmax system. Identical to the parameters of a tpstart(). |
fn | Sets a Callback function to receive a response for a service request. |
svc | Sets a service name registered in a Tmax environment configuration file. |
sndbuf | Data to be sent when calling a service. If not null, it must use a buffer allocated through a tpalloc(). |
len | The length of data to be sent. It must be specified for CARRAY, X_OCTET, and Structure array types. |
flags | Identical to the flags of a tpacall(). Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | If tpacall was used without flags, a normal result is returned even if a called service does not exist in a svc or an invalid result is returned. If a tpacall() is called using a TPBLOCK, a service state can be checked if it is normal or not. |
TPNOTRAN | If a service does not support transactions in a transaction mode, flags must be set to a TPNOTRAN for a tpacall() to be called in the transaction mode. If a tpacall() caller requests a svc service by setting a TPNOTRAN in a transaction mode, a svc service will be executed by being excluded from the transaction mode. When calling a tpacall() within a transaction mode, a call will still affected by a transaction timeout even if a tpacall() is set to TPNOTRAN. If a service with a flag set to a TPNOTRAN fails, this does not affect a caller's transaction. |
TPNOREPLY | If a tpacall() is used to send a service request, a tpacall will return immediately without waiting for a response. A client can retrieve results by using a tpgetrply() with a descriptor returned by a tpacall(). If a TPNOREPLY is set, a response for a service request will not be received. If set to a TPNOREPLY, a tpacall() will return a 0 if a service is called normally. If a function caller is in a transaction mode, a TPNOREPLY must be set along with a TPNOTRAN. In case of a TPNOREPLY, to check if a service state is normal or not, a TPBLOCK also must be set. If a TPBLOCK is not set, an error will not be returned even a service is NRDY. |
TPNOBLOCK | Upon encountering a blocking condition with this flag, for example, an internal buffer is filled with messages to be transmitted, a service request will fail. When calling a tpacall() function without setting a TPNOBLOCK flag, if a blocking condition is encountered, a function caller must wait until blocking is released or a timeout (transaction timeout or blocking timeout) occurs. |
TPNOTIME | A function caller must wait indefinitely until a response is received and blocking timeouts are ignored. If a tpacall() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxAcall2() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. For a structure, this error occurs when the structure is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests was reached. Service requests from a caller cannot be sent. |
[TPETRAN] | A svc does not support transactions, and a TPNOTRAN was not set. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A WinTmaxAcall2() was called from an invalid state. For example, a TPNOREPLY was called in a transaction mode, but a TPNOTRAN was not set. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPEOS] | An operating system error occurred. |
Example
#include <usrinc/tmaxapi.h> #define WM_WINTMAX_RECV WM_USER + 1 int mycallfn(unsigned int, long); ... BEGIN_MESSAGE_MAP(CWinTmaxAcall2TestDlg, CDialog) ... END_MESSAGE_MAP() BOOL CWinTmaxAcall2TestDlg::OnInitDialog() { CDialog::OnInitDialog(); ... ret = tmaxreadenv(“tmax.env”, “TMAX”); if (ret == -1){ AfxMessageBox(“tmaxreadenv fail...”); return FALSE; } return TRUE; // return TRUE unless you set the focus to a control } void CWinTmaxAcall2TestDlg::OnOK() { ... GetDlgItemText(IDC_EDIT1, m_Input); lstrcpy((LPTSTR)buf, (LPCTSTR)m_Input.operator const char *()); ... buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ AfxMessageBox(“buf alloc fail...”); return FALSE; } ret = WinTmaxAcall2((TPSTART_T *)NULL, (WinTmaxCallback)mycallfn, “TOUPPER”, (char *)buf, 0, TPNOFLAGS); if (ret == -1){ error processing } } int mycallfn(unsigned int msg, long retval) { TPSVCINFO *svcinfo; char infomsg[30]; memset(infomsg, 0x00, sizeof(infomsg)); svcinfo = (TPSVCINFO *)msg; strncpy(infomsg, svcinfo->data, svcinfo->len); if (retval != 0){ strcpy(infomsg,tpstrerror(retval)); AfxMessageBox(infomsg); return -1; } else { strncpy(infomsg, svcinfo->data, sizeof(infomsg) - 1); AfxMessageBox(infomsg); return 1; } }
Related Functions
tpacall(),WinTmaxAcall()
The WinTmaxEnd function, available in a client in a Windows system environment, closes a connection to a Tmax system. It functions identically to a tpend(). In a Multi threaded environment, a client is connected to each thread via a WinTmaxStart(), so a WinTmaxEnd() must be used for each thread to close the connection.
Prototype
# include <WinTmax.h> int WinTmaxEnd(void)
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxEnd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPETIME] | Cannot access a critical section due to an internal system error. Check the system status. |
[TPEPROTO] | A WinTmaxEnd() was called from an invalid state. For example, a WinTmaxEnd() was called after a connection was already closed. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Related Functions
tpend(), WinTmaxStart()
The WinTmaxSend function, available in a client in a Window system environment, sends data. This function requests a service in a multi-windows environment.
Prototype
# include <WinTmax.h> int WinTmaxSend(int recvContext, char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
recvContext | Sets a Windows for receiving a response from a Tmax system. It is the return value of a WinTmaxSetContext(). |
svc | A service name. |
data | A buffer allocated through a tpalloc(). The data used to request a service is stored. |
len | Data length. The length must be correctly defined when using a CARRAY or a multiple Structure buffer. |
flags | Flag values are listed in the table below. |
A WinTmaxSend() works similarly to a tpacall() function. It requests a service and is returned immediately without waiting for a response. A response is processed by the thread that was created when calling a WinTmaxStart(), and the response result will be sent to a Windows set by a WinTmaxSetContext(), so a separate API is not provided to receive the response.
The following example finds a vacant slot to store (hwd, 0x300) and returns an index. The return value a rc of a WinTmaxSetContext() is used as a recvContext parameter of a WinTmaxSend(). If a response is received after calling a WinTmaxSend(rc, svc, data, len, 0), a 0 x 300 message and a response result will be sent to a hwd windows.
rc = WinTmaxSetContext(hwd, 0x300, -1); int nSendResult = WindTmaxSend(rc, (LPSTR)(LPCSTR)strService, (Char*)tpbuf, nLen, TPNOFLAGS); /* The internal thread processes the response message and sends the result to the Windows SendMessage(hwd, 0x300, (UINT) &msg, callRet); */
A Windows that receives a message will receive a response data through a WPARAM and a response result through a LPARAM. If a callRet is 0, it means the response will be normal, and -1 means an error occurred. The cause of an error can be known through a tperrno value.
A WinTmaxSend() does not support transactions due to its structure and is not affected by a BLOCKTIME in a Tmax configuration file or a tpsettimeout(). However, when calling a WinTmaxSend(), if a TPBLOCK flag is given, a BLOCKTIME will be applied according to a corresponding flag.
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | If a WinTmaxSend() function is used without this flag, a normal result will be returned even if a called service did not exist in a svc or an invalid result was returned. Errors can be checked at the time of receiving a result. Using this flag, it is possible to check whether a service status is normal or not normal at the time of calling a function. In other words, a WinTmaxSend() checks if a request service can be processed normally within a BLOCKTIME and returns the result. If a service cannot be processed, an error will be stored in a tperrno and a -1 will be returned. If it is impossible to check if a requested service can be processed within a BLOCKTIME, a TPETIME error will be returned. In this case, a client cannot know whether a requested service is processed or not, so an error routine must be written carefully. If a request should be sent again, an error routine must be to check if a previous request was processed. |
TPNOREPLY | Immediately returns a service request sent with a WinTmaxSend() function without waiting for a response. A worker thread receives the result and sends it to the a specified Windows. However, a TPNOREPLY flag will be set to not receive a response for the service. |
TPNOTRAN | If a WinTmaxSend() function caller requests a svc service by setting this flag in a transaction mode, the svc service will be executed while being excluded from the transaction mode. If a svc does not support transactions in a transaction mode, a flag must be set to a TPNOTRAN when a WinTmaxSend() function is called in the transaction mode. If called in the transaction mode, the WinTmaxSend() function will still be affected by a transaction timeout even though a service flag was set to TPNOTRAN. If the service called with a TPNOTRAN fails, it will not affect a caller's transaction. |
TPNOBLOCK | Upon encountering a blocking condition with this flag set (e.g., an internal buffer is filled with messages to be transmitted), a service request will fail. When calling a WinTmaxSend() function without setting a TPNOBLOCK flag and encountering a blocking condition, a function caller will wait until blocking is released or a timeout (transaction timeout or blocking timeout) occurs. |
TPNOTIME | A function caller must wait indefinitely until a response is received and blocking timeouts are ignored. If a WinTmaxSend() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful and a descriptor is returned. Currently this descriptor is not used. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxSend() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. For a structure, this error occurs when the structure is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests was reached. Service requests from a caller cannot be sent. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A WinTmaxSend() was called from an invalid state. For example, a TPNOREPLY was called in a transaction mode, but a TPNOTRAN was not set. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPECLOSE] | Disconnected from a Tmax system due to various reasons (e.g., network issues). |
[TPEOS] | An operating system error occurred. |
If a LPARAM of a message sent to Windows is -1, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | Occurs when a valid descriptor cannot be found when a response message is received. |
[TPEOTYPE] | Occurs when the buffer types of client and server programs do not match when a response message is received. |
[TPEPROTO] | A WinTmaxStart() or a WinTmaxEnd() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPECLOSE] | Disconnected from a Tmax system due to various reasons (e.g., network issues). |
[TPEOS] | An operating system error occurred. |
Example
... int CTMaxGwView::SendData2(char *data, long nLen) { CString szTemp; m_send_length.Format(“%d”,nLen); UpdateData(FALSE); char *tpbuf = tpalloc(“STRING”, NULL, nLen); if (tpbuf == NULL) { szTemp.Format(“tpalloc Error [%s]”, tpstrerror(tperrno)); LogDisplay2(2, (char *)(const char *)szTemp, szTemp.GetLength()); return -1; } memcpy(tpbuf, data, nLen); CString strService; strService.Format(“TOUPPER_STRING”); int nSendResult=WinTmaxSend(2,(LPSTR)(LPCSTR)strService, (char*)tpbuf, nLen, 0); tpfree(tpbuf); … }
Related Functions
WinTmaxStart(),WinTmaxEnd()
The WinTmaxSetContext function, available in a client in a Windows system environment, controls window handles and message types.
This function, used in a Windows environment, manages specified Windows handles and message types by storing them in a vacant slot of a library. Using this information, when a working thread receives a reply, it will send data to the specified Windows in the specified type. The following is the data transmission format:
SendMessage(winhandle, msgType, (UINT) &msg, callRet)
In a Windows environment, a WARM corresponds to a msg and a LARA corresponds to a callRet. A msg is a TPSVCINFO structure and a callRet indicates a result of the process. If a proper message is received, a callRet is 0, and if an improper message is received, a callRet is -1.
For example, if a service is processed as atpreturn (TPSUCCESS, …), or a service fails with a tpreturn (TPFAIL, …), or an unrequested message is received, a callRet becomes 0, since it will be considered as a proper message was received. However, if a synchronous or conversational message is delivered, a callRet will be -1 because those message types cannot be used in a multi Window environment. If a callRet value is -1, a tperrno value can be checked to know the error cause.
Prototype
# include <WinTmax.h> int WinTmaxSetContext(void *winhandle, unsigned int msgType, int slot)
Parameter
Parameter | Description |
---|---|
winhandle | A windows handle to process received data. |
msgType | A message type. |
slot | Indicates a slot used to allocate a specified Windows handle and message type. The maximum available number of slots is 256, and 0 and 1 are internally specified within a system for a default display and error respectively. Thus, if an error occurs while receiving data or a Windows for display is not specified, a default Windows is used. The default slots can be redefined by a user. In case of an unrequested message, a user defined Windows will not exists, so messages are delivered to the number 0 default display Windows. |
The values available for the slot are as follows.
Configuration Value | Description |
---|---|
–1 | Allocates a specified Windows handle and message type by automatically searching for vacant slots within a system. |
0 or a value greater than 0 | Allocates a specified Windows and message type to a slot specified with a given index. |
Return Value
Value | Description |
---|---|
index | A function call was successful and an index for a slot was returned. As well, an index is used as a first parameter of a WinTmaxSend(). |
-1 | A function call failed. A tperrno is set to an error code. |
Error When a WinTmaxSetContext() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. |
[TPEOS] | An operating system error occurred. |
Example
... int CTMaxGwView::Connect() { CString szTemp, Fname; WinTmaxEnd(); int Ret = tmaxreadenv(TMAXINI, “TMAX117”); if(Ret<0) { szTemp.Format(“tmaxreadenv error”); LogDisplay2(2, (char *)(const char *)szTemp, szTemp.GetLength()); return FALSE; } if (WinTmaxStart((TPSTART_T *)NULL) == -1) { szTemp.Format(“WinTmaxStart 에러 = [%s]”, tpstrerror(tperrno)); LogDisplay2(2, (char *)(const char *)szTemp, szTemp.GetLength()); return FALSE; } WinTmaxSetContext(m_hWnd, WM_TMAX_RECV_RDP, 0); WinTmaxSetContext(m_hWnd, WM_TMAX_RECV_ERR, 1); WinTmaxSetContext(m_hWnd, WM_TMAX_RECV, 2); return TRUE; }
Related Functions
WinTmaxStart(),WinTmaxEnd(), WinTmaxSend()
The WinTmaxStart function, available in a client in a Windows system environment, is used to connect to a Tmax system in a multi-Windows environment. This function is identical to a tpstart(). When using multiple threads, connections should be respectively established per thread through a WinTmaxStart().
Prototype
# include <WinTmax.h> int WinTmaxStart(TPSTART_T *tpinfo)
Parameter
Refer to "3.3.10. tpstart" for more information about a TPSTART_T.
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxStart() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a tpinfo is NULL or not a pointer for a TPSTART_T. |
[TPEITYPE] | A tpinfo is not a pointer for a TPSTART_T structure. |
[TPEPROTO] | A WinTmaxStart() was called in an inappropriate condition. For example, a WinTmaxStart() was called in a server program, or it was called after a connection was already established. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Environment variables may be invalid. For example, a connection failed because a TMAX_BACKUP_ADDR or TMAX_BACKUP_PORT was invalid. |
Related Functions
tpstart(), WinTmaxEnd(), WinTmaxSend(), WinTmaxSetContext()
The tlog_close function closes a log file as one of the functions that analyze transaction logs. It can be used separately from a Tmax engine by using <usring/tlog.h> and <libtlog.so> libraries.
Prototype
#include <usring/tlog.h> int tlog_close (tlog_file_t *log);
Parameter
Parameter | Description |
---|---|
log | A log is filled with internal information regarding a corresponding log file when calling a tlog_open(), and it is a pointer for a structure that is used for a tlog_find. |
Return Value
Value | Description |
---|---|
TLOG_OK | A function call was successful. |
Negative number | A function call failed. |
Example
#include <stdio.h> #include <usrinc/tlog.h> int main(int argc, char *argv[]) { int n; tlog_entry_t entry; tlog_file_t log; printf(“\n===== TXLOG =====\n”); n = tlog_open(NULL, &log, TLOG_LOCAL); printf(“n = %d\n”, n); if (n < 0) { printf(“tlog_open = %d, errno = %d\n”, n, errno); exit(1); } ... tlog_close(&log); }
Related Functions
tlog_close(), tlog_find(), tlog_nodeno()
The tlog_find function finds an entry that matches specified information from a transaction log file. The result is saved in an "entry" parameter and returned. It can be used separately from a Tmax engine by using <usring/tlog.h> and <libtlog.so> libraries.
Prototype
#include <usring/tlog.h> int tlog_find (tlog_file_t *log, tlog_entry_t *entry, int flags);
Parameter
Parameter | Description |
---|---|
log | A tlog information structure created with a tlog_open. |
entry | An entry to retrieve. |
flags | Flag values are listed in the table below. |
A tlog_entry_t shows the contents contained in a corresponding transaction log file. The details are as follows:
typedef struct { int decision; TXID xid; time_t ltime; /* following fields have meaning only for TLOG_REMOTE & TLOG_NONTMAX */ TXID remote_xid; char gateway_name[GATEWAY_NAME_SIZE]; } tlog_entry_t;
Member | Description |
---|---|
decision | Records an action that was taken for a transaction. |
xid | Records a log. Two fields of a remote_xid and a gateway_name are added into the transaction logs that were recorded by a gateway. |
ltime | Time at which a log was recorded. |
The values available for a decision are defined as shown below:
/* invalid entry */ #define TXDEC_INVALID -1 /* commit */ #define TXDEC_COMMIT 0 /* rollback */ #define TXDEC_ROLLBACK 1 /* rollback due to svr/cli down or failure during the prepare phase */ #define TXDEC_ABNORMAL_ROLLBACK 2 /* tx initiated from a remote domain */ #define TXDEC_REMOTE 3 /* prepare phase */ #define TXDEC_PREPARE 4
Flags have six kinds of macro and bit-wise OR:
/* get next log entry */ #define TLOG_NEXT 0x0001 /* find an entry logged later than or equal to the ltime field */ #define TLOG_TIME 0x0002 /* find an entry with matching xid */ #define TLOG_XID 0x0004 /* find an entry with matching remote_xid */ #define TLOG_REMOTE_XID 0x0008 /* find an entry from the matching gateway_name field */ #define TLOG_GATEWAY 0x0010 /* find an entry with same decision */ #define TLOG_DECISION 0x0020
Constant Value | Description |
---|---|
TLOG_NEXT | If a TLOG_NEXT bit is on, a current location of a log file will be used for a search, and if not, the start of the file will be used. |
TLOG_TIME | If a TLOG_TIME bit is on, only entries that come after an entry->ltime will be searched. |
TLOG_XID | A TLOG_XID searches only for an entry that matches an entry->xid. For a XID comparison, a branch qualifier will be ignored and only a global transaction ID will be referred to. |
TLOG_REMOTE_XID | A TLOG_REMOVE_XID searches an entry that has matched an entry->remote_xid. |
TLOG_GATEWAY | A TLOG_GATEWAY searches an entry that has matched an entry->gateway_name . |
TLOG_DECISION | A TLOG_DECISION searches an entry that has matched an entry->decision. |
Return Value
Value | Description |
---|---|
TLOG_OK | A function call was successful. |
TLOG_INVAL | An argument was not valid. |
TLOG_NOTFOUND | A search was conducted to the end of a file and further searching cannot be conducteed. |
TLOG_ESYSTEM | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
Example
#include <stdio.h> #include <usrinc/tlog.h> int main(int argc, char *argv[]) { int n; tlog_entry_t entry; tlog_file_t log; printf(“\n===== TXLOG =====\n”); n = tlog_open(NULL, &log, TLOG_LOCAL); printf(“n = %d\n”, n); if (n < 0) { printf(“tlog_open = %d, errno = %d\n”, n, errno); exit(1); } printf(“tlog_open success\n”); while(1) { n = tlog_find(&log, &entry, TLOG_NEXT); if (n == TLOG_NOTFOUND) { printf(“Not found any more\n”); break; } else if (n < 0) { printf(“tlog_find = %d, errno = %d\n”, n,errno); tlog_close(&log); exit(1); } tlog_close(&log); }
Related Functions
tlog_open(), tlog_close(), tlog_nodeno()
The tlog_nodeno function finds the number of a node where a transaction starts using a XID. Since transaction logs are left in a node where a transaction starts in a multi-node configuration, it needs to know which node uses a XID. It can be used separately from a Tmax engine by using <usring/tlog.h> and <libtlog.so> libraries.
Prototype
#include <usring/tlog.h> int tlog_nodeno (TXID *xid);
Parameter
Parameter | Description |
---|---|
xid | A XID used to search a node number. |
Return Value
Value | Description |
---|---|
Node number | A function call was successful and the node number in which a transaction has started is returned. |
Negative number | A function call failed. |
Example
#include <stdio.h> #include <usrinc/tlog.h> int main(int argc, char *argv[]) { int n, nodeno; tlog_entry_t entry; tlog_file_t log; printf(“\n===== TXLOG =====\n”); n = tlog_open(NULL, &log, TLOG_LOCAL); printf(“n = %d\n”, n); if (n < 0) { printf(“tlog_open = %d, errno = %d\n”, n, errno); exit(1); } printf(“tlog_open success\n”); while(1) { n = tlog_find(&log, &entry, TLOG_NEXT); ... } nodeno = tlog_nodeno(&(entry.xid)); printf(“nodeno of txlog = %d\n”, nodeno); tlog_close(&log); }
Related Functionslog_open(), tlog_close(), tlog_find()
The tlog_open function opens a log file as one of the functions that analyze transaction logs. It can be used separately from a Tmax engine by using <usring/tlog.h> and <libtlog.so> libraries.
Prototype
#include <usring/tlog.h> int tlog_open (char *name, tlog_file_t *log, int flags);
Parameter
Parameter | Description |
---|---|
name | A log file name. |
log | Internal information of a log file. This parameter is used in a tlog_close() and a tlog_find(). |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TLOG_LOCAL | Retrieves a TX log of a local node. |
TLOG_REMOTE | Retrieves TX logs generated through a domain gateway. |
TXLOG | Writes logs of a 2PC operations within a node. |
GWTXLOG | When transaction requests are transmitted through a gateway enabled in a node, the information of a remote_xid and local_xid mapping information is recorded. |
The following is the example of a parameter setting.
Open the (TMAXDIR)/log/tlog/TXLOG file.
name = NULL, flags = TLOG_LOCAL
Open the $(TMAXDIR)/log/tlog/GWTXLOG file.
name = NULL, flags = TLOG_REMOTE
name != NULL
name = entered_name, flags = TLOG_LOCAL
Return Value
Value | Description |
---|---|
TLOG_OK | Returned when a log file is successfully opened. |
Negative number | Returned when a log file is successfully opened but an error occurred. |
Example
#include <stdio.h> #include <usrinc/tlog.h> int main(int argc, char *argv[]) { int n; tlog_entry_t entry; tlog_file_t log; printf(“\n===== TXLOG =====\n”); n = tlog_open(NULL, &log, TLOG_LOCAL); printf(“n = %d\n”, n); if (n < 0) { printf(“tlog_open = %d, errno = %d\n”, n, errno); exit(1); } printf(“tlog_open success\n”); ... }
Related Functions
tlog_close(), tlog_find(), tlog_nodeno()
The Usiginit function initializes a Tmax signal handler as a function to be used to set a macro which is necessary for user signal handling. It is not used in Windows.
Prototype
# include <usignal.h> int Usiginit(void)
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is not set to an error code even though an error occurred. |
Example
... #include <signal.h> #include <usrinc/usignal.h> void sig_alrm(int); SERVICE(TPSVCINFO *msg) { int i, ret; data process... ret=Usiginit(); if (ret==-1) { error processing } Usignal(SIGALRM, &sig_alrm); alarm(1); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); } void sig_alrm(int signo) { if (signo == SIGALRM) printf(“SIGALRM recieve\n”); }
The Usignal function is used to set macros for user signal handling. It is not used in a Windows system environment. The default Tmax signal handler handles SIGALRM, SIGPIPE, and SIGTERM for internal implementations.
If a user also tries to handle these signals using signal() system calls, internal Tmax mechanisms that depend on this signal handling may not work. To prevent these situations, a Tmax library provides a Usignal() API. A Usignal() manages an internal table that keeps a record of user signal handlers. When a signal occurs, a Tmax signal handler looks up the table. If a user signal handler is installed, Tmax will invoke a user signal handler first. After finishing user signal handling, a Tmax signal handler will take effect.
Prototype
# include <usignal.h> Sigfunc *Usignal(int sig, Sigfunc *func)
Parameter
Parameter | Description |
---|---|
sig | The number of a parameter. (e.g.: 9 or SIGKILL) |
func | A value to call a function. |
Return Value
Value | Description |
---|---|
User signal handler | Returns a previous user signal handler if any exists. |
SIG_DFL | Returned when a previous user handler signal does not exist. (A value is not specified to a tperrno even when an error occurs.) |
Example
... #include <signal.h> #include <usrinc/usignal.h> void sig_alrm(int); SERVICE(TPSVCINFO *msg) { int i, ret; data process... ret=Usiginit(); if (ret==-1) { error processing } Usignal(SIGALRM, &sig_alrm); alarm(1); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); } void sig_alrm(int signo) { if (signo == SIGALRM) printf(“SIGALRM recieve\n”); }
A variable where an integrated error code is set when an error occurred during a system call.
int Uunixerr
When an ATMI API call fails and a tperrno is set to a TPEOS, a Uunix_err function writes the type of system error to a stderr.
Prototype
# include <Uunix.h> void Uunix_err (char *msg)
Parameter
Parameter | Description |
---|---|
msg | The messages that follow the name of a system call that failed. Generally, a program name is recorded. One of the followings are displayed: UCLOSE, UCREAT, UEXEC, UFCTNL, UFORK, ULSEEK, UMSGCTL, UMSGGET, UMSGSND, UMSGRCV, UOPEN, UPLOCK, UREAD, USEMCTL, USEMGET, USEMOP, USHMCTL, USHMGET, USHMAT, USHMDT, USTAT, UWRITE, USBRK, USYSMUL, UWAIT, UKILL, UTIME, UMKDIR, ULINK, UUNLINK, UUNAME, UNLIST |
Example
ret=tmaxreadenv("NO THAT FILE", "TMAX"); if (ret<0) { Uunix_err("myprog"); exit(1); }
The following is a result of implementing the example above.
mypog: UOPEN
The Ustrerror function returns an integrated error message for a system error code (errno).
Prototype
# include <Uunix.h> char * Ustrerror(int err);
Parameter
Parameter | Description |
---|---|
err | An integrated error number for an error message. |
Return Value
When a system call is succeeded, a pointer to an integrated error message for an errno is returned.
One of the followings is returned in a chr * type pointer:
UCLOSE, UCREAT, UEXEC, UFCTNL, UFORK, ULSEEK, UMSGCTL, UMSGGET, UMSGSND, UMSGRCV, UOPEN, UPLOCK, UREAD, USEMCTL, USEMGET, USEMOP, USHMCTL, USHMGET, USHMAT, USHMDT, USTAT, UWRITE, USBRK, USYSMUL, UWAIT, UKILL, UTIME, UMKDIR, ULINK, UUNLINK, UUNAME, UNLIST
Example
ret=tmaxreadenv("NO THAT FILE", "TMAX"); if (ret<0) { printf("%d->%s\n", Uunixerr, Ustrerror(Uunixerr)); exit(1); }
The following is a result of implementing the example above.
11->UOPEN