-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsuite.cpp
67 lines (57 loc) · 1.1 KB
/
testsuite.cpp
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
/*
**
** g++ -Wall -o testsuite testsuite.cpp -I../include -L../lib -lConnetUtils
**
*/
#include <iostream>
#include <unistd.h>
#include "Server.h"
#include "Thread.h"
using namespace std;
//using namespace ConnetUtils;
class ThreadedObject : public Thread
{
public:
ThreadedObject() {}
void run()
{
for(int x = 0; x < 10; ++x)
{
cout << x << "/10: hello from the thread" << endl;
if(waitForKillEvent(1000)) {
break;
}
}
}
};
bool read_client(int fd, void *data = 0)
{
data = 0;
const int buf_size = 8192; // 8k
char buf[buf_size + 1];
memset(buf, 0, buf_size);
int bytes = read(fd, (char *)buf, buf_size);
if(bytes <= 0) {
return false;
}
// write this to a file
cout << buf << endl;
return true;
}
int main()
{
ThreadedObject thread;
thread.start();
Server server;
try
{
server.listen(32000, read_client);
server.select();
}
catch(const Exception &ex)
{
cout << ex << endl;
}
thread.stop();
return 0;
}