提交 112fbabd715fbca0e33cbfa28b3742b046a9fd99

作者 LJH 李佳桓
1 个父辈 96c3fd6b

add

正在显示 1 个修改的文件 包含 108 行增加0 行删除
  1 +/*
  2 + * Copyright 2008 Stephen Liu
  3 + * For license terms, see the file COPYING along with this library.
  4 + */
  5 +
  6 +#ifndef __spwin32iocp_hpp__
  7 +#define __spwin32iocp_hpp__
  8 +
  9 +#include <winsock2.h>
  10 +#include <mswsock.h>
  11 +#include <windows.h>
  12 +#include <stdio.h>
  13 +
  14 +#include "spiocpevent.hpp"
  15 +
  16 +class SP_HandlerFactory;
  17 +class SP_IOChannelFactory;
  18 +class SP_Session;
  19 +class SP_Message;
  20 +class SP_Response;
  21 +
  22 +typedef struct tagSP_IocpAcceptArg {
  23 + SP_HandlerFactory * mHandlerFactory;
  24 + SP_IOChannelFactory * mIOChannelFactory;
  25 +
  26 + int mReqQueueSize;
  27 + int mMaxConnections;
  28 + char * mRefusedMsg;
  29 +
  30 + // per handle data
  31 + SP_IocpEventArg * mEventArg;
  32 + HANDLE mListenSocket;
  33 +
  34 + // per io data
  35 + OVERLAPPED mOverlapped;
  36 + HANDLE mClientSocket;
  37 + char mBuffer[ 1024 ];
  38 +
  39 + HANDLE mAcceptEvent;
  40 +} SP_IocpAcceptArg_t;
  41 +
  42 +typedef struct tagSP_IocpSession {
  43 + SP_Session * mSession;
  44 + SP_IocpEventArg * mEventArg;
  45 +
  46 + HANDLE mHandle;
  47 +
  48 + SP_IocpEvent_t mRecvEvent;
  49 + SP_IocpEvent_t mSendEvent;
  50 + OVERLAPPED mFreeEvent;
  51 +} SP_IocpSession_t;
  52 +
  53 +class SP_IocpEventCallback {
  54 +public:
  55 +
  56 + enum { eKeyUnknown, eKeyAccept, eKeyMsgQueue, eKeyFree };
  57 +
  58 + static BOOL addSession( SP_IocpEventArg * eventArg, HANDLE client, SP_Session * session );
  59 + static BOOL addRecv( SP_Session * session );
  60 + static BOOL addSend( SP_Session * session );
  61 +
  62 + static void onRecv( SP_IocpSession_t * iocpSession );
  63 + static void onSend( SP_IocpSession_t * iocpSession );
  64 + static BOOL onAccept( SP_IocpAcceptArg_t * acceptArg );
  65 + static void onResponse( void * queueData, void * arg );
  66 +
  67 + static void onTimeout( SP_IocpEventArg * eventArg );
  68 +
  69 + static BOOL eventLoop( SP_IocpEventArg * eventArg, SP_IocpAcceptArg_t * acceptArg );
  70 +
  71 +private:
  72 + SP_IocpEventCallback();
  73 + ~SP_IocpEventCallback();
  74 +};
  75 +
  76 +typedef struct tagSP_Sid SP_Sid_t;
  77 +
  78 +class SP_IocpEventHelper {
  79 +public:
  80 + static void doStart( SP_Session * session );
  81 + static void start( void * arg );
  82 +
  83 + static void doWork( SP_Session * session );
  84 + static void worker( void * arg );
  85 +
  86 + static void doError( SP_Session * session );
  87 + static void error( void * arg );
  88 +
  89 + static void doTimeout( SP_Session * session );
  90 + static void timeout( void * arg );
  91 +
  92 + static void doClose( SP_Session * session );
  93 + static void close( void * arg );
  94 +
  95 + static void doDecodeForWork( SP_Session * session );
  96 +
  97 + static void doCompletion( SP_IocpEventArg * eventArg, SP_Message * msg );
  98 +
  99 + static int isSystemSid( SP_Sid_t * sid );
  100 +
  101 + static DWORD timeoutNext( SP_IocpEventHeap * eventHeap );
  102 +
  103 +private:
  104 + SP_IocpEventHelper();
  105 + ~SP_IocpEventHelper();
  106 +};
  107 +
  108 +#endif
... ...
注册登录 后发表评论