代码出自《Win32多线程程序设计》中完成端口应用于socket的例子        
// ContextKey 的定义:struct ContextKey
{
    SOCKET  sock;
    // Input
    char        InBuffer[4];
    OVERLAPPED  ovIn;
    // Output
    int         nOutBufIndex;
    char        OutBuffer[MAXLINE];
    OVERLAPPED  ovOut;
    DWORD       dwWritten;
};// 节选的源码        // Create a context key and initialize it.
        // calloc will zero the buffer
        pKey = calloc(1, sizeof(struct ContextKey));
        pKey->sock = newsocket;
        pKey->ovOut.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        // Set the event for writing so that packets
        // will not be sent to the completion port when
        // a write finishes.
        pKey->ovOut.hEvent = (HANDLE)((DWORD)pKey->ovOut.hEvent | 0x1); // 这一行是什么意思?        // Associate the socket with the completion port
        CreateIoCompletionPort(
                (HANDLE)newsocket,
                ghCompletionPort,
                (DWORD)pKey,   // No key
                0              // Use default # of threads
            );谢谢!

解决方案 »

  1.   

    将事件对象的最低位置位,实际上是一种的做蔽的方法。表示当写入操作完成时,不需要任何packet被送往competion port.
      

  2.   

    就是把hEvent的最低位设置为1。
      

  3.   

    DentistryDoctor(My heart will fly,in the sky.)  : 为何会用这种方式? 太奇怪了。
      

  4.   

    orbit(走了走了) :   或运算后,hEvent 的值会改变,而SetEvent(hEvent) 之后,hEvent的值不会改变。真搞不懂怎么会有这种代码,ft
      

  5.   

    这个操作的目的是
    将“每个IO操作完成后无为引发completion port”通告的开关关闭。也就等同于IO操作完成后,完成端口并不通知你。
      

  6.   

    每个IO操作完成后无为引发completion port
    =>
    每个IO操作完成后均会引发completion port
      

  7.   

    多谢!
    书上说:“并将其最低位设立,以表示当写入操作完成时,不需要任何packet 被送往completion port。范例程序并未检查完成后的“overlapped 写入”操作结果。“我应该是对完成端口本身没有理解,我慢慢搞吧。.