srv_send_data allows Open Server applications to transfer rows containing multiple columns to clients. It allows Open Server applications to send text, image, and XML data in chunks, preventing the excessive use of memory.
CS_RETCODE srv_send_data(spp, column, buf, buflen) SRV_PROC *spp; CS_INT *column; CS_BYTE *buf; CS_INT buflen;
A pointer to an internal thread control structure.
The number of the column in a row set.
A pointer to a buffer containing the data to send to the client. This determines the size of a section.
The length of the *buf buffer.
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#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); }
srv_send_data sends data of a row set column by column to a client.
When sending columns with text, image or XML data, Open Server applications must call srv_text_info before srv_send_data. This ensures the data stream is correctly set to the total length of data being sent. The application then calls srv_send_data to send the data in chunks, and continues to call the routine until there is no remaining data to be sent.
Open Server applications can send text, image and XML data to clients using srv_bind and srv_xferdata. However, these routines require all data columns to be sent at once. srv_send_data allows applications to send text and image data in chunks.
Because srv_send_data reads and sends data one column at a time, the data format for a whole row needs to be sent to the client together with the first column in the row set. To retrieve fixed I/O fields, such as object name before a column is read, call ct_data_info(). Note that the changeable fields in I/O descriptors such as pointers to text data, and length of text data are retrievable only after the column is read.
Open Server applications treat text, image and XML data streams identically, with the exception of character set conversions. These conversions are only performed on text data.
Related srv_bind, srv_get_text, srv_text_info, srv_xferdata, srv_get_data, and srv_send_text routines in the Open Server Server Library/C Reference Manual.