#ifndef _CCOMPLETIONHANDLER_H_ #define _CCOMPLETIONHANDLER_H_ #include #include //----------------------------------------------------------------------------- // CCompletionHandler Class //----------------------------------------------------------------------------- class CCompletionHandler { private: HANDLE m_hIOCP; unsigned long m_nThread; unsigned long m_nTimeOutMS; public: CCompletionHandler(); virtual ~CCompletionHandler(); bool Initialize(unsigned long nThread = 0, unsigned long nTimeOutMS = INFINITE); // Completion Handler¸¦ ÃʱâÈ­ÇÑ´Ù. bool Destroy(); // Completion Hander¸¦ ¼Ò¸ê½ÃŲ´Ù. bool AttachToHander(HANDLE hAttach, ULONG_PTR pCompletionKey); // Completion Handler¿¡ »õ ÇÚµéÀ» Ãß°¡ÇÑ´Ù. BOOL GetHanderStatus(LPDWORD lpNumOfBytes, PULONG_PTR lpCompletionKey, LPOVERLAPPED *lpOverlapped); // ÀÛ¾÷ÀÌ ³¡³­ ÇÚµéÀ» ¾ò¾î ¿Â´Ù. ±×µ¿¾ÈÀº blockµÈ´Ù. BOOL PostToHandler(unsigned long dwNumOfBytesTransfered, ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped); // Handler¿¡ ÀÛ¾÷À» °­Á¦·Î Ãß°¡ÇÑ´Ù. }; //----------------------------------------------------------------------------- // Inline Implementation ------------------------------------------------------ inline bool CCompletionHandler::AttachToHander(HANDLE hAttach, ULONG_PTR pCompletionKey) { return (0 != CreateIoCompletionPort(hAttach, m_hIOCP, pCompletionKey, m_nThread)); } inline BOOL CCompletionHandler::GetHanderStatus(LPDWORD lpNumOfBytes, PULONG_PTR lpCompletionKey, LPOVERLAPPED *lpOverlapped) { return GetQueuedCompletionStatus(m_hIOCP, lpNumOfBytes, lpCompletionKey, lpOverlapped, m_nTimeOutMS); } inline BOOL CCompletionHandler::PostToHandler(unsigned long dwNumOfBytesTransfered, ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped) { return PostQueuedCompletionStatus(m_hIOCP, dwNumOfBytesTransfered, dwCompletionKey, lpOverlapped); } #endif