worker.c
1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "class.h"
#include "http/worker.h"
#include "http/request/parser.h"
#include "http/response/writer.h"
#include "interface/class.h"
#include "interface/stream_reader.h"
#include "interface/stream_writer.h"
#define SHMN "/worker_"
static
void
ctor(void * _this, va_list * params)
{
HttpWorker this = _this;
char * id = va_arg(*params, char *);
this->id = malloc(strlen(id) + 1);
strcpy(this->id, id);
this->parser = new(HttpRequestParser, this->id);
this->writer = new(HttpResponseWriter, this->id);
}
static
void
dtor(void * _this)
{
HttpWorker this = _this;
free(this->id);
delete(&this->parser);
delete(&this->writer);
}
INIT_IFACE(Class, ctor, dtor, NULL);
INIT_IFACE(StreamReader, (fptr_streamReaderRead)httpWorkerProcess);
INIT_IFACE(StreamWriter, (fptr_streamWriterWrite)httpWorkerWrite);
CREATE_CLASS(
HttpWorker,
NULL,
IFACE(Class),
IFACE(StreamReader),
IFACE(StreamWriter));
// vim: set ts=4 sw=4: