class CAsyncSocketExHelperWindow; class CAsyncSocketExLayer; class CCriticalSectionWrapper; class CAsyncSocketEx : public CObject { DECLARE_DYNAMIC(CAsyncSocketEx) public: //Attaches a new layer to the socket. BOOL AddLayer(CAsyncSocketExLayer *pLayer); //Trigers an event on the socket // Any combination of FD_READ, FD_WRITE, FD_CLOSE, FD_ACCEPT, FD_CONNECT and FD_FORCEREAD is valid for lEvent. BOOL TriggerEvent(long lEvent); protected: //Strucure to hold the socket data struct t_AsyncSocketExData { SOCKET hSocket; //Socket handle int nSocketIndex; //Index of socket, required by CAsyncSocketExHelperWindow } m_SocketData; //If using layers, only the events specified with m_lEvent will send to the event handlers. long m_lEvent; //Critical section for thread synchronization static CCriticalSectionWrapper m_sGlobalCriticalSection; //Pointer to the data of the local thread struct t_AsyncSocketExThreadData { CAsyncSocketExHelperWindow *m_pHelperWindow; int nInstanceCount; DWORD nThreadId; } *m_pLocalAsyncSocketExThreadData; //List of the data structures for all threads static struct t_AsyncSocketExThreadDataList { t_AsyncSocketExThreadDataList *pNext; t_AsyncSocketExThreadData *pThreadData; } *m_spAsyncSocketExThreadDataList; //Initializes Thread data and helper window, fills m_pLocalAsyncSocketExThreadData BOOL InitAsyncSocketExInstance(); //Layer chain CAsyncSocketExLayer *m_pFirstLayer; CAsyncSocketExLayer *m_pLastLayer; friend CAsyncSocketExLayer; //Called by the layers to notify application of some events virtual int OnLayerCallback(const CAsyncSocketExLayer *pLayer, int nType, int nParam1, int nParam2); friend CAsyncSocketExHelperWindow; };