taskrambler  v0.1.8
Web server and task management solution.
http/writer.h
Go to the documentation of this file.
1 /**
2  * \file
3  * Write ready responses to an output stream.
4  *
5  * \author Georg Hopp
6  *
7  * \copyright
8  * Copyright © 2012 Georg Hopp
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef __HTTP_WRITER_H__
25 #define __HTTP_WRITER_H__
26 
27 #include <sys/types.h>
28 
29 #include "class.h"
30 #include "http/message.h"
31 #include "queue.h"
32 #include "stream.h"
33 
34 #include "commons.h"
35 
36 
37 /*
38  * the buffer that will be written back to an http client.
39  * If we have open 1024 paralell connection this will result
40  * in a memory usage of 128MB. Right now, we don't allow more
41  * than this amount of paralell connections.
42  *
43  * This one and the parser buffer are the hugest memory pools
44  * we need. The parser buffer is of the same size.
45  *
46  * Right now only the ringbuffer is reused for each connection
47  * resulting in some memory movement between some temporary
48  * space and the circular buffer.
49  *
50  * This behavioru should be kept in place for low memory machines
51  * running this code.
52  *
53  * Anyway, I will build a version which uses two ringbuffers for
54  * each connection, Resulting in a 256KB memory used for each
55  * connection. Which in turn means 256MB for 1024 paralell connections.
56  *
57  * And as I will also implement a cbuf pool, this memory will not be
58  * freed before application end.
59  */
60 
61 /*
62  * This is the multiplier for the size of the initial write buffer.
63  * It is used to store the
64  * string representation of the message, as well as the first part of
65  * the body if the headers exceed the size a multiple of this will
66  * be reserved...very unlikely, but not impossible.
67  * If no the whole body fits within this buffer only part of it will
68  * be copied in there. The rest will be send in following send calls.
69  */
70 #define WRITER_BUF_CHUNK 1024 * 10 // our default buffer chunk for
71  // headers is 10k. This will result
72  // in at least 20m for 2000 concurrent
73  // connections.
74 
75 typedef enum e_HttpWriterState {
80 
81 CLASS(HttpWriter) {
82  char * buffer;
83 
84  Queue queue;
85  HttpMessage current;
86 
87  size_t nbuffer; // size of buffer
88  size_t nheader; // size headers in buf
89  size_t nbody; // sizeof body in buffer
90  size_t written; // already written bytes
91 
92  HttpWriterState state;
93 };
94 
95 ssize_t httpWriterWrite(void *, Stream);
96 
97 #endif // __HTTP_WRITER_H__
98 
99 // vim: set ts=4 sw=4:
CLASS(HttpWriter)
Definition: http/writer.h:81
ssize_t httpWriterWrite(void *, Stream)
HttpWriterState
Definition: http/writer.h:75