-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSocketState.h
72 lines (50 loc) · 974 Bytes
/
SocketState.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include "Common.h"
EASY_NS_BEGIN
class Socket;
enum StateType {
sDisconnected,
sConnecting,
sConnected,
sListening,
sConnection,
sData,
sError,
sClose,
sMessage,
// io timeout
sTimeout,
};
// base state
class SocketState {
public:
SocketState(Socket *s, void *p);
virtual ~SocketState();
virtual void update() {}
StateType getType() { return type; }
static SocketState* create(Socket *s, StateType t, void *p = 0);
protected:
Socket *socket;
void *param;
StateType type;
};
class SocketStateConnecting : public SocketState {
public:
SocketStateConnecting(Socket *s, void *p);
virtual void update();
private:
time_t start;
};
class SocketStateConnected : public SocketState {
public:
SocketStateConnected(Socket *s, void *p);
virtual void update();
private:
time_t last;
};
class SocketStateListening : public SocketState {
public:
SocketStateListening(Socket *s, void *p);
virtual void update();
};
EASY_NS_END