Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
HttpAsynchResp.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 ****************************************************************************
11 * HEADER
12 *
13 * $Id: HttpAsynchResp.h 5978 2026-09-11 16:13:48Z 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
39#ifndef __HttpAsynchResp_h
40#define __HttpAsynchResp_h
41
42#include <HttpServer.h>
43
44
45#define RESPONSESTATE_IDLE 0
46#define RESPONSESTATE_WRITEMODE 1
47#define RESPONSESTATE_WRITEMODE_CHUNK 2
48#define RESPONSESTATE_BODYSENT 3
49#define RESPONSESTATE_CLOSED 4
50
51
52
111typedef struct HttpAsynchResp
112#ifdef __cplusplus
113: public HttpConnection
114{
115 void *operator new(size_t s) { return ::baMalloc(s); }
116 void operator delete(void* d) { if(d) ::baFree(d); }
117 void *operator new(size_t, void *place) { return place; }
118 void operator delete(void*, void *) { }
119
122
133 HttpAsynchResp(char* buf, int size, HttpRequest* req);
134
145 HttpAsynchResp(char* buf,int size,HttpConnection* con);
146
151 bool isValid();
152
160 void asynchThreadMode();
161
165
175 void close();
176
183
192 int setConClose();
193
201 int setLingeringClose();
202
203
213 int setStatus(int statusCode, const char* protocol=0);
214
224 int setHeader(const char *name, const char *value);
225
238 int sendData(const void* data, int pktSize, int chunkSize);
239
247 int sendNextChunk(const void* data,int chunkSize);
248
263#else
264{
265 HttpConnection super;
266#endif
267 BufPrint bufPrint;
268 HttpConnection* con; /* pointer to 'super' or to a HttpAsyncReqResp */
269 ThreadMutex* mutex; /* Can be set so code automatically locks mutex */
270 BaBool statusSent;
271 BaBool headerSent;
272 U8 responseState;
273 U8 doLingeringClose;
275
276
277#ifdef __cplusplus
278extern "C" {
279#endif
288 HttpAsynchResp* o, char* buf, int size, HttpRequest* req);
297 HttpAsynchResp* o, char* buf, int size, HttpConnection* con);
307 HttpAsynchResp* o, char* buf, int size, HttpConnection* con);
313#define HttpAsynchResp_asynchThreadMode(o) \
314 ((o)->mutex=HttpAsynchResp_getMutex(o))
321#define HttpAsynchResp_destructor(o) HttpAsynchResp_close(o)
324#define HttpAsynchResp_getMutex(o) \
325 SoDisp_getMutex(HttpConnection_getDispatcher((HttpConnection*)(o)))
329#define HttpAsynchResp_setConClose(o)\
330 HttpConnection_clearKeepAlive((HttpConnection*)(o))
336#define HttpAsynchResp_setLingeringClose(o) (o)->doLingeringClose=TRUE
340 HttpAsynchResp* o, int statusCode, const char* protocol);
344 HttpAsynchResp* o,const char *name,const char *value);
348 HttpAsynchResp* o, const void* data, int pktSize, int chunkSize);
352 HttpAsynchResp* o,const void* data,int chunkSize);
359#define HttpAsynchResp_isAsynchThreadMode(o) ((o)->mutex ? TRUE : FALSE)
360#ifdef __cplusplus
361}
362inline HttpAsynchResp::HttpAsynchResp(char* buf, int size, HttpRequest* req) {
363 HttpAsynchResp_constructor(this, buf, size, req);
364}
365inline HttpAsynchResp::HttpAsynchResp(char* buf,int size,HttpConnection* con) {
366 HttpAsynchResp_constructor2(this, buf, size, con);
367}
369 return HttpAsynchResp_isValid(this) ? TRUE : FALSE;
370}
373}
376}
379}
381 return HttpAsynchResp_getMutex(this);
382}
384 return HttpAsynchResp_setConClose(this);
385}
387 return HttpAsynchResp_setConClose(this);
388}
389inline int HttpAsynchResp::setStatus(int statusCode, const char* protocol) {
390 return HttpAsynchResp_setStatus(this, statusCode, protocol);
391}
392inline int HttpAsynchResp::setHeader(const char *name,const char *value) {
393 return HttpAsynchResp_setHeader(this, name, value);
394}
396 const void* data, int pktSize, int chunkSize) {
397 return HttpAsynchResp_sendData(this, data, pktSize, chunkSize);
398}
399inline int HttpAsynchResp::sendNextChunk(const void* data,int chunkSize) {
400 return HttpAsynchResp_sendNextChunk(this,data,chunkSize); }
402 return HttpAsynchResp_getWriter(this);
403}
404#endif
405 /* end of HttpStack */
407
408
409#endif
void * baMalloc(size_t size)
Allocate uninitialized storage using the target's configured allocator.
void baFree(void *p)
Release storage using the target's configured allocator.
BA_API void HttpAsynchResp_ReqRespInit(HttpAsynchResp *o, char *buf, int size, HttpConnection *con)
Initialize the response half of a combined request/response object.
BufPrint * getWriter()
BufPrint is used when sending data of unknown length.
Definition: HttpAsynchResp.h:401
int setHeader(const char *name, const char *value)
Append a response header before starting the body.
Definition: HttpAsynchResp.h:392
ThreadMutex * getMutex()
Get the dispatcher lock.
Definition: HttpAsynchResp.h:380
BA_API void HttpAsynchResp_constructor(HttpAsynchResp *o, char *buf, int size, HttpRequest *req)
Initialize from a request and take over its connection.
BA_API int HttpAsynchResp_sendNextChunk(HttpAsynchResp *o, const void *data, int chunkSize)
Continue the fixed-length body begun with sendData.
#define HttpAsynchResp_asynchThreadMode(o)
Select worker-thread send behavior; see HttpAsynchResp::asynchThreadMode.
Definition: HttpAsynchResp.h:313
BA_API BufPrint * HttpAsynchResp_getWriter(HttpAsynchResp *o)
BufPrint is used when sending data of unknown length.
#define HttpAsynchResp_getMutex(o)
Definition: HttpAsynchResp.h:324
BA_API void HttpAsynchResp_constructor2(HttpAsynchResp *o, char *buf, int size, HttpConnection *con)
Initialize from a connection and take over its socket.
#define HttpAsynchResp_setConClose(o)
Disable persistent connection reuse before sending headers.
Definition: HttpAsynchResp.h:329
void asynchThreadMode()
Set in asynchronous thread mode so you can call the methods in this class using its worker-thread sen...
Definition: HttpAsynchResp.h:377
int sendData(const void *data, int pktSize, int chunkSize)
Begin a fixed-length response body.
Definition: HttpAsynchResp.h:395
#define HttpAsynchResp_destructor(o)
Close the response; no status is returned.
Definition: HttpAsynchResp.h:321
~HttpAsynchResp()
Calls method close.
Definition: HttpAsynchResp.h:371
bool isValid()
Check the installed buffer and connection.
Definition: HttpAsynchResp.h:368
int setConClose()
Close connection when the HttpAsynchResp object is done.
Definition: HttpAsynchResp.h:383
int setLingeringClose()
Request connection closure.
Definition: HttpAsynchResp.h:386
int setStatus(int statusCode, const char *protocol=0)
Append the HTTP status line and standard Date/Server headers.
Definition: HttpAsynchResp.h:389
BA_API int HttpAsynchResp_setStatus(HttpAsynchResp *o, int statusCode, const char *protocol)
Append the HTTP status line and standard Date/Server headers.
BA_API BaBool HttpAsynchResp_isValid(HttpAsynchResp *o)
Check the installed buffer and connection.
void close()
Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1....
Definition: HttpAsynchResp.h:374
BA_API int HttpAsynchResp_sendData(HttpAsynchResp *o, const void *data, int pktSize, int chunkSize)
Begin a fixed-length response body.
int sendNextChunk(const void *data, int chunkSize)
Continue the fixed-length body begun with sendData.
Definition: HttpAsynchResp.h:399
BA_API int HttpAsynchResp_setHeader(HttpAsynchResp *o, const char *name, const char *value)
Append a response header before starting the body.
BA_API void HttpAsynchResp_close(HttpAsynchResp *o)
Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1....
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
The BufPrint class, which implements a compact printf-style formatter, is a base class used by severa...
Definition: BufPrint.h:132
Send data asynchronously to a client.
Definition: HttpAsynchResp.h:114
HttpAsynchResp()
Uninitialized storage; initialize before use or destruction.
Definition: HttpAsynchResp.h:121
Contains information about the physical socket connection.
Definition: HttpConnection.h:80
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:950
A mutual exclusion class.
Definition: ThreadLib.h:196