Sends a request to the server.
CS_RETCODE ct_send (command); CS_COMMAND *command;
(I) Handle for this client/server operation. This handle is defined in the associated ct_cmd_alloc call.
ct_send returns one of the following values:
Value |
Meaning |
---|---|
CS_SUCCEED (-1) |
The routine completed successfully. |
CS_FAIL (-2) |
The routine failed. This result can indicate that SNA sessions cannot be established. |
CS_CANCELLED (-202) |
The routine was canceled.
|
The following code fragment demonstrates the use of ct_send. It is taken from the sample program SYCTSAR6 in Appendix B, “Sample RPC Application.”
/*------------------------------------------------------------*/ /* Prepare the command (an RPC request) */ /*------------------------------------------------------------*/ buf_len = 4; rc = ct_command(cmd, (long) CS_RPC_CMD, rpc_cmd, buf_len, (long) CS_UNUSED); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_COMMAND failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* */ /* Setup a return parameter for NUM_OF_ROWS */ /* Describe the first parameter (NUM_OF_ROWS) */ /* */ /*------------------------------------------------------------*/ strcpy (datafmt.name, "@parm1"); datafmt.namelen = 6; datafmt.datatype = CS_INT_TYPE; datafmt.format = CS_FMT_UNUSED; datafmt.maxlength = CS_UNUSED; datafmt.status = CS_RETURN; datafmt.usertype = CS_UNUSED; buf_len = sizeof(param1); rc = ct_param (cmd, datafmt, param1, buf_len, nullind); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_PARAM CS_INT_TYPE parm1 failed", msg_size) ; no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* */ /* Describe the second parameter (DEPTNO) */ /* */ /*------------------------------------------------------------*/ strcpy (datafmt.name, "@parm2"); datafmt.namelen = 6; datafmt.datatype = CS_VARCHAR_TYPE; datafmt.format = CS_FMT_UNUSED; datafmt.maxlength = CS_UNUSED; datafmt.status = CS_INPUTVALUE; datafmt.usertype = CS_UNUSED; buf_len = sizeof(param2); rc = ct_param (cmd, datafmt, param2, buf_len, nullind); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_PARAM CS_VARCHAR_TYPE parm2 failed", msg_size) ; no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* Send the command */ /*------------------------------------------------------------*/ rc = ct_send (cmd); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_SEND failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } } /* end send_command */
The following code fragment demonstrates the use of ct_send. It is taken from the sample program SYCTSAA6 in Appendix A, “Sample Language Application.”
/*------------------------------------------------------------*/ /* Open connection to the server or CICS region */ /*------------------------------------------------------------*/ rc = ct_connect (connection, servname, server_size); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_CONNECT failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* Invokes SEND_COMMAND routine */ /*------------------------------------------------------------*/ if (no_errors_sw) send_command (); /*------------------------------------------------------------*/ /* Process the results of the command */ /*------------------------------------------------------------*/ if (no_errors_sw) { while (no_more_results == FALSE) proces_results (); } } /* end proces_input */ /********************************************************************/ /* */ /* Subroutine to allocate, send, and process commands */ /* */ /********************************************************************/ void send_command () { CS_INT rc; CS_INT *outlen; CS_INT buf_len; CS_CHAR sql_cmd[45]; /*------------------------------------------------------------*/ /* Find out what the maximum number of connections is */ /*------------------------------------------------------------*/ rc = ct_config (context, CS_GET, CS_MAX_CONNECT, &maxconnect, CS_FALSE, outlen); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_CONFIG failed", msg_size); strncpy (msgtext2, "Please press return to continue!", text_size); error_out(rc); /* reset program flags to move on with the task */ print_once = TRUE; diag_msgs_initialized = TRUE; strncpy(msgtext2, "Press Clear To Exit", text_size); }
/*-------------------------------------------------------------*/ /* Allocate a command handle */ /*-------------------------------------------------------------*/ rc = ct_cmd_alloc (connection, &cmd); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_CMDALLOC failed", msg_size); no_errors_sw = FALSE ; error_out(rc); } /*------------------------------------------------------------*/ /* Prepare the language request */ /*------------------------------------------------------------*/ strcpy(sql_cmd, "SELECT FIRSTNME, EDUCLVL FROM SYBASE.SAMPLETB"); buf_len = sizeof(sql_cmd); rc = ct_command(cmd, (long) CS_LANG_CMD, sql_cmd, buf_len, (long) CS_UNUSED); if (rc != CS_SUCCEED) { strncpy (msgstr, "CT_COMMAND failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } /*------------------------------------------------------------*/ /* Send the language request */ /*------------------------------------------------------------*/ rc = ct_send (cmd); if (rc != CS_SUCCEED) { strcpy (msgstr, "CT_SEND failed", msg_size); no_errors_sw = FALSE ; error_out (rc); } } /* end send_command */
ct_send signals the end of the data to be sent to a server (no more parameters, data, messages) and sends a request to the server.
Sending a request to a server is a three-step process. To send a request to a server, an application:
Initiates the request by calling ct_command, which initiates a language request, RPC, or message stream to send to the server.
Describes parameters for the request, using ct_param.
Not all requests require parameters. For example, an RPC may or may not require parameters, depending on the stored procedure or transaction being called.
Calls ct_send to send the request stream to the server.
ct_send does not wait for a response from the server. An application must call ct_results to verify the success of the request and to set up the results for processing.
Related functions