Commit 87b0d50d1d16cda2b63e420f5657826476673715

Authored by Georg Hopp
1 parent dfcbc494

structural changes for worker/process. @TODO actually i have no idea why this happens.

  1 +2012-02-22 12:19:40 +0100 Georg Hopp
  2 +
  3 + * fix memory problems occured with latest changes (HEAD, master)
  4 +
1 2012-02-22 09:03:40 +0100 Georg Hopp 5 2012-02-22 09:03:40 +0100 Georg Hopp
2 6
3 - * fixed bug in keep-alive check arised by implementation if #10 (HEAD, master) 7 + * fixed bug in keep-alive check arised by implementation if #10 (origin/master, origin/HEAD)
4 8
5 2012-02-22 08:51:05 +0100 Georg Hopp 9 2012-02-22 08:51:05 +0100 Georg Hopp
6 10
7 - * add forgotten jquery assets (origin/master, origin/HEAD) 11 + * add forgotten jquery assets
8 12
9 2012-02-22 08:48:43 +0100 Georg Hopp 13 2012-02-22 08:48:43 +0100 Georg Hopp
10 14
1 VERY BIG TODO: 1 VERY BIG TODO:
2 -- give a contructor a way to fail, so that no object will be created at all  
3 -  
4 - right now i will use long polling ajax calls when feedback from to the client 2 - right now i will use long polling ajax calls when feedback from to the client
5 is needed. In the long term this should be changed to websockets (ws). But 3 is needed. In the long term this should be changed to websockets (ws). But
6 right now ws specification is not final anyway. :) 4 right now ws specification is not final anyway. :)
  5 +
  6 +- handle errors after all system call...especially open, close, etc.
@@ -27,16 +27,18 @@ @@ -27,16 +27,18 @@
27 27
28 #include "class.h" 28 #include "class.h"
29 29
  30 +#define HTTP_HEADER_VALUE_CHUNK_SIZE 128
  31 +
30 CLASS(HttpHeader) { 32 CLASS(HttpHeader) {
31 unsigned long hash; 33 unsigned long hash;
32 char * name; 34 char * name;
33 - char ** value; 35 + char * value[HTTP_HEADER_VALUE_CHUNK_SIZE];
34 size_t nvalue; 36 size_t nvalue;
35 }; 37 };
36 38
37 HttpHeader httpHeaderParse(char * line); // @INFO: destructive 39 HttpHeader httpHeaderParse(char * line); // @INFO: destructive
38 40
39 -void httpHeaderAdd(const HttpHeader *, HttpHeader); 41 +HttpHeader httpHeaderAdd(const HttpHeader *, HttpHeader);
40 HttpHeader httpHeaderGet(const HttpHeader *, const char *); 42 HttpHeader httpHeaderGet(const HttpHeader *, const char *);
41 size_t httpHeaderSizeGet(HttpHeader); 43 size_t httpHeaderSizeGet(HttpHeader);
42 size_t httpHeaderToString(HttpHeader, char *); 44 size_t httpHeaderToString(HttpHeader, char *);
@@ -38,11 +38,10 @@ CLASS(HttpResponse) { @@ -38,11 +38,10 @@ CLASS(HttpResponse) {
38 char * reason; 38 char * reason;
39 }; 39 };
40 40
41 -HttpResponse httpResponse304(int, const char *); 41 +HttpResponse httpResponse304(const char *, const char *, const char *);
42 HttpResponse httpResponse404(); 42 HttpResponse httpResponse404();
43 HttpResponse httpResponseMe(int); 43 HttpResponse httpResponseMe(int);
44 -HttpResponse httpResponseImage(int);  
45 -HttpResponse httpResponseJquery(int); 44 +HttpResponse httpResponseAsset(const char *, const char *, const char *);
46 45
47 #endif // __HTTP_RESPONSE_H__ 46 #endif // __HTTP_RESPONSE_H__
48 47
@@ -49,7 +49,7 @@ extern void classDelete(void **); @@ -49,7 +49,7 @@ extern void classDelete(void **);
49 extern void * classClone(void *); 49 extern void * classClone(void *);
50 50
51 #define new(class,...) classNew(_##class, ##__VA_ARGS__) 51 #define new(class,...) classNew(_##class, ##__VA_ARGS__)
52 -#define delete(object) classDelete((void **)(object)) 52 +#define delete(object) classDelete((void **)&(object))
53 #define clone(object) classClone((void *)(object)) 53 #define clone(object) classClone((void *)(object))
54 54
55 #endif // __INTERFACE_CLASS_H__ 55 #endif // __INTERFACE_CLASS_H__
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 #ifndef __UTILS_MEMORY_H__ 23 #ifndef __UTILS_MEMORY_H__
24 #define __UTILS_MEMORY_H__ 24 #define __UTILS_MEMORY_H__
25 25
26 -#define FREE(val) (ffree((void**)(val))) 26 +#define FREE(val) (ffree((void**)&(val)))
27 27
28 void ffree(void **); 28 void ffree(void **);
29 29
@@ -23,10 +23,10 @@ REQ = http/request.c http/request/has_valid_method.c @@ -23,10 +23,10 @@ REQ = http/request.c http/request/has_valid_method.c
23 RESP = http/response.c \ 23 RESP = http/response.c \
24 http/response/304.c \ 24 http/response/304.c \
25 http/response/404.c \ 25 http/response/404.c \
26 - http/response/image.c \  
27 - http/response/jquery.c \ 26 + http/response/asset.c \
28 http/response/me.c 27 http/response/me.c
29 -WORKER = http/worker.c http/worker/process.c http/worker/write.c 28 +WORKER = http/worker.c http/worker/process.c http/worker/write.c \
  29 + http/worker/get_asset.c http/worker/add_common_header.c
30 WRITER = http/response/writer.c http/response/writer/write.c 30 WRITER = http/response/writer.c http/response/writer/write.c
31 HEADER = http/header.c http/header/get.c http/header/add.c \ 31 HEADER = http/header.c http/header/get.c http/header/add.c \
32 http/header/size_get.c http/header/to_string.c 32 http/header/size_get.c http/header/to_string.c
@@ -35,18 +35,19 @@ @@ -35,18 +35,19 @@
35 35
36 #include "class.h" 36 #include "class.h"
37 #include "interface/class.h" 37 #include "interface/class.h"
  38 +#include "utils/memory.h"
38 39
39 #include "cbuf.h" 40 #include "cbuf.h"
40 41
41 42
42 -static void dtor(void*); 43 +static void cbufDtor(void*);
43 44
44 static 45 static
45 int 46 int
46 -ctor(void * _this, va_list * params) 47 +cbufCtor(void * _this, va_list * params)
47 { 48 {
48 Cbuf this = _this; 49 Cbuf this = _this;
49 - char state = 0; 50 + char state = -1;
50 char * shm_name = va_arg(*params, char*); 51 char * shm_name = va_arg(*params, char*);
51 long psize = sysconf(_SC_PAGESIZE); 52 long psize = sysconf(_SC_PAGESIZE);
52 size_t size; 53 size_t size;
@@ -64,7 +65,7 @@ ctor(void * _this, va_list * params) @@ -64,7 +65,7 @@ ctor(void * _this, va_list * params)
64 size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize; 65 size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize;
65 this->bsize = psize * size; 66 this->bsize = psize * size;
66 67
67 - while (0 == state) { 68 + while (-1 == state) {
68 shm = shm_open(this->shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRWXU); 69 shm = shm_open(this->shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
69 if (-1 == shm) { 70 if (-1 == shm) {
70 break; 71 break;
@@ -93,7 +94,7 @@ ctor(void * _this, va_list * params) @@ -93,7 +94,7 @@ ctor(void * _this, va_list * params)
93 break; 94 break;
94 } 95 }
95 96
96 - state = 1; 97 + state = 0;
97 } 98 }
98 99
99 if (-1 != shm) { 100 if (-1 != shm) {
@@ -101,32 +102,25 @@ ctor(void * _this, va_list * params) @@ -101,32 +102,25 @@ ctor(void * _this, va_list * params)
101 close(shm); 102 close(shm);
102 } 103 }
103 104
104 - if (1 != state) {  
105 - dtor(this);  
106 - }  
107 -  
108 - return 0; 105 + return state;
109 } 106 }
110 107
111 static 108 static
112 void 109 void
113 -dtor(void * _this) 110 +cbufDtor(void * _this)
114 { 111 {
115 Cbuf this = _this; 112 Cbuf this = _this;
116 113
117 - if (NULL != this->shm_name) {  
118 - free(this->shm_name);  
119 - } 114 + FREE(this->shm_name);
120 115
121 if (NULL != this->data && MAP_FAILED != this->data) { 116 if (NULL != this->data && MAP_FAILED != this->data) {
122 munmap(this->data, this->bsize << 1); 117 munmap(this->data, this->bsize << 1);
123 } 118 }
124 119
125 - this->shm_name = NULL;  
126 - this->data = NULL; 120 + this->data = NULL;
127 } 121 }
128 122
129 -INIT_IFACE(Class, ctor, dtor, NULL); 123 +INIT_IFACE(Class, cbufCtor, cbufDtor, NULL);
130 CREATE_CLASS(Cbuf, NULL, IFACE(Class)); 124 CREATE_CLASS(Cbuf, NULL, IFACE(Class));
131 125
132 // vim: set ts=4 sw=4: 126 // vim: set ts=4 sw=4:
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 33
34 static 34 static
35 int 35 int
36 -ctor(void * _this, va_list * params) { 36 +httpHeaderCtor(void * _this, va_list * params) {
37 HttpHeader this = _this; 37 HttpHeader this = _this;
38 char * name; 38 char * name;
39 char * value; 39 char * value;
@@ -46,29 +46,27 @@ ctor(void * _this, va_list * params) { @@ -46,29 +46,27 @@ ctor(void * _this, va_list * params) {
46 46
47 this->hash = sdbm((unsigned char *)name); 47 this->hash = sdbm((unsigned char *)name);
48 48
49 - this->value = malloc(sizeof(char*) * (++(this->nvalue)));  
50 - (this->value)[this->nvalue - 1] = malloc(strlen(value) + 1);  
51 - strcpy((this->value)[this->nvalue - 1], value); 49 + (this->value)[this->nvalue] = malloc(strlen(value) + 1);
  50 + strcpy((this->value)[this->nvalue++], value);
52 51
53 return 0; 52 return 0;
54 } 53 }
55 54
56 static 55 static
57 void 56 void
58 -dtor(void * _this) 57 +httpHeaderDtor(void * _this)
59 { 58 {
60 HttpHeader this = _this; 59 HttpHeader this = _this;
61 size_t i; 60 size_t i;
62 61
63 - FREE(&(this->name)); 62 + FREE(this->name);
64 63
65 for (i=0; i<this->nvalue; i++) { 64 for (i=0; i<this->nvalue; i++) {
66 - FREE(&(this->value[i])); 65 + FREE(this->value[i]);
67 } 66 }
68 - FREE(&(this->value));  
69 } 67 }
70 68
71 -INIT_IFACE(Class, ctor, dtor, NULL); 69 +INIT_IFACE(Class, httpHeaderCtor, httpHeaderDtor, NULL);
72 CREATE_CLASS(HttpHeader, NULL, IFACE(Class)); 70 CREATE_CLASS(HttpHeader, NULL, IFACE(Class));
73 71
74 // vim: set ts=4 sw=4: 72 // vim: set ts=4 sw=4:
@@ -40,20 +40,21 @@ comp(const void * _a, const void * _b) @@ -40,20 +40,21 @@ comp(const void * _a, const void * _b)
40 return (a->hash < b->hash)? -1 : (a->hash > b->hash)? 1 : 0; 40 return (a->hash < b->hash)? -1 : (a->hash > b->hash)? 1 : 0;
41 } 41 }
42 42
43 -void 43 +HttpHeader
44 httpHeaderAdd(const HttpHeader * root, HttpHeader header) 44 httpHeaderAdd(const HttpHeader * root, HttpHeader header)
45 { 45 {
46 HttpHeader * found = tsearch(header, (void **)root, comp); 46 HttpHeader * found = tsearch(header, (void **)root, comp);
47 47
48 if (*found != header) { 48 if (*found != header) {
49 - (*found)->value = realloc(  
50 - (*found)->value,  
51 - sizeof(char*) * (++(*found)->nvalue));  
52 - (*found)->value[(*found)->nvalue - 1] = malloc(  
53 - strlen((header->value)[0]) + 1);  
54 - strcpy(((*found)->value)[(*found)->nvalue - 1], (header->value)[0]);  
55 - delete(&header); 49 + if ((*found)->nvalue >= HTTP_HEADER_VALUE_CHUNK_SIZE) {
  50 + return NULL;
  51 + }
  52 + (*found)->value[(*found)->nvalue++] = (header->value)[0];
  53 + (header->value)[0] = NULL;
  54 + delete(header);
56 } 55 }
  56 +
  57 + return *found;
57 } 58 }
58 59
59 // vim: set ts=4 sw=4: 60 // vim: set ts=4 sw=4:
@@ -28,11 +28,11 @@ @@ -28,11 +28,11 @@
28 size_t 28 size_t
29 httpHeaderSizeGet(HttpHeader header) 29 httpHeaderSizeGet(HttpHeader header)
30 { 30 {
31 - size_t size = 0; 31 + size_t nsize = strlen(header->name) + 2;
  32 + size_t size = header->nvalue * nsize;
32 int i; 33 int i;
33 34
34 for (i=0; i<header->nvalue; i++) { 35 for (i=0; i<header->nvalue; i++) {
35 - size += strlen(header->name) + 2;  
36 size += strlen(header->value[i]) + 2; 36 size += strlen(header->value[i]) + 2;
37 } 37 }
38 38
@@ -42,12 +42,12 @@ inline @@ -42,12 +42,12 @@ inline
42 void 42 void
43 tDelete(void * node) 43 tDelete(void * node)
44 { 44 {
45 - delete(&node); 45 + delete(node);
46 } 46 }
47 47
48 static 48 static
49 int 49 int
50 -ctor(void * _this, va_list * params) 50 +httpMessageCtor(void * _this, va_list * params)
51 { 51 {
52 HttpMessage this = _this; 52 HttpMessage this = _this;
53 char * version = va_arg(* params, char *); 53 char * version = va_arg(* params, char *);
@@ -60,11 +60,11 @@ ctor(void * _this, va_list * params) @@ -60,11 +60,11 @@ ctor(void * _this, va_list * params)
60 60
61 static 61 static
62 void 62 void
63 -dtor(void * _this) 63 +httpMessageDtor(void * _this)
64 { 64 {
65 HttpMessage this = _this; 65 HttpMessage this = _this;
66 66
67 - ffree((void **)&(this->version)); 67 + FREE(this->version);
68 68
69 /** 69 /**
70 * this is a GNU extension...anyway on most non 70 * this is a GNU extension...anyway on most non
@@ -75,7 +75,7 @@ dtor(void * _this) @@ -75,7 +75,7 @@ dtor(void * _this)
75 75
76 switch (this->type) { 76 switch (this->type) {
77 case HTTP_MESSAGE_BUFFERED: 77 case HTTP_MESSAGE_BUFFERED:
78 - ffree((void **)&(this->body)); 78 + FREE(this->body);
79 break; 79 break;
80 80
81 case HTTP_MESSAGE_PIPED: 81 case HTTP_MESSAGE_PIPED:
@@ -87,7 +87,7 @@ dtor(void * _this) @@ -87,7 +87,7 @@ dtor(void * _this)
87 } 87 }
88 } 88 }
89 89
90 -INIT_IFACE(Class, ctor, dtor, NULL); 90 +INIT_IFACE(Class, httpMessageCtor, httpMessageDtor, NULL);
91 CREATE_CLASS(HttpMessage, NULL, IFACE(Class)); 91 CREATE_CLASS(HttpMessage, NULL, IFACE(Class));
92 92
93 // vim: set ts=4 sw=4: 93 // vim: set ts=4 sw=4:
@@ -29,24 +29,24 @@ @@ -29,24 +29,24 @@
29 29
30 static 30 static
31 int 31 int
32 -ctor(void * _this, va_list * params) 32 +messageQueueCtor(void * _this, va_list * params)
33 { 33 {
34 return 0; 34 return 0;
35 } 35 }
36 36
37 static 37 static
38 void 38 void
39 -dtor(void * _this) 39 +messageQueueDtor(void * _this)
40 { 40 {
41 HttpMessageQueue this = _this; 41 HttpMessageQueue this = _this;
42 int i; 42 int i;
43 43
44 for (i=0; i<this->nmsgs; i++) { 44 for (i=0; i<this->nmsgs; i++) {
45 - delete(&(this->msgs)[i]); 45 + delete((this->msgs)[i]);
46 } 46 }
47 } 47 }
48 48
49 -INIT_IFACE(Class, ctor, dtor, NULL); 49 +INIT_IFACE(Class, messageQueueCtor, messageQueueDtor, NULL);
50 CREATE_CLASS(HttpMessageQueue, NULL, IFACE(Class)); 50 CREATE_CLASS(HttpMessageQueue, NULL, IFACE(Class));
51 51
52 // vim: set ts=4 sw=4: 52 // vim: set ts=4 sw=4:
@@ -35,19 +35,23 @@ @@ -35,19 +35,23 @@
35 35
36 static 36 static
37 int 37 int
38 -ctor(void * _this, va_list * params) 38 +httpRequestCtor(void * _this, va_list * params)
39 { 39 {
  40 + /**
  41 + * the parent is not called by intention. All infomations
  42 + * are read from the request stream.
  43 + */
40 return 0; 44 return 0;
41 } 45 }
42 46
43 static 47 static
44 void 48 void
45 -dtor(void * _this) 49 +httpRequestDtor(void * _this)
46 { 50 {
47 HttpRequest this = _this; 51 HttpRequest this = _this;
48 52
49 - ffree((void **)&(this->uri));  
50 - ffree((void **)&(this->method)); 53 + FREE(this->uri);
  54 + FREE(this->method);
51 55
52 PARENTCALL(_this, Class, dtor); 56 PARENTCALL(_this, Class, dtor);
53 } 57 }
@@ -88,7 +92,7 @@ toString(void * _this, char * string) @@ -88,7 +92,7 @@ toString(void * _this, char * string)
88 return string; 92 return string;
89 } 93 }
90 94
91 -INIT_IFACE(Class, ctor, dtor, NULL); 95 +INIT_IFACE(Class, httpRequestCtor, httpRequestDtor, NULL);
92 INIT_IFACE(HttpIntro, sizeGet, toString); 96 INIT_IFACE(HttpIntro, sizeGet, toString);
93 CREATE_CLASS(HttpRequest, 97 CREATE_CLASS(HttpRequest,
94 HttpMessage, 98 HttpMessage,
@@ -33,10 +33,12 @@ @@ -33,10 +33,12 @@
33 #include "http/request.h" 33 #include "http/request.h"
34 #include "cbuf.h" 34 #include "cbuf.h"
35 35
  36 +#include "utils/memory.h"
  37 +
36 38
37 static 39 static
38 int 40 int
39 -ctor(void * _this, va_list * params) 41 +requestParserCtor(void * _this, va_list * params)
40 { 42 {
41 HttpRequestParser this = _this; 43 HttpRequestParser this = _this;
42 44
@@ -48,23 +50,20 @@ ctor(void * _this, va_list * params) @@ -48,23 +50,20 @@ ctor(void * _this, va_list * params)
48 50
49 static 51 static
50 void 52 void
51 -dtor(void * _this) 53 +requestParserDtor(void * _this)
52 { 54 {
53 HttpRequestParser this = _this; 55 HttpRequestParser this = _this;
54 56
55 - delete(&(this->request_queue)); 57 + delete(this->request_queue);
56 58
57 if (TRUE == this->ourLock) 59 if (TRUE == this->ourLock)
58 cbufRelease(this->buffer); 60 cbufRelease(this->buffer);
59 61
60 - if (NULL != this->incomplete)  
61 - free(this->incomplete);  
62 -  
63 - if (NULL != this->cur_request)  
64 - delete(&(this->cur_request)); 62 + FREE(this->incomplete);
  63 + delete(this->cur_request);
65 } 64 }
66 65
67 -INIT_IFACE(Class, ctor, dtor, NULL); 66 +INIT_IFACE(Class, requestParserCtor, requestParserDtor, NULL);
68 INIT_IFACE(StreamReader, (fptr_streamReaderRead)httpRequestParserParse); 67 INIT_IFACE(StreamReader, (fptr_streamReaderRead)httpRequestParserParse);
69 CREATE_CLASS(HttpRequestParser, NULL, IFACE(Class), IFACE(StreamReader)); 68 CREATE_CLASS(HttpRequestParser, NULL, IFACE(Class), IFACE(StreamReader));
70 69
@@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
36 36
37 static 37 static
38 int 38 int
39 -ctor(void * _this, va_list * params) 39 +httpResponseCtor(void * _this, va_list * params)
40 { 40 {
41 HttpResponse this = _this; 41 HttpResponse this = _this;
42 char * reason; 42 char * reason;
@@ -54,11 +54,11 @@ ctor(void * _this, va_list * params) @@ -54,11 +54,11 @@ ctor(void * _this, va_list * params)
54 54
55 static 55 static
56 void 56 void
57 -dtor(void * _this) 57 +httpResponseDtor(void * _this)
58 { 58 {
59 HttpResponse this = _this; 59 HttpResponse this = _this;
60 60
61 - ffree((void **)&(this->reason)); 61 + FREE(this->reason);
62 62
63 PARENTCALL(_this, Class, dtor); 63 PARENTCALL(_this, Class, dtor);
64 } 64 }
@@ -99,7 +99,7 @@ toString(void * _this, char * string) @@ -99,7 +99,7 @@ toString(void * _this, char * string)
99 return string; 99 return string;
100 } 100 }
101 101
102 -INIT_IFACE(Class, ctor, dtor, NULL); 102 +INIT_IFACE(Class, httpResponseCtor, httpResponseDtor, NULL);
103 INIT_IFACE(HttpIntro, sizeGet, toString); 103 INIT_IFACE(HttpIntro, sizeGet, toString);
104 CREATE_CLASS( 104 CREATE_CLASS(
105 HttpResponse, 105 HttpResponse,
@@ -20,11 +20,6 @@ @@ -20,11 +20,6 @@
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */ 21 */
22 22
23 -#include <stdio.h>  
24 -#include <time.h>  
25 -#include <sys/stat.h>  
26 -#include <fcntl.h>  
27 -  
28 #include "class.h" 23 #include "class.h"
29 #include "interface/class.h" 24 #include "interface/class.h"
30 25
@@ -34,44 +29,24 @@ @@ -34,44 +29,24 @@
34 29
35 30
36 HttpResponse 31 HttpResponse
37 -httpResponse304(int handle, const char * content_type) 32 +httpResponse304(const char * mime, const char * etag, const char * mtime)
38 { 33 {
39 - time_t t;  
40 - struct tm * tmp;  
41 - char buffer[200];  
42 - struct stat st;  
43 HttpResponse response; 34 HttpResponse response;
44 HttpMessage message; 35 HttpMessage message;
45 36
46 - fstat(handle, &st);  
47 -  
48 response = new(HttpResponse, "HTTP/1.1", 304, "Not Modified"); 37 response = new(HttpResponse, "HTTP/1.1", 304, "Not Modified");
49 message = (HttpMessage)response; 38 message = (HttpMessage)response;
50 39
51 - httpHeaderAdd(&(message->header),  
52 - new(HttpHeader, "Content-Type", content_type));  
53 - httpHeaderAdd(&(message->header),  
54 - new(HttpHeader, "Server", "testserver"));  
55 -  
56 message->type = HTTP_MESSAGE_BUFFERED; 40 message->type = HTTP_MESSAGE_BUFFERED;
57 message->nbody = 0; 41 message->nbody = 0;
58 message->body = NULL; 42 message->body = NULL;
59 43
60 - tmp = localtime(&(st.st_mtime));  
61 - strftime(buffer, sizeof(buffer), "%s", tmp);  
62 httpHeaderAdd(&(message->header), 44 httpHeaderAdd(&(message->header),
63 - new(HttpHeader, "ETag", buffer));  
64 -  
65 - tmp = localtime(&(st.st_mtime));  
66 - strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); 45 + new(HttpHeader, "Content-Type", mime));
67 httpHeaderAdd(&(message->header), 46 httpHeaderAdd(&(message->header),
68 - new(HttpHeader, "Last-Modified", buffer));  
69 -  
70 - t = time(NULL);  
71 - tmp = localtime(&t);  
72 - strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); 47 + new(HttpHeader, "ETag", etag));
73 httpHeaderAdd(&(message->header), 48 httpHeaderAdd(&(message->header),
74 - new(HttpHeader, "Date", buffer)); 49 + new(HttpHeader, "Last-Modified", mtime));
75 50
76 return response; 51 return response;
77 } 52 }
@@ -53,8 +53,6 @@ httpResponse404() @@ -53,8 +53,6 @@ httpResponse404()
53 53
54 httpHeaderAdd(&(message->header), 54 httpHeaderAdd(&(message->header),
55 new(HttpHeader, "Content-Type", "text/html")); 55 new(HttpHeader, "Content-Type", "text/html"));
56 - httpHeaderAdd(&(message->header),  
57 - new(HttpHeader, "Server", "testserver"));  
58 56
59 message->type = HTTP_MESSAGE_BUFFERED; 57 message->type = HTTP_MESSAGE_BUFFERED;
60 message->nbody = sizeof(RESP_DATA) - 1; 58 message->nbody = sizeof(RESP_DATA) - 1;
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 #include <stdio.h> 23 #include <stdio.h>
24 #include <sys/stat.h> 24 #include <sys/stat.h>
25 #include <fcntl.h> 25 #include <fcntl.h>
  26 +#include <string.h>
26 27
27 #include "class.h" 28 #include "class.h"
28 #include "interface/class.h" 29 #include "interface/class.h"
@@ -33,41 +34,45 @@ @@ -33,41 +34,45 @@
33 34
34 35
35 HttpResponse 36 HttpResponse
36 -httpResponseImage(int handle) 37 +httpResponseAsset(const char * fname, const char * mime, const char * match)
37 { 38 {
38 - char buffer[200]; 39 + struct tm * tmp;
  40 + char etag[200];
  41 + char mtime[200];
  42 + char clen[200];
39 struct stat st; 43 struct stat st;
40 HttpResponse response; 44 HttpResponse response;
41 HttpMessage message; 45 HttpMessage message;
  46 + int handle;
42 47
  48 + handle = open(fname, O_RDONLY);
43 fstat(handle, &st); 49 fstat(handle, &st);
44 50
  51 + tmp = localtime(&(st.st_mtime));
  52 + strftime(etag, sizeof(etag), "%s", tmp);
  53 + strftime(mtime, sizeof(mtime), "%a, %d %b %Y %T %Z", tmp);
  54 +
  55 + if (0 == strcmp(etag, match)) {
  56 + return httpResponse304(mime, etag, mtime);
  57 + }
  58 +
45 response = new(HttpResponse, "HTTP/1.1", 200, "OK"); 59 response = new(HttpResponse, "HTTP/1.1", 200, "OK");
46 message = (HttpMessage)response; 60 message = (HttpMessage)response;
47 61
48 - httpHeaderAdd(&(message->header),  
49 - new(HttpHeader, "Content-Type", "image/jpeg"));  
50 - httpHeaderAdd(&(message->header),  
51 - new(HttpHeader, "Server", "testserver"));  
52 -  
53 message->type = HTTP_MESSAGE_PIPED; 62 message->type = HTTP_MESSAGE_PIPED;
54 message->handle = handle; 63 message->handle = handle;
55 message->nbody = st.st_size; 64 message->nbody = st.st_size;
56 65
57 - sprintf(buffer, "%d", message->nbody);  
58 - httpHeaderAdd(&(message->header),  
59 - new(HttpHeader, "Content-Length", buffer)); 66 + sprintf(clen, "%d", message->nbody);
60 67
61 - tmp = localtime(&(st.st_mtime));  
62 - strftime(buffer, sizeof(buffer), "%s", tmp);  
63 httpHeaderAdd(&(message->header), 68 httpHeaderAdd(&(message->header),
64 - new(HttpHeader, "ETag", buffer));  
65 -  
66 - t = time(NULL);  
67 - tmp = localtime(&t);  
68 - strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); 69 + new(HttpHeader, "Content-Type", mime));
  70 + httpHeaderAdd(&(message->header),
  71 + new(HttpHeader, "Content-Length", clen));
  72 + httpHeaderAdd(&(message->header),
  73 + new(HttpHeader, "ETag", etag));
69 httpHeaderAdd(&(message->header), 74 httpHeaderAdd(&(message->header),
70 - new(HttpHeader, "Date", buffer)); 75 + new(HttpHeader, "Last-Modified", mtime));
71 76
72 return response; 77 return response;
73 } 78 }
1 -/**  
2 - * \file  
3 - *  
4 - * \author Georg Hopp  
5 - *  
6 - * \copyright  
7 - * Copyright (C) 2012 Georg Hopp  
8 - *  
9 - * This program is free software: you can redistribute it and/or modify  
10 - * it under the terms of the GNU General Public License as published by  
11 - * the Free Software Foundation, either version 3 of the License, or  
12 - * (at your option) any later version.  
13 - *  
14 - * This program is distributed in the hope that it will be useful,  
15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
17 - * GNU General Public License for more details.  
18 - *  
19 - * You should have received a copy of the GNU General Public License  
20 - * along with this program. If not, see <http://www.gnu.org/licenses/>.  
21 - */  
22 -  
23 -#include <stdio.h>  
24 -#include <time.h>  
25 -#include <sys/stat.h>  
26 -#include <fcntl.h>  
27 -  
28 -#include "class.h"  
29 -#include "interface/class.h"  
30 -  
31 -#include "http/response.h"  
32 -#include "http/message.h"  
33 -#include "http/header.h"  
34 -  
35 -  
36 -HttpResponse  
37 -httpResponseJquery(int handle)  
38 -{  
39 - time_t t;  
40 - struct tm * tmp;  
41 - char buffer[200];  
42 - struct stat st;  
43 - HttpResponse response;  
44 - HttpMessage message;  
45 -  
46 - fstat(handle, &st);  
47 -  
48 - response = new(HttpResponse, "HTTP/1.1", 200, "OK");  
49 - message = (HttpMessage)response;  
50 -  
51 - httpHeaderAdd(&(message->header),  
52 - new(HttpHeader, "Content-Type", "text/javascript"));  
53 - httpHeaderAdd(&(message->header),  
54 - new(HttpHeader, "Server", "testserver"));  
55 -  
56 - message->type = HTTP_MESSAGE_PIPED;  
57 - message->handle = handle;  
58 - message->nbody = st.st_size;  
59 -  
60 - sprintf(buffer, "%d", message->nbody);  
61 - httpHeaderAdd(&(message->header),  
62 - new(HttpHeader, "Content-Length", buffer));  
63 -  
64 - tmp = localtime(&(st.st_mtime));  
65 - strftime(buffer, sizeof(buffer), "%s", tmp);  
66 - httpHeaderAdd(&(message->header),  
67 - new(HttpHeader, "ETag", buffer));  
68 -  
69 - t = time(NULL);  
70 - tmp = localtime(&t);  
71 - strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp);  
72 - httpHeaderAdd(&(message->header),  
73 - new(HttpHeader, "Date", buffer));  
74 -  
75 - return response;  
76 -}  
77 -  
78 -// vim: set ts=4 sw=4:  
@@ -69,8 +69,6 @@ httpResponseMe(int value) @@ -69,8 +69,6 @@ httpResponseMe(int value)
69 httpHeaderAdd(&(message->header), 69 httpHeaderAdd(&(message->header),
70 new(HttpHeader, "Content-Type", "text/html")); 70 new(HttpHeader, "Content-Type", "text/html"));
71 httpHeaderAdd(&(message->header), 71 httpHeaderAdd(&(message->header),
72 - new(HttpHeader, "Server", "testserver"));  
73 - httpHeaderAdd(&(message->header),  
74 new(HttpHeader, "Set-Cookie", "name=\"Georg Hopp\"")); 72 new(HttpHeader, "Set-Cookie", "name=\"Georg Hopp\""));
75 httpHeaderAdd(&(message->header), 73 httpHeaderAdd(&(message->header),
76 new(HttpHeader, "Set-Cookie", "profession=\"coder\"")); 74 new(HttpHeader, "Set-Cookie", "profession=\"coder\""));
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 31
32 static 32 static
33 int 33 int
34 -ctor(void * _this, va_list * params) 34 +responseWriterCtor(void * _this, va_list * params)
35 { 35 {
36 HttpResponseWriter this = _this; 36 HttpResponseWriter this = _this;
37 37
@@ -43,20 +43,20 @@ ctor(void * _this, va_list * params) @@ -43,20 +43,20 @@ ctor(void * _this, va_list * params)
43 43
44 static 44 static
45 void 45 void
46 -dtor(void * _this) 46 +responseWriterDtor(void * _this)
47 { 47 {
48 HttpResponseWriter this = _this; 48 HttpResponseWriter this = _this;
49 49
50 - delete(&(this->response_queue)); 50 + delete(this->response_queue);
51 51
52 if (TRUE == this->ourLock) 52 if (TRUE == this->ourLock)
53 cbufRelease(this->buffer); 53 cbufRelease(this->buffer);
54 54
55 if (NULL != this->cur_response) 55 if (NULL != this->cur_response)
56 - delete(&(this->cur_response)); 56 + delete(this->cur_response);
57 } 57 }
58 58
59 -INIT_IFACE(Class, ctor, dtor, NULL); 59 +INIT_IFACE(Class, responseWriterCtor, responseWriterDtor, NULL);
60 INIT_IFACE(StreamWriter, (fptr_streamWriterWrite)httpResponseWriterWrite); 60 INIT_IFACE(StreamWriter, (fptr_streamWriterWrite)httpResponseWriterWrite);
61 CREATE_CLASS(HttpResponseWriter, NULL, IFACE(Class), IFACE(StreamWriter)); 61 CREATE_CLASS(HttpResponseWriter, NULL, IFACE(Class), IFACE(StreamWriter));
62 62
@@ -143,13 +143,13 @@ httpResponseWriterWrite(HttpResponseWriter this, int fd) @@ -143,13 +143,13 @@ httpResponseWriterWrite(HttpResponseWriter this, int fd)
143 */ 143 */
144 cbufRelease(this->buffer); 144 cbufRelease(this->buffer);
145 this->ourLock = FALSE; 145 this->ourLock = FALSE;
146 - delete(&this->cur_response); 146 + delete(this->cur_response);
147 return -1; 147 return -1;
148 } 148 }
149 149
150 cbufRelease(this->buffer); 150 cbufRelease(this->buffer);
151 this->ourLock = FALSE; 151 this->ourLock = FALSE;
152 - delete(&this->cur_response); 152 + delete(this->cur_response);
153 153
154 break; 154 break;
155 } 155 }
@@ -13,10 +13,11 @@ @@ -13,10 +13,11 @@
13 #include "interface/stream_reader.h" 13 #include "interface/stream_reader.h"
14 #include "interface/stream_writer.h" 14 #include "interface/stream_writer.h"
15 15
16 -#define SHMN "/worker_" 16 +#include "utils/memory.h"
  17 +
17 static 18 static
18 int 19 int
19 -ctor(void * _this, va_list * params) 20 +httpWorkerCtor(void * _this, va_list * params)
20 { 21 {
21 HttpWorker this = _this; 22 HttpWorker this = _this;
22 char * id = va_arg(*params, char *); 23 char * id = va_arg(*params, char *);
@@ -41,17 +42,17 @@ ctor(void * _this, va_list * params) @@ -41,17 +42,17 @@ ctor(void * _this, va_list * params)
41 42
42 static 43 static
43 void 44 void
44 -dtor(void * _this) 45 +httpWorkerDtor(void * _this)
45 { 46 {
46 HttpWorker this = _this; 47 HttpWorker this = _this;
47 48
48 - if (NULL != this->id) free(this->id); 49 + FREE(this->id);
49 50
50 - delete(&(this->parser));  
51 - delete(&(this->writer)); 51 + delete(this->parser);
  52 + delete(this->writer);
52 53
53 - if (NULL != this->pbuf) delete(&(this->pbuf));  
54 - if (NULL != this->wbuf) delete(&(this->wbuf)); 54 + if (NULL != this->pbuf) delete(this->pbuf);
  55 + if (NULL != this->wbuf) delete(this->wbuf);
55 } 56 }
56 57
57 static 58 static
@@ -70,7 +71,7 @@ _clone(void * _this, void * _base) @@ -70,7 +71,7 @@ _clone(void * _this, void * _base)
70 this->writer = new(HttpResponseWriter, base->wbuf); 71 this->writer = new(HttpResponseWriter, base->wbuf);
71 } 72 }
72 73
73 -INIT_IFACE(Class, ctor, dtor, _clone); 74 +INIT_IFACE(Class, httpWorkerCtor, httpWorkerDtor, _clone);
74 INIT_IFACE(StreamReader, (fptr_streamReaderRead)httpWorkerProcess); 75 INIT_IFACE(StreamReader, (fptr_streamReaderRead)httpWorkerProcess);
75 INIT_IFACE(StreamWriter, (fptr_streamWriterWrite)httpWorkerWrite); 76 INIT_IFACE(StreamWriter, (fptr_streamWriterWrite)httpWorkerWrite);
76 CREATE_CLASS( 77 CREATE_CLASS(
  1 +#include <time.h>
  2 +
  3 +#include "class.h"
  4 +#include "interface/class.h"
  5 +
  6 +#include "http/message.h"
  7 +#include "http/response.h"
  8 +
  9 +void
  10 +httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
  11 +{
  12 + time_t t;
  13 + struct tm * tmp;
  14 + char buffer[200];
  15 +
  16 + if (httpMessageHasKeepAlive(request)) {
  17 + httpHeaderAdd(
  18 + &(response->header),
  19 + new(HttpHeader, "Connection", "Keep-Alive"));
  20 + }
  21 + else {
  22 + httpHeaderAdd(
  23 + &(response->header),
  24 + new(HttpHeader, "Connection", "Close"));
  25 + }
  26 +
  27 + httpHeaderAdd(&(response->header),
  28 + new(HttpHeader, "Server", "testserver"));
  29 +
  30 + t = time(NULL);
  31 + tmp = localtime(&t);
  32 + strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp);
  33 + httpHeaderAdd(&(response->header),
  34 + new(HttpHeader, "Date", buffer));
  35 +}
  36 +
  37 +// vim: set ts=4 sw=4:
  1 +#include "http/header.h"
  2 +#include "http/message.h"
  3 +#include "http/request.h"
  4 +#include "http/response.h"
  5 +
  6 +HttpMessage
  7 +httpWorkerGetAsset(
  8 + HttpRequest request,
  9 + const char * fname,
  10 + const char * mime)
  11 +{
  12 + char * match;
  13 + HttpHeader header;
  14 +
  15 + header = httpHeaderGet(
  16 + &(((HttpMessage)request)->header),
  17 + "If-None-Match");
  18 +
  19 + if (NULL == header) {
  20 + match = "";
  21 + }
  22 + else {
  23 + match = (header->value)[0];
  24 + }
  25 +
  26 + return (HttpMessage)httpResponseAsset(fname, mime, match);
  27 +}
  28 +
  29 +// vim: set ts=4 sw=4:
@@ -21,18 +21,22 @@ @@ -21,18 +21,22 @@
21 */ 21 */
22 22
23 #include <sys/types.h> 23 #include <sys/types.h>
24 -#include <sys/stat.h>  
25 -#include <fcntl.h>  
26 24
27 #include "class.h" 25 #include "class.h"
28 #include "interface/class.h" 26 #include "interface/class.h"
29 27
30 #include "http/worker.h" 28 #include "http/worker.h"
  29 +#include "http/message.h"
  30 +#include "http/request.h"
  31 +#include "http/message/queue.h"
31 #include "http/request/parser.h" 32 #include "http/request/parser.h"
32 #include "http/header.h" 33 #include "http/header.h"
33 #include "http/request.h" 34 #include "http/request.h"
34 #include "http/message.h" 35 #include "http/message.h"
35 36
  37 +HttpMessage httpWorkerGetAsset(HttpRequest, const char *, const char *);
  38 +void httpWorkerAddCommonHeader(HttpMessage, HttpMessage);
  39 +
36 ssize_t 40 ssize_t
37 httpWorkerProcess(HttpWorker this, int fd) 41 httpWorkerProcess(HttpWorker this, int fd)
38 { 42 {
@@ -47,57 +51,35 @@ httpWorkerProcess(HttpWorker this, int fd) @@ -47,57 +51,35 @@ httpWorkerProcess(HttpWorker this, int fd)
47 HttpMessageQueue respq = this->writer->response_queue; 51 HttpMessageQueue respq = this->writer->response_queue;
48 52
49 for (i=0; i<reqq->nmsgs; i++) { 53 for (i=0; i<reqq->nmsgs; i++) {
50 - /**  
51 - * \todo for now simply remove request and send not found.  
52 - * Make this sane.  
53 - */  
54 - HttpRequest request = (HttpRequest)(reqq->msgs[i]);  
55 - HttpMessage response = NULL;  
56 -  
57 - if (0 == strcmp("GET", request->method) &&  
58 - 0 == strcmp("/me/", request->uri)) {  
59 - response = (HttpMessage)httpResponseMe(*(this->val));  
60 - }  
61 - else if (0 == strcmp("GET", request->method) &&  
62 - 0 == strcmp("/image/", request->uri)) {  
63 - int handle = open("./assets/waldschrat.jpg", O_RDONLY);  
64 -  
65 - if (NULL != httpHeaderGet(  
66 - &(((HttpMessage)request)->header),  
67 - "If-None-Match")) {  
68 - response = (HttpMessage)httpResponse304(handle, "image/jpeg");  
69 - }  
70 - else {  
71 - response = (HttpMessage)httpResponseImage(handle); 54 + HttpRequest request = (HttpRequest)(reqq->msgs[i]);
  55 + HttpMessage response = NULL;
  56 +
  57 + if (0 == strcmp("GET", request->method)) {
  58 +
  59 + if (0 == strcmp("/me/", request->uri)) {
  60 + response = (HttpMessage)httpResponseMe(*(this->val));
72 } 61 }
73 - }  
74 - else if (0 == strcmp("GET", request->method) &&  
75 - 0 == strcmp("/jquery/", request->uri)) {  
76 - int handle = open("./assets/jquery-1.7.1.min.js", O_RDONLY);  
77 -  
78 - if (NULL != httpHeaderGet(  
79 - &(((HttpMessage)request)->header),  
80 - "If-None-Match")) {  
81 - response = (HttpMessage)httpResponse304(handle, "text/javascript"); 62 +
  63 + if (0 == strcmp("/image/", request->uri)) {
  64 + response = httpWorkerGetAsset(
  65 + request,
  66 + "./assets/waldschrat.jpg",
  67 + "image/jpeg");
82 } 68 }
83 - else {  
84 - response = (HttpMessage)httpResponseJquery(handle); 69 +
  70 + if (0 == strcmp("/jquery/", request->uri)) {
  71 + response = httpWorkerGetAsset(
  72 + request,
  73 + "./assets/jquery-1.7.1.min.js",
  74 + "text/javascript");
85 } 75 }
86 } 76 }
87 - else { 77 +
  78 + if (NULL == response) {
88 response = (HttpMessage)httpResponse404(); 79 response = (HttpMessage)httpResponse404();
89 } 80 }
90 81
91 - if (httpMessageHasKeepAlive(reqq->msgs[i])) {  
92 - httpHeaderAdd(  
93 - &(response->header),  
94 - new(HttpHeader, "Connection", "Keep-Alive"));  
95 - }  
96 - else {  
97 - httpHeaderAdd(  
98 - &(response->header),  
99 - new(HttpHeader, "Connection", "Close"));  
100 - } 82 + httpWorkerAddCommonHeader((HttpMessage)request, response);
101 83
102 t = time(NULL); 84 t = time(NULL);
103 tmp = localtime(&t); 85 tmp = localtime(&t);
@@ -107,7 +89,7 @@ httpWorkerProcess(HttpWorker this, int fd) @@ -107,7 +89,7 @@ httpWorkerProcess(HttpWorker this, int fd)
107 89
108 respq->msgs[(respq->nmsgs)++] = response; 90 respq->msgs[(respq->nmsgs)++] = response;
109 response = NULL; 91 response = NULL;
110 - delete(&(reqq->msgs[i])); 92 + delete((reqq->msgs)[i]);
111 } 93 }
112 94
113 reqq->nmsgs = 0; 95 reqq->nmsgs = 0;
@@ -41,7 +41,7 @@ logger_level_str[] = { @@ -41,7 +41,7 @@ logger_level_str[] = {
41 41
42 static 42 static
43 int 43 int
44 -ctor(void * _this, va_list * params) 44 +loggerCtor(void * _this, va_list * params)
45 { 45 {
46 Logger this = _this; 46 Logger this = _this;
47 this->min_level = va_arg(*params, int); 47 this->min_level = va_arg(*params, int);
@@ -49,9 +49,9 @@ ctor(void * _this, va_list * params) @@ -49,9 +49,9 @@ ctor(void * _this, va_list * params)
49 return 0; 49 return 0;
50 } 50 }
51 51
52 -static void dtor(void * _this) {} 52 +static void loggerDtor(void * _this) {}
53 53
54 -INIT_IFACE(Class, ctor, dtor, NULL); 54 +INIT_IFACE(Class, loggerCtor, loggerDtor, NULL);
55 CREATE_CLASS(Logger, NULL, IFACE(Class)); 55 CREATE_CLASS(Logger, NULL, IFACE(Class));
56 56
57 // vim: set ts=4 sw=4: 57 // vim: set ts=4 sw=4:
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 34
35 static 35 static
36 int 36 int
37 -ctor(void * _this, va_list * params) 37 +serverCtor(void * _this, va_list * params)
38 { 38 {
39 Server this = _this; 39 Server this = _this;
40 in_port_t port; 40 in_port_t port;
@@ -73,25 +73,25 @@ ctor(void * _this, va_list * params) @@ -73,25 +73,25 @@ ctor(void * _this, va_list * params)
73 73
74 static 74 static
75 void 75 void
76 -dtor(void * _this) 76 +serverDtor(void * _this)
77 { 77 {
78 Server this = _this; 78 Server this = _this;
79 int i; 79 int i;
80 80
81 for (i=0; i<this->nfds; i++) { 81 for (i=0; i<this->nfds; i++) {
82 if (this->sock->handle != (this->fds)[i].fd) { 82 if (this->sock->handle != (this->fds)[i].fd) {
83 - delete(&(this->conns[(this->fds)[i].fd]).sock);  
84 - delete(&(this->conns[(this->fds)[i].fd]).worker); 83 + delete((this->conns[(this->fds)[i].fd]).sock);
  84 + delete((this->conns[(this->fds)[i].fd]).worker);
85 } 85 }
86 } 86 }
87 87
88 - FREE(&(this->fds));  
89 - FREE(&(this->conns)); 88 + FREE(this->fds);
  89 + FREE(this->conns);
90 90
91 - delete(&this->sock); 91 + delete(this->sock);
92 } 92 }
93 93
94 -INIT_IFACE(Class, ctor, dtor, NULL); 94 +INIT_IFACE(Class, serverCtor, serverDtor, NULL);
95 CREATE_CLASS(Server, NULL, IFACE(Class)); 95 CREATE_CLASS(Server, NULL, IFACE(Class));
96 96
97 // vim: set ts=4 sw=4: 97 // vim: set ts=4 sw=4:
@@ -31,8 +31,8 @@ serverCloseConn(Server this, unsigned int i) @@ -31,8 +31,8 @@ serverCloseConn(Server this, unsigned int i)
31 { 31 {
32 int fd = (this->fds)[i].fd; 32 int fd = (this->fds)[i].fd;
33 33
34 - delete(&((this->conns)[fd].sock));  
35 - delete(&((this->conns)[fd].worker)); 34 + delete((this->conns)[fd].sock);
  35 + delete((this->conns)[fd].worker);
36 36
37 memset(&(this->fds[i]), 0, sizeof(struct pollfd)); 37 memset(&(this->fds[i]), 0, sizeof(struct pollfd));
38 } 38 }
@@ -52,7 +52,7 @@ serverHandleAccept(Server this) @@ -52,7 +52,7 @@ serverHandleAccept(Server this)
52 (this->fds)[this->nfds].events = POLLIN; 52 (this->fds)[this->nfds].events = POLLIN;
53 this->nfds++; 53 this->nfds++;
54 } else { 54 } else {
55 - delete(&acc); 55 + delete(acc);
56 56
57 switch(errno) { 57 switch(errno) {
58 case EAGAIN: 58 case EAGAIN:
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 31
32 static 32 static
33 int 33 int
34 -ctor(void * _this, va_list * params) 34 +socketCtor(void * _this, va_list * params)
35 { 35 {
36 Sock this = _this; 36 Sock this = _this;
37 int reUse = 1; //! \todo make this configurable 37 int reUse = 1; //! \todo make this configurable
@@ -44,7 +44,7 @@ ctor(void * _this, va_list * params) @@ -44,7 +44,7 @@ ctor(void * _this, va_list * params)
44 loggerLog(this->log, LOGGER_CRIT, 44 loggerLog(this->log, LOGGER_CRIT,
45 "error opening socket: %s - service terminated", 45 "error opening socket: %s - service terminated",
46 strerror(errno)); 46 strerror(errno));
47 - return; 47 + return -1;
48 } 48 }
49 49
50 //! Make the socket REUSE a TIME_WAIT socket 50 //! Make the socket REUSE a TIME_WAIT socket
@@ -55,7 +55,7 @@ ctor(void * _this, va_list * params) @@ -55,7 +55,7 @@ ctor(void * _this, va_list * params)
55 55
56 static 56 static
57 void 57 void
58 -dtor(void * _this) 58 +socketDtor(void * _this)
59 { 59 {
60 Sock this = _this; 60 Sock this = _this;
61 61
@@ -65,7 +65,7 @@ dtor(void * _this) @@ -65,7 +65,7 @@ dtor(void * _this)
65 } 65 }
66 } 66 }
67 67
68 -INIT_IFACE(Class, ctor, dtor, NULL); 68 +INIT_IFACE(Class, socketCtor, socketDtor, NULL);
69 CREATE_CLASS(Sock, NULL, IFACE(Class)); 69 CREATE_CLASS(Sock, NULL, IFACE(Class));
70 70
71 // vim: set ts=4 sw=4: 71 // vim: set ts=4 sw=4:
@@ -165,9 +165,9 @@ main() @@ -165,9 +165,9 @@ main()
165 } 165 }
166 } while (!WIFEXITED(status) && !WIFSIGNALED(status)); 166 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
167 167
168 - if (NULL != server) delete(&server);  
169 - if (NULL != worker) delete(&worker);  
170 - if (NULL != logger) delete(&logger); 168 + if (NULL != server) delete(server);
  169 + if (NULL != worker) delete(worker);
  170 + if (NULL != logger) delete(logger);
171 } 171 }
172 172
173 break; 173 break;
Please register or login to post a comment