结构体:
struct Msg
{
unsigned char type;
short option;
unsigned short totalLen;
unsigned char* data;
};
struct ResponseProcParam
{
Msg msg;
void* p_socket;
MsgManagement manage;
};
创建线程:
ResponseProcParam* param = new ResponseProcParam();
param->p_socket =(void *) (&fdSocket.fd_array[i]);
param->msg = msg;
param->manage = portListener.manage;
HANDLE manageThread = CreateThread(NULL,0,ManageTransientMsg,param,0,NULL);
线程函数:
DWORD WINAPI ManageTransientMsg(LPVOID pParam)
{
ResponseProcParam* param = (ResponseProcParam*)pParam;
MsgManagement manage = param->manage;
manage(param->p_socket,param->msg.data,param->msg.totalLen-MsgOP::getHeaderLen(),param->msg.type,param->msg.option);
//释放空间
if(param!=NULL)
{
if(param->msg.data!=NULL)
delete param->msg.data;
/*CBlockingSocket cSocket;
cSocket.m_socket = *((SOCKET*)param->p_socket);
cSocket.Close();*/
delete param;
}
return 0;
}