|
看看CAttemperEngine中处理数据的代码:
1 // 队列接口
2 void __cdecl CAttemperEngine::OnQueueServiceSink(WORD wIdentifier, void * pBuffer, WORD wDataSize, DWORD dwInsertTime)
3 {
4 //内核事件
5 ASSERT(m_pIAttemperEngineSink!=NULL);
6 switch (wIdentifier)
7 {
8 case EVENT_TIMER: //定时器事件
9 {
10 //效验参数
11 ASSERT(wDataSize==sizeof(NTY_TimerEvent));
12 if (wDataSize!=sizeof(NTY_TimerEvent)) return;
13
14 //处理消息
15 NTY_TimerEvent * pTimerEvent=(NTY_TimerEvent *)pBuffer;
16 m_pIAttemperEngineSink->OnEventTimer(pTimerEvent->wTimerID,pTimerEvent->wBindParam);
17
18 return;
19 }
20 case EVENT_DATABASE: //数据库事件
21 {
22 //效验参数
23 ASSERT(wDataSize>=sizeof(NTY_DataBaseEvent));
24 if (wDataSize<sizeof(NTY_DataBaseEvent)) return;
25
26 //处理消息
27 NTY_DataBaseEvent * pDataBaseEvent=(NTY_DataBaseEvent *)pBuffer;
28 m_pIAttemperEngineSink->OnEventDataBase(pDataBaseEvent+1,wDataSize-sizeof(NTY_DataBaseEvent),pDataBaseEvent);
29
30 return;
31 }
32 case EVENT_SOCKET_ACCEPT: //网络应答事件
33 {
34 //效验大小
35 ASSERT(wDataSize==sizeof(NTY_SocketAcceptEvent));
36 if (wDataSize!=sizeof(NTY_SocketAcceptEvent)) return;
37
38 //处理消息
39 NTY_SocketAcceptEvent * pSocketAcceptEvent=(NTY_SocketAcceptEvent *)pBuffer;
40 m_pIAttemperEngineSink->OnEventSocketAccept(pSocketAcceptEvent);
41
42 return;
43 }
44 case EVENT_SOCKET_READ: //网络读取事件
45 {
46 //效验大小
47 NTY_SocketReadEvent * pSocketReadEvent=(NTY_SocketReadEvent *)pBuffer;
48 ASSERT(wDataSize>=sizeof(NTY_SocketReadEvent));
49 ASSERT(wDataSize==(sizeof(NTY_SocketReadEvent)+pSocketReadEvent->wDataSize));
50 if (wDataSize<sizeof(NTY_SocketReadEvent)) return;
51 if (wDataSize!=(sizeof(NTY_SocketReadEvent)+pSocketReadEvent->wDataSize)) return;
52
53 //处理消息
54 bool bSuccess=false;
55 try
56 {
57 bSuccess=m_pIAttemperEngineSink->OnEventSocketRead(pSocketReadEvent->Command,pSocketReadEvent+1,pSocketReadEvent->wDataSize,pSocketReadEvent);
58 }
59 catch () { }
60 if (bSuccess==false) m_pITCPSocketEngine->CloseSocket(pSocketReadEvent->wIndex,pSocketReadEvent->wRoundID);
61
62 return;
63 }
64 case EVENT_SOCKET_CLOSE: //网络关闭事件
65 {
66 //效验大小
67 ASSERT(wDataSize==sizeof(NTY_SocketCloseEvent));
68 if (wDataSize!=sizeof(NTY_SocketCloseEvent)) return;
69
70 //处理消息
71 NTY_SocketCloseEvent * pSocketCloseEvent=(NTY_SocketCloseEvent *)pBuffer;
72 m_pIAttemperEngineSink->OnEventSocketClose(pSocketCloseEvent);
73
74 return;
75 }
76 }
77
78 //其他事件
79 m_pIAttemperEngineSink->OnAttemperEvent(wIdentifier,pBuffer,wDataSize,dwInsertTime);
80
81 return;
82}
|
|