spiocpevent.hpp
2.3 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
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright 2008 Stephen Liu
* For license terms, see the file COPYING along with this library.
*/
#ifndef __spiocpevent_hpp__
#define __spiocpevent_hpp__
#include "spporting.hpp"
typedef struct tagSP_IocpEvent {
enum { SP_IOCP_MAX_IOV = 8 };
enum { eEventUnknown, eEventRecv, eEventSend, eEventTimer };
OVERLAPPED mOverlapped;
int mType;
WSABUF mWsaBuf;
void ( * mOnTimer ) ( void * );
int mHeapIndex;
struct timeval mTimeout;
} SP_IocpEvent_t;
class SP_IocpEventHeap {
public:
SP_IocpEventHeap();
~SP_IocpEventHeap();
int push( SP_IocpEvent_t * item );
SP_IocpEvent_t * top();
SP_IocpEvent_t * pop();
int erase( SP_IocpEvent_t * item );
int getCount();
private:
static int isGreater( SP_IocpEvent_t * item1, SP_IocpEvent_t * item2 );
int reserve( int count );
void shiftUp( int index, SP_IocpEvent_t * item );
void shiftDown( int index, SP_IocpEvent_t * item );
SP_IocpEvent_t ** mEntries;
int mMaxCount, mCount;
};
class SP_CircleQueue;
class SP_BlockingQueue;
class SP_SessionManager;
class SP_IocpMsgQueue {
public:
typedef void ( * QueueFunc_t ) ( void * queueData, void * arg );
SP_IocpMsgQueue( HANDLE completionPort, DWORD completionKey, QueueFunc_t func, void * arg );
~SP_IocpMsgQueue();
int push( void * queueData );
int process();
private:
HANDLE mCompletionPort;
DWORD mCompletionKey;
QueueFunc_t mFunc;
void * mArg;
HANDLE mMutex;
SP_CircleQueue * mQueue;
};
class SP_IocpEventArg {
public:
SP_IocpEventArg( int timeout );
~SP_IocpEventArg();
HANDLE getCompletionPort();
SP_BlockingQueue * getInputResultQueue();
SP_BlockingQueue * getOutputResultQueue();
void setResponseQueue( SP_IocpMsgQueue * responseQueue );
SP_IocpMsgQueue * getResponseQueue();
SP_SessionManager * getSessionManager();
SP_IocpEventHeap * getEventHeap();
int loadDisconnectEx( SOCKET fd );
BOOL disconnectEx( SOCKET fd, LPOVERLAPPED lpOverlapped,
DWORD dwFlags, DWORD reserved );
void setTimeout( int timeout );
int getTimeout();
private:
SP_BlockingQueue * mInputResultQueue;
SP_BlockingQueue * mOutputResultQueue;
SP_IocpMsgQueue * mResponseQueue;
SP_SessionManager * mSessionManager;
SP_IocpEventHeap * mEventHeap;
void * mDisconnectExFunc;
int mTimeout;
HANDLE mCompletionPort;
};
#endif