Commit e4d77c831146f5931c638727b1d9daf47ef28064
1 parent
2a988830
moved httpMessageQueue to a generalized Queue class as in fact it was nothing el…
…se except that it only stored HttpMessages.
Showing
15 changed files
with
66 additions
and
67 deletions
... | ... | @@ -26,7 +26,7 @@ |
26 | 26 | |
27 | 27 | #include "class.h" |
28 | 28 | #include "http/message.h" |
29 | -#include "http/message/queue.h" | |
29 | +#include "queue.h" | |
30 | 30 | #include "cbuf.h" |
31 | 31 | #include "stream.h" |
32 | 32 | |
... | ... | @@ -51,7 +51,7 @@ CLASS(HttpParser) { |
51 | 51 | char * incomplete; |
52 | 52 | size_t isize; |
53 | 53 | |
54 | - HttpMessageQueue queue; | |
54 | + Queue queue; | |
55 | 55 | HttpMessage current; |
56 | 56 | |
57 | 57 | HttpMessageState state; | ... | ... |
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | |
29 | 29 | #include "class.h" |
30 | 30 | #include "http/message.h" |
31 | -#include "http/message/queue.h" | |
31 | +#include "queue.h" | |
32 | 32 | #include "cbuf.h" |
33 | 33 | #include "stream.h" |
34 | 34 | |
... | ... | @@ -45,17 +45,17 @@ typedef enum e_HttpWriterState { |
45 | 45 | } HttpWriterState; |
46 | 46 | |
47 | 47 | CLASS(HttpWriter) { |
48 | - Cbuf buffer; | |
49 | - Bool ourLock; | |
48 | + Cbuf buffer; | |
49 | + Bool ourLock; | |
50 | 50 | |
51 | - HttpMessageQueue queue; | |
52 | - HttpMessage current; | |
51 | + Queue queue; | |
52 | + HttpMessage current; | |
53 | 53 | |
54 | - size_t nheader; | |
55 | - size_t nbody; | |
56 | - size_t written; | |
54 | + size_t nheader; | |
55 | + size_t nbody; | |
56 | + size_t written; | |
57 | 57 | |
58 | - HttpWriterState state; | |
58 | + HttpWriterState state; | |
59 | 59 | }; |
60 | 60 | |
61 | 61 | ssize_t httpWriterWrite(void *, Stream); | ... | ... |
... | ... | @@ -23,35 +23,34 @@ |
23 | 23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
24 | 24 | */ |
25 | 25 | |
26 | -#ifndef __HTTP_MESSAGE_QUEUE_H__ | |
27 | -#define __HTTP_MESSAGE_QUEUE_H__ | |
26 | +#ifndef __QUEUE_H__ | |
27 | +#define __QUEUE_H__ | |
28 | 28 | |
29 | 29 | #include <sys/types.h> |
30 | 30 | |
31 | 31 | #include "class.h" |
32 | -#include "http/message.h" | |
33 | 32 | #include "commons.h" |
34 | 33 | |
35 | 34 | |
36 | -CLASS(HttpMessageQueue) { | |
37 | - HttpMessage msg; | |
38 | - HttpMessageQueue next; | |
35 | +CLASS(Queue) { | |
36 | + void * msg; | |
37 | + Queue next; | |
39 | 38 | |
40 | 39 | /** |
41 | 40 | * first and last are only available in the initial queue |
42 | 41 | * element (the root). This elelment does not contain any message |
43 | 42 | * and exists only for organizational purpose. |
44 | 43 | */ |
45 | - HttpMessageQueue first; | |
46 | - HttpMessageQueue last; | |
47 | - size_t nmsg; | |
44 | + Queue first; | |
45 | + Queue last; | |
46 | + size_t nmsg; | |
48 | 47 | }; |
49 | 48 | |
50 | -void httpMessageQueuePut(HttpMessageQueue, HttpMessage); | |
51 | -HttpMessage httpMessageQueueGet(HttpMessageQueue); | |
49 | +void queuePut(Queue, void *); | |
50 | +void * queueGet(Queue); | |
52 | 51 | |
53 | -#define httpMessageQueueEmpty(this) (0 >= (this)->nmsg) | |
52 | +#define queueEmpty(this) (0 >= (this)->nmsg) | |
54 | 53 | |
55 | -#endif // __HTTP_MESSAGE_QUEUE_H__ | |
54 | +#endif // __QUEUE_H__ | |
56 | 55 | |
57 | 56 | // vim: set ts=4 sw=4: | ... | ... |
... | ... | @@ -13,6 +13,7 @@ LIBS = ./http/libhttp.a \ |
13 | 13 | ./cbuf/libcbuf.a \ |
14 | 14 | ./class/libclass.a \ |
15 | 15 | ./hash/libhash.a \ |
16 | + ./queue/libqueue.a \ | |
16 | 17 | ./logger/liblogger.a \ |
17 | 18 | ./server/libserver.a \ |
18 | 19 | ./session/libsession.a \ |
... | ... | @@ -28,4 +29,4 @@ webgameserver_CFLAGS = -Wall -I ../include/# $(COVERAGE_CFLAGS) |
28 | 29 | webgameserver_LDADD = $(LIBS) -lrt -lssl -lldap |
29 | 30 | #webgameserver_LDFLAGS = $(COVERAGE_LDFLAGS) |
30 | 31 | |
31 | -SUBDIRS = auth cbuf class hash http logger server session socket stream | |
32 | +SUBDIRS = auth cbuf class hash queue http logger server session socket stream | ... | ... |
... | ... | @@ -6,9 +6,6 @@ MSG = message.c \ |
6 | 6 | message/header_to_string.c \ |
7 | 7 | message/get_version.c \ |
8 | 8 | message/has_valid_version.c |
9 | -MSGQ = message/queue.c \ | |
10 | - message/queue/get.c \ | |
11 | - message/queue/put.c | |
12 | 9 | REQ = request.c \ |
13 | 10 | request/has_valid_method.c |
14 | 11 | RESP = response.c \ |
... | ... | @@ -38,6 +35,6 @@ HEADER = header.c \ |
38 | 35 | |
39 | 36 | noinst_LIBRARIES = libhttp.a |
40 | 37 | |
41 | -libhttp_a_SOURCES = $(MSG) $(MSGQ) $(REQ) $(RESP) $(PARSER) $(WRITER) \ | |
38 | +libhttp_a_SOURCES = $(MSG) $(REQ) $(RESP) $(PARSER) $(WRITER) \ | |
42 | 39 | $(WORKER) $(HEADER) interface/i_http_intro.c |
43 | 40 | libhttp_a_CFLAGS = -Wall -I ../../include/ | ... | ... |
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | #include "stream.h" |
29 | 29 | |
30 | 30 | #include "http/parser.h" |
31 | -#include "http/message/queue.h" | |
31 | +#include "queue.h" | |
32 | 32 | #include "http/request.h" |
33 | 33 | #include "http/response.h" |
34 | 34 | #include "cbuf.h" |
... | ... | @@ -48,7 +48,7 @@ httpParserCtor(void * _this, va_list * params) |
48 | 48 | return -1; |
49 | 49 | } |
50 | 50 | |
51 | - this->queue = new(HttpMessageQueue); | |
51 | + this->queue = new(Queue); | |
52 | 52 | |
53 | 53 | return 0; |
54 | 54 | } | ... | ... |
... | ... | @@ -25,6 +25,7 @@ |
25 | 25 | #include "class.h" |
26 | 26 | #include "cbuf.h" |
27 | 27 | #include "stream.h" |
28 | +#include "queue.h" | |
28 | 29 | |
29 | 30 | #include "http/parser.h" |
30 | 31 | #include "http/header.h" |
... | ... | @@ -170,7 +171,7 @@ httpParserParse(void * _this, Stream st) |
170 | 171 | /** |
171 | 172 | * enqueue current request |
172 | 173 | */ |
173 | - httpMessageQueuePut(this->queue, this->current); | |
174 | + queuePut(this->queue, this->current); | |
174 | 175 | this->current = NULL; |
175 | 176 | |
176 | 177 | /** | ... | ... |
... | ... | @@ -29,20 +29,19 @@ |
29 | 29 | |
30 | 30 | #include "class.h" |
31 | 31 | #include "auth.h" |
32 | +#include "queue.h" | |
33 | +#include "session.h" | |
34 | +#include "stream.h" | |
35 | +#include "hash.h" | |
32 | 36 | |
33 | 37 | #include "http/worker.h" |
34 | 38 | #include "http/header.h" |
35 | 39 | #include "http/message.h" |
36 | 40 | #include "http/request.h" |
37 | 41 | #include "http/response.h" |
38 | -#include "http/message/queue.h" | |
39 | 42 | #include "http/parser.h" |
40 | -#include "session.h" | |
41 | -#include "stream.h" | |
42 | -#include "hash.h" | |
43 | 43 | |
44 | 44 | #include "utils/memory.h" |
45 | -#include "hash.h" | |
46 | 45 | #include "commons.h" |
47 | 46 | |
48 | 47 | |
... | ... | @@ -60,8 +59,8 @@ httpWorkerProcess(HttpWorker this, Stream st) |
60 | 59 | |
61 | 60 | if (0 < (size = httpParserParse(this->parser, st))) { |
62 | 61 | |
63 | - while (! httpMessageQueueEmpty(this->parser->queue)) { | |
64 | - HttpRequest request = (HttpRequest)httpMessageQueueGet( | |
62 | + while (! queueEmpty(this->parser->queue)) { | |
63 | + HttpRequest request = queueGet( | |
65 | 64 | this->parser->queue); |
66 | 65 | HttpMessage response = NULL; |
67 | 66 | |
... | ... | @@ -237,7 +236,7 @@ httpWorkerProcess(HttpWorker this, Stream st) |
237 | 236 | |
238 | 237 | delete(request); |
239 | 238 | |
240 | - httpMessageQueuePut(this->writer->queue, response); | |
239 | + queuePut(this->writer->queue, response); | |
241 | 240 | response = NULL; |
242 | 241 | } |
243 | 242 | } | ... | ... |
... | ... | @@ -25,7 +25,7 @@ |
25 | 25 | #include "class.h" |
26 | 26 | #include "stream.h" |
27 | 27 | |
28 | -#include "http/message/queue.h" | |
28 | +#include "queue.h" | |
29 | 29 | #include "http/writer.h" |
30 | 30 | |
31 | 31 | static |
... | ... | @@ -35,7 +35,7 @@ httpWriterCtor(void * _this, va_list * params) |
35 | 35 | HttpWriter this = _this; |
36 | 36 | |
37 | 37 | this->buffer = va_arg(*params, Cbuf); |
38 | - this->queue = new(HttpMessageQueue); | |
38 | + this->queue = new(Queue); | |
39 | 39 | |
40 | 40 | return 0; |
41 | 41 | } | ... | ... |
... | ... | @@ -25,7 +25,7 @@ |
25 | 25 | |
26 | 26 | #include "class.h" |
27 | 27 | #include "http/message.h" |
28 | -#include "http/message/queue.h" | |
28 | +#include "queue.h" | |
29 | 29 | #include "http/writer.h" |
30 | 30 | #include "cbuf.h" |
31 | 31 | #include "stream.h" |
... | ... | @@ -51,9 +51,8 @@ httpWriterWrite(void * _this, Stream st) |
51 | 51 | while (cont) { |
52 | 52 | switch (this->state) { |
53 | 53 | case HTTP_WRITER_GET: |
54 | - if (NULL == this->current && | |
55 | - ! httpMessageQueueEmpty(this->queue)) { | |
56 | - this->current = httpMessageQueueGet(this->queue); | |
54 | + if (NULL == this->current && ! queueEmpty(this->queue)) { | |
55 | + this->current = queueGet(this->queue); | |
57 | 56 | |
58 | 57 | this->written = 0; |
59 | 58 | this->nbody = 0; | ... | ... |
src/queue/Makefile.am
0 → 100644
... | ... | @@ -21,14 +21,13 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | #include "class.h" |
24 | -#include "http/message.h" | |
25 | -#include "http/message/queue.h" | |
24 | +#include "queue.h" | |
26 | 25 | |
27 | -HttpMessage | |
28 | -httpMessageQueueGet(HttpMessageQueue this) | |
26 | +void * | |
27 | +queueGet(Queue this) | |
29 | 28 | { |
30 | - HttpMessageQueue first; | |
31 | - HttpMessage msg; | |
29 | + Queue first; | |
30 | + void * msg; | |
32 | 31 | |
33 | 32 | if (NULL == this->first) { |
34 | 33 | return NULL; | ... | ... |
... | ... | @@ -21,15 +21,14 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | #include "class.h" |
24 | -#include "http/message.h" | |
25 | -#include "http/message/queue.h" | |
24 | +#include "queue.h" | |
26 | 25 | |
27 | 26 | void |
28 | -httpMessageQueuePut(HttpMessageQueue this, HttpMessage msg) | |
27 | +queuePut(Queue this, void * msg) | |
29 | 28 | { |
30 | - HttpMessageQueue node = (this->last)? this->last : this; | |
29 | + Queue node = (this->last)? this->last : this; | |
31 | 30 | |
32 | - node->next = new(HttpMessageQueue); | |
31 | + node->next = new(Queue); | |
33 | 32 | this->last = node->next; |
34 | 33 | |
35 | 34 | if (node == this) { | ... | ... |
... | ... | @@ -23,33 +23,31 @@ |
23 | 23 | #include <stdarg.h> |
24 | 24 | |
25 | 25 | #include "class.h" |
26 | - | |
27 | -#include "http/message/queue.h" | |
26 | +#include "queue.h" | |
28 | 27 | |
29 | 28 | static |
30 | 29 | int |
31 | -messageQueueCtor(void * _this, va_list * params) | |
30 | +queueCtor(void * _this, va_list * params) | |
32 | 31 | { |
33 | 32 | return 0; |
34 | 33 | } |
35 | 34 | |
36 | 35 | static |
37 | 36 | void |
38 | -messageQueueDtor(void * _this) | |
37 | +queueDtor(void * _this) | |
39 | 38 | { |
40 | - HttpMessageQueue this = _this; | |
41 | - HttpMessageQueue node = this->first; | |
42 | - int i; | |
39 | + Queue this = _this; | |
40 | + Queue node = this->first; | |
43 | 41 | |
44 | 42 | while (NULL != node) { |
45 | - HttpMessageQueue next = node->next; | |
43 | + Queue next = node->next; | |
46 | 44 | delete(node->msg); |
47 | 45 | delete(node); |
48 | 46 | node = next; |
49 | 47 | } |
50 | 48 | } |
51 | 49 | |
52 | -INIT_IFACE(Class, messageQueueCtor, messageQueueDtor, NULL); | |
53 | -CREATE_CLASS(HttpMessageQueue, NULL, IFACE(Class)); | |
50 | +INIT_IFACE(Class, queueCtor, queueDtor, NULL); | |
51 | +CREATE_CLASS(Queue, NULL, IFACE(Class)); | |
54 | 52 | |
55 | 53 | // vim: set ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment