-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccepter.h
54 lines (41 loc) · 998 Bytes
/
Accepter.h
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
#ifndef ACCEPTER_H
#define ACCEPTER_H
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <iostream>
#include "ThreadManager.h"
#include "Stack.h"
using namespace std;
class Nimble;
class Accepter : public Runnable {
public:
Accepter(Nimble& nimble, int port);
virtual ~Accepter();
void run(void);
void handleFdBuffer(void);
private:
ThreadStack<int> _fdBuffer;
int _port;
int _listenFd;
Nimble& _nimble;
void setup();
};
// Command pattern: (Design pattern or just a hack in this case?)
class HandleBufferCommand : public Runnable {
public:
HandleBufferCommand(Accepter* accepter) {
_accepter = accepter;
}
virtual void run(void) {
_accepter->handleFdBuffer();
// Kind of tricky ehh?
delete this;
}
private:
Accepter* _accepter;
};
#endif /* ACCEPTER_H */