srv_get_text

Description

Read a text or image datastream from a client, in chunks.

Syntax

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

Parameters

spp

A pointer to an internal thread control structure.

bp

A pointer to a buffer where the data from the client is placed.

buflen

The size of the *bp pointer. This indicates how many bytes are transferred in each chunk.

outlenp

The number of the bytes read into the *bp buffer is returned here.

Returns

Table 3-48: Return values (srv_get_text)

Returns

To indicate

CS_SUCCEED

The call to srv_get_text ran successfully.

CS_FAIL

The routine failed.

CS_END_DATA

Open Server read in the entire text or image data stream.

Examples

Example 1

#include        <ospublic.h>
#include        <stdio.h>
/*
 ** Local Prototype
 */
CS_RETCODE    ex_srv_get_text        PROTOTYPE((
SRV_PROC      *spp,
CS_INT        *outlenp,
CS_BYTE       *bbuf
));
/*
 ** EX_SRV_GET_TEXT
 **
**    Example routine to read chunks of text or image datastream
 **    from a client into a buffer and then write it to a disk
 **    file.
**
** Arguments:
**
**    spp        Pointer to thread control structure.
**    outlenp    Number of bytes read and written.
**    bbuf       Pointer to very large buffer for text.
**
** Returns
**
**    CS_SUCCEED    The data was successfully read.
**    CS_FAIL       An error was detected.
 **
 */
#define    BUFSIZE     256
#define    FPUTS(a,b)      fputs(a,b)
CS_RETCODE  ex_srv_get_text(spp,outlenp,bbuf)
SRV_PROC    *spp;
CS_INT      *outlenp;
CS_BYTE     *bbuf;
{
   CS_INT       llen;    /* Local length. */
    CS_INT       lout;    /* Local read count. */
    CS_RETCODE   lret;    /* Local return code. */
    CS_BYTE      *lbufp;    /* Local pointer into bbuf. */
   /* Check arguments. */
   if(bbuf == (CS_VOID *)0)
      return(CS_FAIL);
   if(spp == (SRV_PROC *)0)
      return(CS_FAIL);
   llen = BUFSIZE;
   lbufp = bbuf;
   /*
    ** Loop around getting data and copy it to bbuf.
    */
   while(lret != CS_END_DATA)
   {
        (CS_VOID)srv_bzero(lbufp,BUFSIZE);
        lout = 0;
        lret = srv_get_text(spp, lbufp, llen, &lout);
        if(lret == CS_FAIL)
            break;
        *outlenp += lout;
        lbufp += lout;
    }
    if(lret == CS_END_DATA)
        return(CS_SUCCEED);
    else
        return(lret);
}

Usage

See also

srv_bind, srv_descfmt, srv_send_text, srv_text_info, srv_thread_props, srv_xferdata, “International support”, “Text and image”