提交 7fe2d536b0402571656ff8c1078b66d267b074d4

作者 LJH 李佳桓
1 个父辈 b8af8120

add

正在显示 1 个修改的文件 包含 119 行增加0 行删除
  1 +/*
  2 + * Copyright 2008 Stephen Liu
  3 + * For license terms, see the file COPYING along with this library.
  4 + */
  5 +
  6 +#ifndef __spiocpevent_hpp__
  7 +#define __spiocpevent_hpp__
  8 +
  9 +#include "spporting.hpp"
  10 +
  11 +typedef struct tagSP_IocpEvent {
  12 + enum { SP_IOCP_MAX_IOV = 8 };
  13 + enum { eEventUnknown, eEventRecv, eEventSend, eEventTimer };
  14 +
  15 + OVERLAPPED mOverlapped;
  16 + int mType;
  17 + WSABUF mWsaBuf;
  18 +
  19 + void ( * mOnTimer ) ( void * );
  20 +
  21 + int mHeapIndex;
  22 + struct timeval mTimeout;
  23 +} SP_IocpEvent_t;
  24 +
  25 +class SP_IocpEventHeap {
  26 +public:
  27 + SP_IocpEventHeap();
  28 + ~SP_IocpEventHeap();
  29 +
  30 + int push( SP_IocpEvent_t * item );
  31 +
  32 + SP_IocpEvent_t * top();
  33 +
  34 + SP_IocpEvent_t * pop();
  35 +
  36 + int erase( SP_IocpEvent_t * item );
  37 +
  38 + int getCount();
  39 +
  40 +private:
  41 +
  42 + static int isGreater( SP_IocpEvent_t * item1, SP_IocpEvent_t * item2 );
  43 +
  44 + int reserve( int count );
  45 +
  46 + void shiftUp( int index, SP_IocpEvent_t * item );
  47 + void shiftDown( int index, SP_IocpEvent_t * item );
  48 +
  49 + SP_IocpEvent_t ** mEntries;
  50 + int mMaxCount, mCount;
  51 +};
  52 +
  53 +class SP_CircleQueue;
  54 +class SP_BlockingQueue;
  55 +class SP_SessionManager;
  56 +
  57 +class SP_IocpMsgQueue {
  58 +public:
  59 + typedef void ( * QueueFunc_t ) ( void * queueData, void * arg );
  60 +
  61 + SP_IocpMsgQueue( HANDLE completionPort, DWORD completionKey, QueueFunc_t func, void * arg );
  62 + ~SP_IocpMsgQueue();
  63 +
  64 + int push( void * queueData );
  65 +
  66 + int process();
  67 +
  68 +private:
  69 + HANDLE mCompletionPort;
  70 + DWORD mCompletionKey;
  71 + QueueFunc_t mFunc;
  72 + void * mArg;
  73 +
  74 + HANDLE mMutex;
  75 + SP_CircleQueue * mQueue;
  76 +};
  77 +
  78 +class SP_IocpEventArg {
  79 +public:
  80 + SP_IocpEventArg( int timeout );
  81 + ~SP_IocpEventArg();
  82 +
  83 + HANDLE getCompletionPort();
  84 + SP_BlockingQueue * getInputResultQueue();
  85 + SP_BlockingQueue * getOutputResultQueue();
  86 +
  87 + void setResponseQueue( SP_IocpMsgQueue * responseQueue );
  88 + SP_IocpMsgQueue * getResponseQueue();
  89 +
  90 + SP_SessionManager * getSessionManager();
  91 +
  92 + SP_IocpEventHeap * getEventHeap();
  93 +
  94 + int loadDisconnectEx( SOCKET fd );
  95 +
  96 + BOOL disconnectEx( SOCKET fd, LPOVERLAPPED lpOverlapped,
  97 + DWORD dwFlags, DWORD reserved );
  98 +
  99 + void setTimeout( int timeout );
  100 + int getTimeout();
  101 +
  102 +private:
  103 + SP_BlockingQueue * mInputResultQueue;
  104 + SP_BlockingQueue * mOutputResultQueue;
  105 + SP_IocpMsgQueue * mResponseQueue;
  106 +
  107 + SP_SessionManager * mSessionManager;
  108 +
  109 + SP_IocpEventHeap * mEventHeap;
  110 +
  111 + void * mDisconnectExFunc;
  112 +
  113 + int mTimeout;
  114 +
  115 + HANDLE mCompletionPort;
  116 +};
  117 +
  118 +#endif
  119 +
... ...
注册登录 后发表评论