Receive a TDS packet from a server.
RETCODE dbrecvpassthru(dbproc, recv_bufp) DBPROCESS *dbproc; DBVOIDPTR *recv_bufp;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library/C uses to manage communications and data between the front end and the server.
A pointer to a variable that dbrecvpassthru fills with the address of a buffer containing the TDS packet most recently received by this DBPROCESS connection. The application is not responsible for allocating this buffer.
DB_PASSTHRU_MORE, DB_PASSTHRU_EOM, or FAIL.
dbrecvpassthru receives a TDS (Tabular Data Stream) packet from a server.
TDS is an application protocol used for the transfer of requests and request results between clients and servers. Under ordinary circumstances, a DB-Library/C application does not have to deal directly with TDS, because DB-Library/C manages the data stream.
dbrecvpassthru and dbsendpassthru are useful in gateway applications. When an application serves as the intermediary between two servers, it can use these routines to pass the TDS stream from one server to the other, eliminating the process of interpreting the information and re-encoding it.
dbrecvpassthru reads a packet of bytes from the server connection identified by dbproc and sets *recv_bufp to point to the buffer containing the bytes.
A packet has a default size of 512 bytes. An application can change its packet size using DBSETLPACKET. See the dbgetpacket and DBSETLPACKET reference pages.
dbrecvpassthru returns DB_PASSTHRU_EOM if the TDS packet has been marked by the server as EOM (End Of Message). If the TDS packet is not the last in the stream, dbrecvpassthru returns DB_PASSTHRU_MORE.
A DBPROCESS connection which is used for a dbrecvpassthru operation cannot be used for any other DB-Library/C function until DB_PASSTHRU_EOM has been received.
This is a code fragment using dbrecvpassthru:
/*
** The following code fragment illustrates the
** use of dbrecvpassthru() in an Open Server
** gateway application. It will continually get
** packets from a remote server, and pass them
** through to the client.
**
** The routine srv_sendpassthru() is the Open
* Server counterpart required to complete
** this passthru operation.
*/
DBPROCESS *dbproc;
SRV_PROC *srvproc;
int ret;
BYTE *packet;
while(1)
{
/* Get a TDS packet from the remote server */
ret = dbrecvpassthru(dbproc, &packet);
if( ret == FAIL )
{
fprintf(stderr, "ERROR - dbrecvpassthru\
failed in handle_results.\n");
exit();
}
/* Now send the packet to the client */
if( srv_sendpassthru(srvproc, packet,
(int *)NULL) == FAIL )
{
fprintf(stderr, "ERROR - srv_sendpassthru \
failed in handle_results.\n");
exit();
}
/*
** We’ve sent the packet, so let’s see if
** there’s any more.
*/
if( ret == DB_PASSTHRU_MORE )
continue;
else
break;
}