Sun Java System Web Server 7.0 Update 4 NSAPI Developer's Guide

netbuf_getbytes() Function

The netbuf_getbytes function reads bytes from a network buffer into a caller-supplied buffer. If the network buffer is empty, the function waits to receive data from the network buffer's socket until either at least one byte is available from the socket or the network buffer's timeout has elapsed.

Syntax

int netbuf_getbytes(netbuf *buf, char *buffer, int sz);

Return Values

The number of bytes placed into the buffer between 1 and sz if the operation is successful, the constant NETBUF_EOF on end of file, or the constant NETBUF_ERROR if an error occurred.

Parameters

netbuf *buf is the buffer from which to retrieve bytes.

char *buffer is the caller-supplied buffer that receives the bytes.

int sz is the maximum number of bytes to read.

Example

int cl = 0;

* Read the entire request body */
for (;;) {
     char mybuf[1024];
     int rv;

     rv = netbuf_getbytes(sn->inbuf, mybuf, sizeof(mybuf));
     if (rv == NETBUF_EOF) {
         log_error(LOG_INFORM, "mysaf", sn, rq,
                   "Received %d byte(s)",
                   cl);
         break;
     }
     if (rv == NETBUF_ERROR) {
         log_error(LOG_FAILURE, "mysaf", sn, rq,
                   "Error reading request body (%s)",
                   cl, system_errmsg());
         break;     }

     cl += rv;
} 

See Also

netbuf_buf2sd() Function, netbuf_close() Function, netbuf_getc() Function, netbuf_grab() Function, netbuf_open() Function