You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.7 KiB
81 lines
1.7 KiB
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.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 *);
|
|
int * val = va_arg(*params, int *);
|
|
char cbuf_id[100];
|
|
|
|
this->id = malloc(strlen(id) + 1);
|
|
strcpy(this->id, id);
|
|
this->val = val;
|
|
|
|
sprintf(cbuf_id, "%s_%s", "parser", id);
|
|
this->pbuf = new(Cbuf, cbuf_id, REQUEST_PARSER_BUFFER_MAX);
|
|
|
|
sprintf(cbuf_id, "%s_%s", "writer", id);
|
|
this->wbuf = new(Cbuf, cbuf_id, RESPONSE_WRITER_MAX_BUF);
|
|
|
|
this->parser = new(HttpRequestParser, this->pbuf);
|
|
this->writer = new(HttpResponseWriter, this->wbuf);
|
|
}
|
|
|
|
static
|
|
void
|
|
dtor(void * _this)
|
|
{
|
|
HttpWorker this = _this;
|
|
|
|
if (NULL != this->id) free(this->id);
|
|
|
|
delete(&(this->parser));
|
|
delete(&(this->writer));
|
|
|
|
if (NULL != this->pbuf) delete(&(this->pbuf));
|
|
if (NULL != this->wbuf) delete(&(this->wbuf));
|
|
}
|
|
|
|
static
|
|
void
|
|
_clone(void * _this, void * _base)
|
|
{
|
|
HttpWorker this = _this;
|
|
HttpWorker base = _base;
|
|
|
|
this->id = NULL;
|
|
this->val = base->val;
|
|
this->pbuf = NULL;
|
|
this->wbuf = NULL;
|
|
|
|
this->parser = new(HttpRequestParser, base->pbuf);
|
|
this->writer = new(HttpResponseWriter, base->wbuf);
|
|
}
|
|
|
|
INIT_IFACE(Class, ctor, dtor, _clone);
|
|
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:
|