重叠模型之完成例程

本文详细解析了WSAWaitForMultipleEvents函数的工作原理及其参数意义,通过代码示例展示了如何利用该函数来处理I/O完成事件,特别强调了fAlertable参数的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WSAWaitForMultipleEvents Function

 

Parameters

 

fAlertable

A value that specifies whether the thread is placed in an alertable wait state so the system can execute I/O completion routines. If TRUE, the thread is placed in an altertable wait state and WSAWaitForMultipleEvents can return when the system executes an I/O completion routine. In this case, WSA_WAIT_IO_COMPLETION is returned and the event that was being waited on is not signaled yet. The application must call the WSAWaitForMultipleEvents function again. If FALSE, the thread is not placed in an altertable wait state and I/O completion routines are not executed.

 

完成例程的讲解比较少~尤其是调用的函数到底是谁?有没有又开了个线程。

参数说明(上面的说明说的很清楚~)


   DWORD curThreadId = GetCurrentThreadId();

都可以知道是没有,但是具体是怎样运行的那?

单步一下就知道了,再加个Sleep,更清晰了~

 

CODE:

 while(true)
 {
  //step 5:
  DWORD Index = WSAWaitForMultipleEvents(1, EventArray, FALSE, 1000, TRUE);
  //step 6:
  if( Index == WSA_IO_INCOMPLETE || Index == WSA_WAIT_TIMEOUT )
  {
   Sleep(30000);
   DWORD curThreadId = GetCurrentThreadId();
   printf("IO_INCOMPLETE waitEvent Thread Id is %d/n", curThreadId);
   int i = 1;
  }
  else if(Index == WSA_WAIT_IO_COMPLETION)
  {
   DWORD curThreadId = GetCurrentThreadId();
   printf("IO_COMPLETE waitEvent Thread Id is %d/n", curThreadId);
  }
 }

到执行WSAWaitForMultipleEvents的时候,先去看有无完成事件,如果完成了就去执行我们wsarecv时候注册的函数,然后WSAWaitForMultipleEvents返回WSA_WAIT_IO_COMPLETION

上面的英文说的也很清楚~仔细看看吧~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值