代码出自《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
);谢谢!
// 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
);谢谢!
解决方案 »
- 【【【【【【【为什么tab control 点击不灵活,很奇怪的问题】】】】】】】】】】】】
- 编译问题
- 全局变量的问题
- DWORD dwDelay = GetTickCount() - m_dwStart;这样一条语句出错,大家看看什么原因?
- 高手请来看看这个问题。
- 对于大量数据的接收,这样的方法是否合理?
- 请问各位程序员 : 何谓‘系统集成‘??
- 大家有没有碰到这样的问题
- 急 谁会做MFC下拉菜单里读取文本内容 文本里是人名和对应手机号
- 急问:谁有pos3和smtp协议的包的具体格式或相关资料啊?坚决给分的
- 请教!如何实现单击按钮,弹出一个记事本文件.
- oledb访问ACCESS数据库,GetNextRows函数只能返回一条记录?
将“每个IO操作完成后无为引发completion port”通告的开关关闭。也就等同于IO操作完成后,完成端口并不通知你。
=>
每个IO操作完成后均会引发completion port
书上说:“并将其最低位设立,以表示当写入操作完成时,不需要任何packet 被送往completion port。范例程序并未检查完成后的“overlapped 写入”操作结果。“我应该是对完成端口本身没有理解,我慢慢搞吧。.