tpf_srvcSendResponse: Send service response message
This function sends a service response message to the asynchronous service message handler.
Last updated
- Changed for PUT15.
- Added for PUT14.
Format
LIBS := CSVC
#include <tpf/services.h>
int tpf_srvcSendResponse(tpf_srvc_token token,
tpf_srvc_resp *response,
int options);- token
- The z/TPF service connection token, which identifies the service requester that the response is sent to.
- response
- A pointer to a service response structure that contains the following
information to build and send the service response:
- data
- A pointer to the service response data.
- datalen
- An integer that indicates the length of the service response data.
- status
- An integer that indicates the status of the service response.
- status_reason
- One of the following values:
- A pointer to a null-terminated string that describes the status of the service response.
- NULL.
- httpsvr
- A tpf_httpsvr_resp structure. This parameter is valid only when the options parameter is specified as TPF_SRVC_SEND_RAW.
- options
- Specifies the processing options for this function. Specify one
of the following values:
- TPF_SRVC_SEND_RAW
- The tpf_httpsvr_resp structure is used for the response instead of other fields. For more information about this structure, see the tpf_httpSendResponse function.
- 0
- No special processing is requested.
Normal return
A value of 0.
Error return
A value of -1 is returned and errno is set to one
of the following values:
- ETPF_HTTPSENDRSP_CONNECTION_CLOSED
- The client connection associated with the input token was closed.
- ETPF_HTTPSENDRSP_MALLOC_ERR
- API processing was unable to allocate malloc storage to send the service response message.
- ETPF_HTTPSENDRSP_NOT_STATEFUL_ECB_SEND_ERR
- The stateful service response can be sent only from the stateful ECB for that service request.
- ETPF_HTTPSENDRSP_RESPONSE_ERR
- The pointer to the service response structure was NULL or not pointing to addressable storage. Error status 500 is returned to the caller.
- ETPF_HTTPSENDRSP_SOCKET_ERR
- An error occurred when the response is being sent by using the associated service requester connection.
- ETPF_HTTPSENDRSP_STATUS_ERR
- The status code in the service response structure was not valid. Error status 500 is returned to the caller.
- ETPF_HTTPSENDRSP_SYNTAX_ERR
- Data passed in the service response structure was not valid. Error status 500 is returned to the caller.
- ETPF_HTTPSENDRSP_TOKEN_ERR
- The input token was NULL or not valid, or the associated service request already timed out.
Programming considerations
- The status_reason portion of the response is EBCDIC 1047 on input and is translated to ASCII before the response message is sent.
- After a service response message is sent successfully, the z/TPF service connection token is released and no longer valid for use.
Examples
The following example sends a normal
response to the REST service
requester.
#include <tpf/services.h>
#include <tpf/tpfapi.h>
#include <errno.h>
typedef struct {
char first_name[20];
char last_name[20];
char address[40];
char card_num[16];
} indata;
typedef struct {
long fgn;
} outdata;
void QXRH(indata *request_data, unsigned int request_length,
tpf_srvc_token token)
{
tpf_srvc_resp response;
outdata *response_data = NULL;
int resp_data_len = 0;
int rc;
char msgbuf[40];
/* call request services to get response information */
response.status = TPF_SRVC_OK;
response.data = response_data;
response.datalen = resp_data_len;
rc = tpf_srvcSendResponse(token, &response, 0);
if (rc) {
sprintf(msgbuf, "Error sending response, errno = %d\n",
errno);
wtopc(msgbuf, WTOPC_PRC, WTOPC_NO_CHAIN, NULL);
}
exit(0);
}