Barracuda Application Server C/C++ Reference
HttpAsynchResp Struct Reference

Send data asynchronously to a client. More...

#include <HttpAsynchResp.h>

Inheritance diagram for HttpAsynchResp:

Public Member Functions

 HttpAsynchResp (char *buf, int size, HttpRequest *req)
 Initiate a HttpAsynchResp from a HttpRequest object. More...
 HttpAsynchResp (char *buf, int size, HttpConnection *con)
 Initiate a HttpAsynchResp from a HttpConnection object. More...
bool isValid ()
 Returns true if the HttpConnection object is valid – i.e., if the socket connection is alive.
void asynchThreadMode ()
 Set in asynchronous thread mode so you can call the methods in this class without having to lock the dispatcher mutex. More...
 ~HttpAsynchResp ()
 Calls method close.
void close ()
 Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1.1 socket connection object is moved back into the Web-server's HTTP 1.1 HttpConnection pool such that the connection can be recycled. More...
ThreadMutexgetMutex ()
 Get the dispatcher lock. More...
int setConClose ()
 Close connection when the HttpAsynchResp object is done. More...
int setLingeringClose ()
 Used if a resource must close an active HttpAsynchReq and data is pending. More...
int setStatus (int statusCode, const char *protocol=0)
 Set the response status code. More...
int setHeader (const char *name, const char *value)
 Sets a HTTP response header with the given name and value. More...
int sendData (const void *data, int pktSize, int chunkSize)
 Send data of known size to client. More...
int sendNextChunk (const void *data, int chunkSize)
 Send next chunk if not all data was sent with sendData. More...
BufPrintgetWriter ()
 BufPrint is used when sending data of unknown length. More...
- Public Member Functions inherited from HttpConnection
struct HttpServergetServer ()
 Fetch the HttpServer object.
void setKeepAlive ()
 Close connection after request completed.
void clearKeepAlive ()
 Keep connection after request completed, i.e. More...
- Public Member Functions inherited from SoDispCon
int connect (const char *host, U16 port, const void *bindIntfName=0, U16 bindPort=0, U32 timeout=1500, BaBool dgram=false, BaBool ipv6=false, char **errinfo=0)
 Connect to host/IP address. More...
bool isSecure ()
 Deprecated: Use getSharkSslCon(NULL).
bool getSharkSslCon (SharkSslCon **sc)
 Returns true if this is an SSL connection. More...
bool isValid ()
 Returns true if the socket connection is valid.
bool isIP6 ()
 Returns true if this is an IP version 6 connection.
int getPeerName (HttpSockaddr *addr, U16 *port=0)
 Returns the 'peer' IP address. More...
int getSockName (HttpSockaddr *addr, U16 *port=0)
 Returns the 'sock' IP address. More...
char * addr2String (HttpSockaddr *addr, char *buf, int len)
 Converts IP address to string.
bool cmpAddr (HttpSockaddr *addr2)
 Compare addr with address returned by getPeerName.
void setTCPNoDelay (bool enable)
 Disable the TCP delay. More...
struct SoDispgetDispatcher ()
 Fetch the SoDisp object.
bool hasMoreData ()
 Returns true if more data on the socket.
bool dispatcherHasCon ()
 Returns true if connection is in the SoDisp object.
bool recEvActive ()
 Returns true if the connection is active in the SoDisp object.
bool sendEvActive ()
 Used for non blocking send.

Detailed Description

Send data asynchronously to a client.

Please see the HTTP protocol stack for an introduction to the HttpAsynchResp class.

You must lock the dispatcher prior to calling any methods in the HttpAsynchResp class unless the object is used from within a Barracuda event callback or you have called method HttpAsynchResp::asynchThreadMode. See using multiple threads in the Barracuda introduction for more information on protecting the Barracuda code.

There is one exception to the above. You can call method HttpAsynchResp::getMutex without locking the dispatcher first. You cannot lock the dispatcher unless you first have a reference to the dispatcher object.

example code

myAsynchResp->getWriter()->printf("Hi client");

Certain restrictions apply to how you can use this object. This is, after all, a lightweight version of HttpResponse. The HttpAsynchResp object does not have large buffers for storing out data. Thus, the methods must be called in the following order:

Calling methods setConClose, setStatus, and setHeader are optional.

Calling method setHeader implicitly calls method setStatus with status code 200 unless you already called setStatus.

Sending data using method sendData or the methods in BufPrint flushes the HTTP header. Thus, you cannot call method setHeader after the HTTP header is flushed.

You must use one of BufPrint or ( HttpAsynchResp::sendData [ & HttpAsynchResp::sendNextChunk ] ) when sending response data.

This class provides an easy and less error prone way of locking and releasing a mutex.
Definition: ThreadLib.h:116
int sendData(const void *data, int pktSize, int chunkSize)
Send data of known size to client.
Definition: HttpAsynchResp.h:312