srv_send_text

Description

Send a text or image data stream to a client, in chunks.

Syntax

CS_RETCODE srv_send_text(spp, bp, buflen)
SRV_PROC        *spp;
CS_BYTE           *bp;
CS_INT              buflen;

Parameters

spp

A pointer to an internal thread control structure.

bp

A pointer to a buffer containing the data to send to the client. This determines the size of a section.

buflen

The size of the *bp buffer.

Returns

Table 3-116:  Return values (srv_send_text)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#include    <ctpublic.h>
#include    <ospublic.h>

/*
** Local Prototype.
*/
CS_RETCODE ex_srv_send_text PROTOTYPE((
SRV_PROC    *spp,
CS_COMMAND  *cmd
));

/*
** EX_SRV_SEND_TEXT
**
**   Example routine to demonstrate how to write text to a client
 **   using srv_send_text. This routine will send all the text
 **   read from a server back to the client.
**
** Arguments:
**   spp   A pointer to an internal thread control structure.
**   cmd   The command handle for the command that is returning
 **         text data.
**
** Returns:
**   CS_SUCCEED   Result set sent successfully to client.
**   CS_FAIL      An error was detected. 
*/
CS_RETCODE      ex_srv_send_text(spp, cmd)
SRV_PROC       *spp;
CS_COMMAND     *cmd;
{
   CS_BOOL     ok;            /* Error control flag.    */
   CS_INT      ret;           /* ct_fetch return value.  */
   CS_INT      len_read;      /* Amount of data read.    */
   CS_BYTE     data[1024];    /* Buffer for text data.    */

   /* Initialization. */
   ok = CS_TRUE;

   /* Read the text from the server. */
   while ((ret = ct_get_data(cmd, 1, data, CS_SIZEOF(data),
          &len_read))
         == CS_SUCCEED)
   {
         /* Write text to client a chunck at a time */
         if (srv_send_text(spp, data, len_read) != CS_SUCCEED)
         {
                ok = CS_FALSE;
                break;
         }
   }

   switch(ret)
   {
   case CS_SUCCEED:    /* The routine completed successfully. */
   case CS_END_ITEM:   /* Reached the end of this item’s value. */
   case CS_END_DATA:   /* Reached the end of this item’s value. */
        break;
   case CS_FAIL:       /* The routine failed.  */
   case CS_CANCELED:  /* The get data operation was cancelled. */
   case CS_PENDING:    /* Asynchronous network I/O is in effect. */
   case CS_BUSY:       /* An asynchronous operation is pending. */
   default:
          ok = CS_FALSE;
   }

   return (ok ? CS_SUCCEED : CS_FAIL);
}

Usage

WARNING! An Open Server application can only use srv_send_text to send a row if that row contains a single column and that column contains text or image data.

See also

srv_bind, srv_descfmt, srv_get_text, srv_text_info, srv_xferdata, “Text and image”