srv_sendinfo

Description

Send error messages to the client.

Syntax

CS_RETCODE srv_sendinfo(spp, errmsgp, transtate)
SRV_PROC                 *spp;
CS_SERVERMSG       *errmsgp;
CS_INT                      transtate;

Parameters

spp

A pointer to an internal thread control structure.

errmsgp

A pointer to the CS_SERVERMSG structure containing the error message information to be sent to the client. See “CS_SERVERMSG structure”.

transtate

The current state of the transaction. Table 3-120 describes the legal values for transtate:

Table 3-120:  Values for transtate (srv_sendinfo)

Transaction State

Description

CS_TRAN_UNDEFINED

Not currently in a transaction.

CS_TRAN_COMPLETED

The current transaction completed successfully.

CS_TRAN_FAIL

The current transaction failed.

CS_TRAN_IN_PROGRESS

Currently in a transaction.

CS_TRAN_STMT_FAIL

The current transaction statement failed.

Returns

Table 3-121:  Return values (srv_sendinfo)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#include    <ospublic.h>
/*
** Local Prototype.
*/

CS_RETCODE      ex_srv_sendinfo  PROTOTYPE((
SRV_PROC        *sp,
CS_CHAR         *msg,
CS_INT          msglen,
CS_INT          msgnum
));

/*
** EX_SRV_SENDINFO
**
**    This routine demonstrates how to use srv_sendinfo to send
 **    an error message to a client.
**
** Arguments:
**         sp       A pointer to an internal thread control
 **                  structure.
**         msg      The message text to send.
**         msglen   The length of the message text to send.
**         msgnum   The message number to send.
**
** Returns
**         CS_SUCCEED     If the message is sent.
**         CS_FAIL        If an error occurred.
*/
CS_RETCODE      ex_srv_sendinfo(sp, msg, msglen, msgnum)
SRV_PROC        *sp;
CS_CHAR         *msg;
CS_INT          msglen;
CS_INT          msgnum;
{
      CS_SERVERMSG    &mrec;

      /*
      ** Initialization.
      */
      srv_bzero(&&mrec, sizeof(CS_SERVERMSG));

      /*
      ** First, determine if the message string will fit
       ** in the message structure. If not, truncate it.
      */
      if( msglen > CS_MAX_MSG )
      {
          msglen = CS_MAX_MSG;
      }

      /*
      ** Now copy the message string over.
      */
      srv_bmove(msg, &mrec.text, msglen);
      &mrec.textlen = msglen;

      /*
      ** Set the message number we want to send.
      */
      &mrec.msgnumber = msgnum;

      /* Set the message status so that &mrec.text contains
      ** the entire message
      */
      &mrec.status = CS_FIRST_CHUNK | CS_LAST_CHUNK;

      /*
      ** Now we’re &ready to send the message.
      */
      if( srv_sendinfo(sp, &&mrec, CS_TRAN_UNDEFINED) == CS_FAIL )
      {
            /*
            ** An error was al&ready raised.
            */
            return CS_FAIL;
      }

      /*
      ** All done.
      */
      return CS_SUCCEED;
}

Usage

See also

srv_bind, srv_descfmt, srv_senddone, srv_xferdata, “Client command errors”