Barracuda Application Server C/C++ Reference
NO
HttpAsynchResp.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 ****************************************************************************
11 * HEADER
12 *
13 * $Id: HttpAsynchResp.h 5355 2022-11-16 10:33:45Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2004-2022
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 ****************************************************************************
34 *
35 */
36
37#ifndef __HttpAsynchResp_h
38#define __HttpAsynchResp_h
39
40#include <HttpServer.h>
41
42
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
48
49
50
107typedef struct HttpAsynchResp
108#ifdef __cplusplus
109: public HttpConnection
110{
111 void *operator new(size_t s) { return ::baMalloc(s); }
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 *) { }
115
116 HttpAsynchResp() {}
117
124 HttpAsynchResp(char* buf, int size, HttpRequest* req);
125
132 HttpAsynchResp(char* buf,int size,HttpConnection* con);
133
137 bool isValid();
138
145 void asynchThreadMode();
146
150
157 void close();
158
163
171 int setConClose();
172
185 int setLingeringClose();
186
187
195 int setStatus(int statusCode, const char* protocol=0);
196
203 int setHeader(const char *name, const char *value);
204
213 int sendData(const void* data, int pktSize, int chunkSize);
214
219 int sendNextChunk(const void* data,int chunkSize);
220
230#else
231{
232 HttpConnection super;
233#endif
234 BufPrint bufPrint;
235 HttpConnection* con; /* pointer to 'super' or to a HttpAsyncReqResp */
236 ThreadMutex* mutex; /* Can be set so code automatically locks mutex */
237 BaBool statusSent;
238 BaBool headerSent;
239 U8 responseState;
240 U8 doLingeringClose;
242
243
244#ifdef __cplusplus
245extern "C" {
246#endif
247BA_API void HttpAsynchResp_constructor(
248 HttpAsynchResp* o, char* buf, int size, HttpRequest* req);
249BA_API void HttpAsynchResp_constructor2(
250 HttpAsynchResp* o, char* buf, int size, HttpConnection* con);
251BA_API void HttpAsynchResp_ReqRespInit(
252 HttpAsynchResp* o, char* buf, int size, HttpConnection* con);
253BA_API BaBool HttpAsynchResp_isValid(HttpAsynchResp* o);
254#define HttpAsynchResp_asynchThreadMode(o) \
255 ((o)->mutex=HttpAsynchResp_getMutex(o))
256BA_API void HttpAsynchResp_close(HttpAsynchResp* 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(
264 HttpAsynchResp* o, int statusCode, const char* protocol);
265BA_API int HttpAsynchResp_setHeader(
266 HttpAsynchResp* o,const char *name,const char *value);
267BA_API int HttpAsynchResp_sendData(
268 HttpAsynchResp* o, const void* data, int pktSize, int chunkSize);
269BA_API int HttpAsynchResp_sendNextChunk(
270 HttpAsynchResp* o,const void* data,int chunkSize);
271BA_API BufPrint* HttpAsynchResp_getWriter(HttpAsynchResp* o);
272#define HttpAsynchResp_isAsynchThreadMode(o) ((o)->mutex ? TRUE : FALSE)
273#ifdef __cplusplus
274}
275inline HttpAsynchResp::HttpAsynchResp(char* buf, int size, HttpRequest* req) {
276 HttpAsynchResp_constructor(this, buf, size, req);
277}
278inline HttpAsynchResp::HttpAsynchResp(char* buf,int size,HttpConnection* con) {
279 HttpAsynchResp_constructor2(this, buf, size, con);
280}
282 return HttpAsynchResp_isValid(this) ? TRUE : FALSE;
283}
285 HttpAsynchResp_destructor(this);
286}
288 HttpAsynchResp_close(this);
289}
291 HttpAsynchResp_asynchThreadMode(this);
292}
294 return HttpAsynchResp_getMutex(this);
295}
297 return HttpAsynchResp_setConClose(this);
298}
300 return HttpAsynchResp_setConClose(this);
301}
302inline int HttpAsynchResp::setStatus(int statusCode, const char* protocol) {
303 return HttpAsynchResp_setStatus(this, statusCode, protocol);
304}
305inline int HttpAsynchResp::setHeader(const char *name,const char *value) {
306 return HttpAsynchResp_setHeader(this, name, value);
307}
309 const void* data, int pktSize, int chunkSize) {
310 return HttpAsynchResp_sendData(this, data, pktSize, chunkSize);
311}
312inline int HttpAsynchResp::sendNextChunk(const void* data,int chunkSize) {
313 return HttpAsynchResp_sendNextChunk(this,data,chunkSize); }
315 return HttpAsynchResp_getWriter(this);
316}
317#endif
318 /* end of HttpStack */
320
321
322#endif
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