SYSTEM_INFO sysInfo; //定义系统信息结构体
GetSystemInfo(&sysInfo); //获取系统信息
for (int i = 0; i < (int)(sysInfo.dwNumberOfProcessors*2+2); i++)
{
HANDLE hThread = CreateThread(NULL,0,ThreadProc,this,0,NULL);
if (hThread == NULL)
{
TRACE("err code=%d\n",GetLastError());
return;
}
}
(3)编写线程处理函数:
DWORD WINAPI CMY_UdpIocpSrvDlg::ThreadProc(LPVOID lpParameter)
{
CMY_UdpIocpSrvDlg *p = (CMY_UdpIocpSrvDlg*)lpParameter;
DWORD bytestransferred;
DWORD key;本文来自辣.文~论^文·网原文请找腾讯324.9114
DWORD flag = 0;
//定义并初始化一个包
LPPER_IO_DATA pData = new PER_IO_DATA;
pData->data.buf = pData->buf;
pData->data.len = DATA_SIZE;
pData->opType = RECV_POSTED;
int addrlen = sizeof(sockaddr_in);
memset(&pData->ol,0,sizeof(OVERLAPPED));
//向I/O系统投递一个异步请求(重叠方式)
intret=WSARecvFrom(p->udpSocket,&pData->data,1,&bytestransferred,&flag,(sockaddr*)&pData->addr,&addrlen,&pData->ol,NULL);
if (SOCKET_ERROR == ret)
{
if (WSA_IO_PENDING == WSAGetLastError())
{
}
else
{
if (pData != NULL)
delete pData;
return 1;
}
}
while (TRUE)
{
LPPER_IO_DATA pIoData = NULL;
//轮询完成通知队列
if (GetQueuedCompletionStatus(p->hIocp,&bytestransferred,&key,
(LPOVERLAPPED*)&pIoData,INFINITE)==FALSE)
{
if (WAIT_TIMEOUT == GetLastError()) //超时
{
continue;
}
return 1;
}
if (key == -1)
{
if (pIoData != NULL)
delete pIoData; //释放丢弃包的内存空间
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >>
C++的多媒体屏幕广播教学系统设计 第12页下载如图片无法显示或论文不完整,请联系qq752018766