重叠模型之完成例程

来源:互联网 发布:mac 文件路径 编辑:程序博客网 时间:2024/04/29 07:08

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

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

原创粉丝点击