-
Notifications
You must be signed in to change notification settings - Fork 14
/
PackageIOCPClient.h
70 lines (56 loc) · 1.39 KB
/
PackageIOCPClient.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
#ifndef _IOCPCLIENT_H_
#define _IOCPCLIENT_H_
/*
A Simple IOCP Class
Author:201724
Email:[email protected]
*/
typedef enum IOCPClient_ConnectionType
{
IOCPClient_ConnectionType_ConnectFailed,
IOCPClient_ConnectionType_Connected,
IOCPClient_ConnectionType_Disconnected
}IOCPClient_ConnectionType;
class IOCPClientContext:public IOCPMutex
{
public:
SOCKET sdSocketCopy;
CIOCPBufferWriter m_ReceivedBytes;
IOCPQueue<CIOCPBuffer*> m_SendBufferList;
CIOCPBufferReader* m_SendingBytes;
IOCPClientContext(){
sdSocketCopy = INVALID_SOCKET;
m_SendingBytes = NULL;
}
};
class PackageIOCPClient
{
public:
WSADATA m_stWSAData;
IOCPMutex m_Mutex;
IOCPClientContext m_ClientContext;
sockaddr_in m_stRemoteAddress;
BOOL m_bIsConnected;
bool m_bShutdown;
private:
HANDLE m_hThread;
VOID CloseConnect();
SOCKET GetSockets();
VOID AsyncConnect(u_long adr,u_short port);
VOID AsyncProcessReceive();
VOID AsyncProcessSending();
VOID AsyncProcessConnected();
VOID AsyncProcessDisconnected();
static UINT WINAPI AsyncProcessThread(LPVOID Param);
public:
PackageIOCPClient();
virtual ~PackageIOCPClient();
BOOL Connect(char* szHostName,USHORT Port);
VOID Send(CIOCPBuffer buffer);
VOID Send(BYTE* Buffer,DWORD Size);
public:
//Óû§Á¬½Ó״̬
virtual VOID NotifyConnectionStatus(IOCPClient_ConnectionType ConnectionType);
virtual VOID NotifyReceivedFormatPackage(CIOCPBuffer* lpBuffer);
};
#endif