// IOCP.cpp: implementation of the CMemoryPool class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "MemoryPool.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMemoryPool::CMemoryPool() { m_ListenSocket = NULL; } CMemoryPool::~CMemoryPool() { if(m_ListenSocket != NULL) { closesocket(m_ListenSocket); m_ListenSocket = NULL; } } /********************************************************************************/ // Á¢¼Ó¿¡ ´ëÇÑ ¸Þ¸ð¸®¸¦ ÇÒ´çÇÏ°í ¿¬°á /********************************************************************************/ pPerSocketContext CMemoryPool::AllocPerSocketContext(SOCKET clientSocket) { pPerSocketContext pPerSocketCtx = NULL; if (m_pPerSocketCtxMemPool->GetAllocCount() == m_pPerSocketCtxMemPool->GetBlockCount()) return NULL; pPerSocketCtx = m_pPerSocketCtxMemPool->Alloc(); if (!pPerSocketCtx) return NULL; pPerSocketCtx->socket = clientSocket; pPerSocketCtx->recvContext = AllocPerIoContextForRecv(); pPerSocketCtx->sendContext = AllocPerIoContextForSend(); pPerSocketCtx->recvContext->ReleaseBuffer(); pPerSocketCtx->sendContext->ReleaseBuffer(); return pPerSocketCtx; } int CMemoryPool::GetSocketContextAllocCount() { return m_pPerSocketCtxMemPool->GetAllocCount(); } // Per Io Context ¸Þ¸ð¸® ÇÒ´ç pPerIoContext CMemoryPool::AllocPerIoContextForSend(void) { pPerIoContext pPerSendIoCtx = NULL; pPerSendIoCtx = m_pSendMemPool->Alloc(); return pPerSendIoCtx; } // Per Socket Context ¸Þ¸ð¸® ÇÒ´ç pPerIoContext CMemoryPool::AllocPerIoContextForRecv(void) { pPerIoContext pPerRecvIoCtx = NULL; pPerRecvIoCtx = m_pRecvMemPool->Alloc(); return pPerRecvIoCtx; } // PerSocketContext ¸Þ¸ð¸® Á¦°Å void CMemoryPool::DeallocPerSocketContext(pPerSocketContext pPerSocketCtx) { assert(pPerSocketCtx); // IO Context ÇÒ´çÇÑ °Í Á¦°Å pPerSocketCtx->recvContext->ReleaseBuffer(); pPerSocketCtx->sendContext->ReleaseBuffer(); DeallocPerIoContextForRecv(pPerSocketCtx->recvContext); DeallocPerIoContextForSend(pPerSocketCtx->sendContext); // ¼ÒÄÏ ÄÁÅØ½ºÆ® Á¦°Å BOOL bRet=m_pPerSocketCtxMemPool->Free(pPerSocketCtx); assert(bRet); } void CMemoryPool::DeallocPerIoContextForSend(pPerIoContext pPerSendIoCtx) { assert(pPerSendIoCtx); BOOL bRet = m_pSendMemPool->Free(pPerSendIoCtx); assert(bRet); } // PerIoContext ¸Þ¸ð¸® Á¦°Å void CMemoryPool::DeallocPerIoContextForRecv(pPerIoContext pPerRecvIoCtx) { assert(pPerRecvIoCtx); BOOL bRet = m_pRecvMemPool->Free(pPerRecvIoCtx); assert(bRet); }