mock_worker.c
1.03 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "class.h"
#include "stream.h"
#include "mock_worker.h"
static
int
mockWorkerCtor(void * _this, va_list * params)
{
MockWorker this = _this;
this->rbuf = &(this->_rbuf[0]);
this->wbuf = &(this->_wbuf[0]);
return 0;
}
static
void
mockWorkerDtor(void * _this)
{
}
static
void
mockWorkerClone(void * _this, void * _base)
{
MockWorker this = _this;
MockWorker base = _base;
this->rbuf = &(base->_rbuf[0]);
this->wbuf = &(base->_wbuf[0]);
}
static
ssize_t
mockWorkerRead(void * _this, Stream st)
{
MockWorker this = _this;
size_t size;
size = read((st->handle).fd, this->rbuf, 1024);
return size;
}
static
ssize_t
mockWorkerWrite(void * _this, Stream st)
{
return 0;
}
INIT_IFACE(Class, mockWorkerCtor, mockWorkerDtor, mockWorkerClone);
INIT_IFACE(StreamReader, mockWorkerRead);
INIT_IFACE(StreamWriter, mockWorkerWrite);
CREATE_CLASS(
MockWorker,
NULL,
IFACE(Class),
IFACE(StreamReader),
IFACE(StreamWriter));
// vim: set ts=4 sw=4: