关于事件句柄,hEvent = (HANDLE*)( (DWORD)hEvent | 0x1) 是什么意思?
代码出自《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
);
谢谢!