New srv_send_data routine added

Description

The new API routine, srv_send_data, allows Open Server applications to transfer rows containing multiple columns to clients. It allows Open Server applications to send text and image data in chunks, preventing excessive utilization of memory.

Syntax

CS_RETCODE srv_send_data(spp, column, buf, buflen)
SRV_PROC  *spp;
CS_INT         *column;
CS_BYTE      *buf;	
CS_INT          buflen;

Parameters

spp

A pointer to an internal thread control structure.

column

The number of the column in a row set.

buf

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

buflen

The length of the *buf buffer.

Return Value

Table 6: Return values (srv_send_data)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Example

#include <ctpublic.h>
#include <ospublic.h>
/*
** Local Prototype.
*/
CS_RETCODE ex_srv_send_data PROTOTYPE((
	SRV_PROC *spp,
	CS_COMMAND *cmd,
	CS_INT cols
));
#define MAX_BULK 51200/*
** EX_SRV_SEND_DATA** Example routine to demonstrate how to write columns
** of data in a row set to a client using srv_send_data.
** This routine will send all the columns of data 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.
** cols The number of columns in a row set.

** Returns:
** CS_SUCCEED Result set sent successfully to client.
** CS_FAIL An error was detected.
*/
CS_RETCODE ex_srv_send_data(spp, cmd, cols)
SRV_PROC *spp;
CS_COMMAND *cmd;
CS_INT cols;
{
	CS_INT *len;		/* Length of column data. */
	CS_INT	 *outlen;	/* Number of bytes received. */
	CS_BYTE	 **data;		/* Column data. */
	CS_BYTE	 buf[MAX_BULK]; /* Buffer for text data. */
	CS_BOOL 	ok; 		/* Error control flag. */
	CS_INT 	 i;
	CS_INT 		 ret;
	
	/* Initialization. */
	ok = CS_TRUE;
	/*
	** Transfer a row.
	*/
	for (i = 0; i < cols; i++)
	{
		if ((fmt[i].datatype != CS_TEXT_TYPE) &&
		    (fmt[i].datatype != CS_IMAGE_TYPE))
		{
			/*
			** Transfer a non TEXT/IMAGE column.
			*/
			/* 
			** Read the data of a non-text/image column
			** from the server. 
			*/
			ret = ct_get_data(cmd, i+1, data[i],
				len[i], &outlen[i]);
			if ((ret != CS_SUCCEED) 
				&& (ret != CS_END_DATA)
				&& (ret != CS_END_ITEM))
			{
				ok = CS_FALSE;
				break;
			}
			/* 
			** Write the data of a non-text/image column 
			** to client. 
			*/
			if (ret = srv_send_data(srvproc, i+1,
					 NULL, 0) != CS_SUCCEED)
			{
				ok = CS_FALSE;
				break;
			}
		}
		else
		{
			/*
			** Transfer a TEXT/IMAGE column in small   
			** trunks.
			*/
			/* 
			** Read a chunk of data of a text/image column
			** from the server. 
			*/
			while ((ret = ct_get_data(cmd, i+1, buf, 
				MAX_BULK, &len[i])) == CS_SUCCEED)
			{
				/* Write the chunk of data to client. */
				if (ret = srv_send_data(srvproc, i+1, buf, 
					len[i]) != 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 row’s data. */
	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);
}

NoteFor more information on using srv_send_data, refer to ctos_procmultitextcol in the ctos.c sample program.

Usage

See also

Related srv_bind, srv_get_text, srv_text_info, srv_xferdata, srv_get_data, and srv_send_text routines in the Open Server 15.0 Server Library/C Reference Manual.