37#ifndef __HttpAsynchResp_h
38#define __HttpAsynchResp_h
40#include <HttpServer.h>
43#define RESPONSESTATE_IDLE 0
44#define RESPONSESTATE_WRITEMODE 1
45#define RESPONSESTATE_WRITEMODE_CHUNK 2
46#define RESPONSESTATE_BODYSENT 3
47#define RESPONSESTATE_CLOSED 4
112 void operator delete(
void* d) {
if(d)
::baFree(d); }
113 void *
operator new(size_t,
void *place) {
return place; }
114 void operator delete(
void*,
void *) { }
195 int setStatus(
int statusCode,
const char* protocol=0);
203 int setHeader(
const char *name,
const char *value);
213 int sendData(
const void* data,
int pktSize,
int chunkSize);
247BA_API
void HttpAsynchResp_constructor(
249BA_API
void HttpAsynchResp_constructor2(
251BA_API
void HttpAsynchResp_ReqRespInit(
254#define HttpAsynchResp_asynchThreadMode(o) \
255 ((o)->mutex=HttpAsynchResp_getMutex(o))
257#define HttpAsynchResp_destructor(o) HttpAsynchResp_close(o)
258#define HttpAsynchResp_getMutex(o) \
259 SoDisp_getMutex(HttpConnection_getDispatcher((HttpConnection*)(o)))
260#define HttpAsynchResp_setConClose(o)\
261 HttpConnection_clearKeepAlive((HttpConnection*)(o))
262#define HttpAsynchResp_setLingeringClose(o) (o)->doLingeringClose=TRUE
263BA_API
int HttpAsynchResp_setStatus(
265BA_API
int HttpAsynchResp_setHeader(
267BA_API
int HttpAsynchResp_sendData(
269BA_API
int HttpAsynchResp_sendNextChunk(
272#define HttpAsynchResp_isAsynchThreadMode(o) ((o)->mutex ? TRUE : FALSE)
275inline HttpAsynchResp::HttpAsynchResp(
char* buf,
int size,
HttpRequest* req) {
276 HttpAsynchResp_constructor(
this, buf, size, req);
279 HttpAsynchResp_constructor2(
this, buf, size, con);
282 return HttpAsynchResp_isValid(
this) ? TRUE : FALSE;
285 HttpAsynchResp_destructor(
this);
288 HttpAsynchResp_close(
this);
291 HttpAsynchResp_asynchThreadMode(
this);
294 return HttpAsynchResp_getMutex(
this);
297 return HttpAsynchResp_setConClose(
this);
300 return HttpAsynchResp_setConClose(
this);
303 return HttpAsynchResp_setStatus(
this, statusCode, protocol);
306 return HttpAsynchResp_setHeader(
this, name, value);
309 const void* data,
int pktSize,
int chunkSize) {
310 return HttpAsynchResp_sendData(
this, data, pktSize, chunkSize);
313 return HttpAsynchResp_sendNextChunk(
this,data,chunkSize); }
315 return HttpAsynchResp_getWriter(
this);
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
void baFree(void *p)
Deallocates space to which it points.
BufPrint * getWriter()
BufPrint is used when sending data of unknown length.
Definition: HttpAsynchResp.h:314
int setHeader(const char *name, const char *value)
Sets a HTTP response header with the given name and value.
Definition: HttpAsynchResp.h:305
ThreadMutex * getMutex()
Get the dispatcher lock.
Definition: HttpAsynchResp.h:293
void asynchThreadMode()
Set in asynchronous thread mode so you can call the methods in this class without having to lock the ...
Definition: HttpAsynchResp.h:290
int sendData(const void *data, int pktSize, int chunkSize)
Send data of known size to client.
Definition: HttpAsynchResp.h:308
~HttpAsynchResp()
Calls method close.
Definition: HttpAsynchResp.h:284
bool isValid()
Returns true if the HttpConnection object is valid – i.e., if the socket connection is alive.
Definition: HttpAsynchResp.h:281
int setConClose()
Close connection when the HttpAsynchResp object is done.
Definition: HttpAsynchResp.h:296
int setLingeringClose()
Used if a resource must close an active HttpAsynchReq and data is pending.
Definition: HttpAsynchResp.h:299
int setStatus(int statusCode, const char *protocol=0)
Set the response status code.
Definition: HttpAsynchResp.h:302
void close()
Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1....
Definition: HttpAsynchResp.h:287
int sendNextChunk(const void *data, int chunkSize)
Send next chunk if not all data was sent with sendData.
Definition: HttpAsynchResp.h:312
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
Send data asynchronously to a client.
Definition: HttpAsynchResp.h:110
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:808
A mutual exclusion class.
Definition: ThreadLib.h:186