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

dr_net_write() Function

The dr_net_write function sends a response back to the requestor after constructing the full page with hdr, the content of the cached entry as the body located using the key, and ftr. The hdr, ftr, or hdl can be NULL, but not all of them can be NULL. If hdl is NULL, no cache lookup is done. The caller must pass DR_NONE as the flag.

By default, this function refreshes the cache entry if it has expired by making a call to the ref function passed to dr_cache_init. If no cache entry is found with the specified key, this function adds a new cache entry by calling the ref function before sending out the response. However, if the DR_CHECK flag is passed in the flags parameter and if either the cache entry has expired or the cache entry corresponding to the key does not exist, dr_net_write does not send any data out. Instead, the function returns with DR_EXPIR.

If ref which is passed to dr_cache_init is NULL, the DR_CHECK flag is not passed in the flags parameter, and the cache entry corresponding to the key has expired or does not exist, then dr_net_write fails with DR_ERROR. However, dr_net_write refreshes the cache if ref is not NULL and DR_CHECK is not passed.

If ref which is passed to dr_cache_init is NULL and the DR_CHECK flag is not passed but DR_IGNORE is passed and the entry is present in the cache, dr_net_write sends out the response even if the entry has expired. However, if the entry is not found, dr_net_write returns DR_ERROR.

If ref which is passed to dr_cache_init is not NULL and the DR_CHECK flag is not passed but DR_IGNORE is passed and the entry is present in the cache, dr_net_write sends out the response even if the entry has expired. However, if the entry is not found, dr_net_write calls the ref function and stores the new entry returned from ref before sending out the response.

Syntax

PRInt32 dr_net_write(DrHdl hdl, const char *key, PRUint32 klen, const char *hdr, 
                    const char *ftr, PRUint32 hlen, PRUint32 flen, 
                    PRIntervalTime timeout, PRUint32 flags, 
                    Request *rq, Session *sn);

Return Values

IO_OKAY if successful.

IO_ERROR if an error occurs.

DR_ERROR if an error in cache handling occurs.

DR_EXPIR if the cache has expired.

Parameters

The following table describes parameters for the dr_net_write function.

DrHdl hdl

Persistent handle created by the dr_cache_init function

const char *key

Key to cache, search, or refresh

PRUint32 klen

Length of the key in bytes

const char *hdr

Any header data, which can be NULL.

const char *ftr

Any footer data, which can be NULL.

PRUint32 hlen

Length of the header data in bytes, which can be 0.

PRUint32 flen

Length of the footer data in bytes, which can be 0.

PRIntervalTime timeout

Timeout before this function aborts.

PRUint32 flags

ORed directives for this function. See Flags.

Request *rq

Pointer to the request

Session *sn

Pointer to the session

Flags

This section describes the flags for dr_net_write function.

DR_NONE

Specifies that no cache is used, so the function works as net_write does, DrHdl can be NULL.

DR_FORCE

Forces the cache to refresh, even if it has not expired.

DR_CHECK

Returns DR_EXPIR if the cache has expired. If the calling function has not provided a refresh function and this flag is not used, DR_ERROR is returned.

DR_IGNORE

Ignores cache expiration and sends out the cache entry even if it has expired.

DR_CNTLEN

Supplies the Content-Length header and does a PROTOCOL_START_RESPONSE.

DR_PROTO

Does a PROTOCOL_START_RESPONSE.

Example

if(dr_net_write(Dr, szFileName, iLenK, NULL, NULL, 0, 0, 0, 
                DR_CNTLEN | DR_PROTO, rq, sn) == IO_ERROR)
{
    return(REQ_EXIT);
}