📄 iocpprocess.cpp
字号:
// IocpProcess.cpp: implementation of the CIocpProcess class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IocpProcess.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIocpProcess::CIocpProcess()
{
m_pIocpMngr = NULL;
}
CIocpProcess::~CIocpProcess()
{
}
int CIocpProcess::Processing(IOCPTASK& itTask)
{
int nErr=ERROR_NONE;
ZNET_TRY
{
CIocpContext* pContext=itTask.pContext;
CIocpPacket* pPacket=itTask.pPacket;
SOCKET soContext=(pContext!=NULL)?pContext->m_soContext:INVALID_SOCKET;
ULONG ulKey=(pPacket!=NULL)?pPacket->m_ulKey:0;
switch (itTask.wType)
{
case IOCPTASK_NEW_CONNECTION:
nErr = ProcessNewConnection(pContext);
break;
case IOCPTASK_DIS_CONNECTION:
nErr = ProcessDisConnection(soContext);
break;
case IOCPTASK_PACKET_BEGIN:
nErr = ProcessPacketBegin(soContext, pPacket);
break;
case IOCPTASK_PACKET_PROGRESS:
nErr = ProcessPacketProgress(soContext, ulKey, itTask.wParam, itTask.lParam);
break;
case IOCPTASK_PACKET_END:
nErr = ProcessPacketEnd(soContext, pPacket);
break;
case IOCPTASK_PACKET_PROCESS:
nErr = ProcessPacket(soContext, pPacket);
break;
case IOCPTASK_PACKET_CANCEL:
nErr = ProcessPacketCancel(soContext, ulKey);
break;
default:
nErr = ERROR_IOCPPROCESS_NOT_DONE;
break;
}
}
ZNET_CATCH
ZNET_CATCH_ALL(ERROR_IOCPPROCESS_PROCESS_EXCEPTION);
return nErr;
}
int CIocpProcess::ProcessNewConnection(CIocpContext* pContext)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
int CIocpProcess::ProcessDisConnection(SOCKET soSocket)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
int CIocpProcess::ProcessPacketBegin(SOCKET soSocket, CIocpPacket* pPacket)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
int CIocpProcess::ProcessPacketProgress(SOCKET soSocket, ULONG ulKey, WPARAM wParam, LPARAM lParam)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
int CIocpProcess::ProcessPacketEnd(SOCKET soSocket, CIocpPacket* pPacket)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
int CIocpProcess::ProcessPacketCancel(SOCKET soSocket, ULONG ulKey)
{
return ERROR_FUNC_NOT_IMPLEMENT;
}
int CIocpProcess::ProcessPacket(SOCKET soSocket, CIocpPacket* pPacket)
{
int nErr=ERROR_FUNC_NOT_IMPLEMENT;
if (pPacket!=NULL && m_pIocpMngr!=NULL)
{
IOCPWAITSEND iwWaitSend;
if (m_pIocpMngr->GetWaitSend(pPacket->GetPacketHeader().m_gdHeader, iwWaitSend))
{
if (iwWaitSend.pWaitPacket!=NULL)
pPacket->Clone(iwWaitSend.pWaitPacket); //拷贝返回数据
if (iwWaitSend.hWaitEvent!=NULL)
m_pIocpMngr->ReleaseWaitEvent(iwWaitSend.hWaitEvent); //清除同步命令的等待事件
nErr = ERROR_NONE;
}
else
{
CIocpPacketHeader& pkHeader=pPacket->GetPacketHeader();
if (pkHeader.m_nCmd==CMD_IOCP_COMMON)
{
if (pkHeader.m_wParam==CMD_IOCP_COMMON_SEND_CANCEL)
{
CIocpContext* pContext=m_pIocpMngr->FindContext(soSocket);
ULONG ulKey=pkHeader.m_lParam+1; //
IOCPTASK itTask;
itTask.wType = IOCPTASK_PACKET_CANCEL;
itTask.pContext = pContext;
itTask.pPacket = (pContext!=NULL)?pContext->FindPacket(ulKey):NULL;
nErr = m_pIocpMngr->Processing(itTask);
if (pContext!=NULL) pContext->ReleasePacket(ulKey, PACKETTYPE_READ);
}
else if (pkHeader.m_wParam==CMD_IOCP_COMMON_RECV_CANCEL)
{
ULONG ulKey=pkHeader.m_lParam-1;
nErr = m_pIocpMngr->CancelSendData(soSocket, ulKey);
}
}
}
}
return nErr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -