-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSocket.h
More file actions
96 lines (81 loc) · 2.78 KB
/
WebSocket.h
File metadata and controls
96 lines (81 loc) · 2.78 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <unordered_map>
#include <map>
#include <mutex>
#include "SocketLib/SocketLib.h"
using namespace std;
class WebSocket
{
typedef struct
{
string strBuffer;
vector<pair<string, string>> HeaderList;
bool bNew;
} CONNECTIONDETAILS;
typedef unordered_map<TcpSocket*, CONNECTIONDETAILS> CONNECTIONLIST;
typedef struct
{
uint8_t OpCode : 4;
uint8_t RSV3 : 1;
uint8_t RSV2 : 1;
uint8_t RSV1 : 1;
uint8_t FIN : 1;
uint8_t PLoad : 7;
uint8_t Mask : 1;
}HEADER;
typedef struct
{
HEADER stHeader;
uint64_t nLen;
uint32_t uiMask;
//shared_ptr<TempFile> pTmpFile;
uint64_t nReceived;
wstring strPath;
}SOCKETPARAM;
public:
typedef struct
{
bool m_bSSL;
string m_strCAcertificate;
string m_strHostCertificate;
string m_strHostKey;
string m_strDhParam;
string m_strSslCipher;
} HOSTPARAM;
public:
WebSocket(const string& strBindIp = string("127.0.0.1"), short sPort = 9090);
WebSocket(const WebSocket&) = delete;
WebSocket(WebSocket&& other) noexcept;
WebSocket& operator=(const WebSocket&) = delete;
WebSocket& operator=(WebSocket&& other) noexcept;
virtual ~WebSocket();
virtual bool Start();
virtual bool Stop();
virtual bool IsStopped() noexcept;
const string& GetBindAdresse() const noexcept;
short GetPort() const noexcept;
HOSTPARAM& GetParameterBlockRef(const string& szHostName);
virtual void Connected(const void* pId) { ; }
virtual void Closeing(const void* pId) { ; }
virtual void TextDataRecieved(const void* pId, const wstring strPath, uint8_t* szData, uint32_t nDataLen) { ; }
virtual void BinaryDataRecieved(const void* pId, const wstring strPath, uint8_t* szData, uint32_t nDataLen, bool bIsLast) { ; }
virtual void PongRecieved(const void* pId) { ; }
size_t WriteData(const void* pId, const uint8_t* szData, const uint32_t nDataLen);
size_t SendPing(const void* pId);
private:
void OnNewConnection(const vector<TcpSocket*>& vNewConnections);
void OnDataRecieved(TcpSocket* const pTcpSocket);
void OnSocketError(BaseSocket* const pBaseSocket);
void OnSocketCloseing(BaseSocket* const pBaseSocket);
void OnDataRecievedWebSocket(TcpSocket* pTcpSocket);
void OnSocketErrorWebSocket(BaseSocket* pBaseSocket);
void OnSocketCloseingWebSocket(BaseSocket* pBaseSocket);
private:
TcpServer* m_pSocket;
CONNECTIONLIST m_vConnections;
mutex m_mtxConnections;
map<BaseSocket*, SOCKETPARAM> SocketList;
mutex mxList;
string m_strBindIp;
short m_sPort;
map<string, HOSTPARAM> m_vHostParam;
};