PostQueuedCompletionStatus 与 GetQueuedCompletionStatus

 PostQueuedCompletionStatus功能函数向一个已经初始完的I/O端口发送数据包,触发GetQueuedCompletionStatus功能调用函数来取得数据包

BOOL PostQueuedCompletionStatus(
HANDLE CompletionPort,  // handle to an I/O completion port  
DWORDdwNumberOfBytesTransferred,  // value to return via  GetQueuedCompletionStatus'  lpNumberOfBytesTranferred  
DWORD dwCompletionKey,  // value to return via  GetQueuedCompletionStatus'  lpCompletionKey  
LPOVERLAPPED lpOverlapped  // value to return via  GetQueuedCompletionStatus'lpOverlapped  
); 


以上PostQueuedCompletionStatus的三个参数的值正好由GetQueuedCompletionStatus函数接收

BOOL GetQueuedCompletionStatus(
  HANDLE CompletionPort,       // handle to completion port
  LPDWORD lpNumberOfBytes,     // bytes transferred
  PULONG_PTR lpCompletionKey,  // file completion key
  LPOVERLAPPED *lpOverlapped,  // buffer
  DWORD dwMilliseconds         // optional timeout value
); 



线程中,不断的执行GetQueuedCompletionStatus来从消息队列中读取数据
例如某一线程执行函数RepetitionRun:

//Run函数
bool CQueueServiceThread::RepetitionRun()
{
 //效验参数
 GT_ASSERT(m_hCompletionPort!=NULL);
 //变量定义
 DWORD dwThancferred=0;
 OVERLAPPED * pOverLapped=NULL;
 CQueueService * pQueueService=NULL;
 //等待完成端口
 if (GetQueuedCompletionStatus(m_hCompletionPort,&dwThancferred,(PULONG_PTR)&pQueueService,&pOverLapped,INFINITE))
 {
  //判断退出
  if (pQueueService==NULL) return false;
  //获取数据
  tagDataHead DataHead;
  bool bSuccess=pQueueService->GetData(DataHead,m_cbBuffer,sizeof(m_cbBuffer));
  GT_ASSERT(bSuccess==true);
  //处理数据
  if (bSuccess==true) pQueueService->OnQueueServiceThread(m_cbThreadIndex, DataHead,m_cbBuffer,DataHead.wDataSize);
  return true;
 }
 return false;
}
CreateIoCompletionPort则是创建消息队列
HANDLE CreateIoCompletionPort (
  HANDLE FileHandle,              // handle to file
  HANDLE ExistingCompletionPort,  // handle to I/O completion port
  ULONG_PTR CompletionKey,        // completion key
  DWORD NumberOfConcurrentThreads // number of threads to execute concurrently
);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值