spwin32iocp.hpp
2.4 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
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright 2008 Stephen Liu
* For license terms, see the file COPYING along with this library.
*/
#ifndef __spwin32iocp_hpp__
#define __spwin32iocp_hpp__
#include <winsock2.h>
#include <mswsock.h>
#include <windows.h>
#include <stdio.h>
#include "spiocpevent.hpp"
class SP_HandlerFactory;
class SP_IOChannelFactory;
class SP_Session;
class SP_Message;
class SP_Response;
typedef struct tagSP_IocpAcceptArg {
SP_HandlerFactory * mHandlerFactory;
SP_IOChannelFactory * mIOChannelFactory;
int mReqQueueSize;
int mMaxConnections;
char * mRefusedMsg;
// per handle data
SP_IocpEventArg * mEventArg;
HANDLE mListenSocket;
// per io data
OVERLAPPED mOverlapped;
HANDLE mClientSocket;
char mBuffer[ 1024 ];
HANDLE mAcceptEvent;
} SP_IocpAcceptArg_t;
typedef struct tagSP_IocpSession {
SP_Session * mSession;
SP_IocpEventArg * mEventArg;
HANDLE mHandle;
SP_IocpEvent_t mRecvEvent;
SP_IocpEvent_t mSendEvent;
OVERLAPPED mFreeEvent;
} SP_IocpSession_t;
class SP_IocpEventCallback {
public:
enum { eKeyUnknown, eKeyAccept, eKeyMsgQueue, eKeyFree };
static BOOL addSession( SP_IocpEventArg * eventArg, HANDLE client, SP_Session * session );
static BOOL addRecv( SP_Session * session );
static BOOL addSend( SP_Session * session );
static void onRecv( SP_IocpSession_t * iocpSession );
static void onSend( SP_IocpSession_t * iocpSession );
static BOOL onAccept( SP_IocpAcceptArg_t * acceptArg );
static void onResponse( void * queueData, void * arg );
static void onTimeout( SP_IocpEventArg * eventArg );
static BOOL eventLoop( SP_IocpEventArg * eventArg, SP_IocpAcceptArg_t * acceptArg );
private:
SP_IocpEventCallback();
~SP_IocpEventCallback();
};
typedef struct tagSP_Sid SP_Sid_t;
class SP_IocpEventHelper {
public:
static void doStart( SP_Session * session );
static void start( void * arg );
static void doWork( SP_Session * session );
static void worker( void * arg );
static void doError( SP_Session * session );
static void error( void * arg );
static void doTimeout( SP_Session * session );
static void timeout( void * arg );
static void doClose( SP_Session * session );
static void close( void * arg );
static void doDecodeForWork( SP_Session * session );
static void doCompletion( SP_IocpEventArg * eventArg, SP_Message * msg );
static int isSystemSid( SP_Sid_t * sid );
static DWORD timeoutNext( SP_IocpEventHeap * eventHeap );
private:
SP_IocpEventHelper();
~SP_IocpEventHelper();
};
#endif