Table of Contents
This chapter describes the functions used in UCS.
The following describes the functions used in UCS programs.
Server/Client Functions
Function | Description |
---|---|
tppost | Generates a specific event from a server or client and delivers a message. |
tpsetfd | Registers a socket FD in an external socket scheduler of a UCS process |
tpsubscribe | Subscribes to a specific event or set of events. |
tpunsubscribe | Removes an event subscription or a set of event subscriptions. |
Server Functions
Function | Description |
---|---|
tpclrfd | Turns off a socket FD in an internal fdset of a UCS-type process. |
tpissetfd | Checks if data is received in a socket FD in a UCS process. |
tpregcb | Sets a routine that receives a response for an asynchronous request of a UCS from a server. |
tprelay | Forwards a service request to another service routine that contains the information of a client that has requested the service. |
tpsavectx | Manages client information in a UCS process. |
tpschedule | Waits for data to be received in a UCS-type server process. |
tpsendtocli | Sends an unrequested message to a specified client. |
tpsvctimeout | A routine called when a service timeout occurs. |
tpsvrdown | Terminates the UCS-type server process normally. |
tpunregb | Resets a routine that receives a response for an asynchronous request. |
Client Functions
Function | Description |
---|---|
tpgetunsol | Processes unrequested messages. |
tpsetunsol | Sets a routine that processes unrequested and received messages. |
tpsetunsol_flag | Sets a notification message reception flag. |
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 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 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 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 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 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 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 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()
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 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 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 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()