本文介绍了如何触发WSAOVERLAPPED事件? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 注意:我遇到麻烦的特定情况是当lpCompletionRoutine为null和lpOverlapped不是。 我试图写一个数据包嗅探器。我挂钩WSARecv并替换为我自己的代码。如果lpOverlapped不为null,我创建自己的LPWSAOVERLAPPED变量并调用真正的WSARecv。我收到并记录数据包就好了,但问题是,我嗅探的客户端似乎等待它的WSAOVERLAPPED事情被触发。 所以问题是,我如何触发初始lpOverlapped?我试过像WSASetEvent。我尝试做内联asm并做这样的事情: __ asm { push InFlags push lpOverlapped push BytesTransferred push错误调用lpOverlapped } 这些事情都没有奏效。我认为应该有一个简单的方法来触发wsaoverlapped,所以游戏知道i / o操作完成,但我只是不知道如何。 编辑: 我尝试通过执行以下操作来发信号通知代码,但是我收到一个ERROR_INVALID_HANDLE错误。 WSAOVERLAPPED overlapped = * lpOverlapped; HANDLE hEvent = overlapped.hEvent; if(!SetEvent(hEvent)){ int error = GetLastError(); Write(error); } 有什么特别的事我需要做准备活动吗? 谢谢!解决方案同意Eugene Homyakov,实际上,操作系统可以通过3种方式通知进程关于重叠I / O完成。 设置由 结构 调用完成例程(在 关于完成例程 - 您应该注意,当I / O完成时,它会调度到调用者线程的APC队列。它实际上只有当线程调用一个可警告的等待过程,例如 SleepEx 或 WaitForMultipleObjectsEx 。 如果套接字/文件句柄已经与它相关联,那么操作系统将把完成发布到完成端口。有关详细信息,请参阅 CreateIoCompletionPort 和 PostQueuedCompletionStatus 。 Note: The particular case I'm having troubles with is when lpCompletionRoutine is null and lpOverlapped is not.I'm trying to write a packet sniffer. I'm hooking WSARecv and replacing it with my own code. If lpOverlapped is not null, I create my own LPWSAOVERLAPPED variable and call the real WSARecv. I receive and log the packet just fine, but the problem is, the client that I'm sniffing seems to wait for it's WSAOVERLAPPED thing to be triggered.So the question is, how do I trigger the initial lpOverlapped? I've tried things like WSASetEvent. I've tried doing inline asm and doing something like this:__asm{ push InFlags push lpOverlapped push BytesTransferred push Error call lpOverlapped}Neither of those things worked. I'm thinking there should be a simple way to trigger the wsaoverlapped so the game knows that the i/o operation is complete, but I just don't know how.Any and all help is appreciated.Thanks!edit:I've tried signaling the code by doing the following, but I get an ERROR_INVALID_HANDLE error.WSAOVERLAPPED overlapped = *lpOverlapped;HANDLE hEvent = overlapped.hEvent;if(!SetEvent(hEvent)){ int error = GetLastError(); Write(error);}Is there something special I need to do to prepare the event?Thanks! 解决方案 Agree with Eugene Homyakov, with one little addition. Actually there are 3 ways the OS may notify the process about overlapped I/O completion.Setting the event specified by hEvent member of the OVERLAPPED structureInvoking the completion routine (specified in the call to WSAxxxx).Posting a completion to the completion port.About the completion routine - you should note that it's scheduled to the caller thread's APC queue when the I/O completes. It actually gets called only when the thread calls an alertable wait procedure, such as SleepEx or WaitForMultipleObjectsEx.The OS will post the completion to the completion port if the socket/file handle has been associated with it. See CreateIoCompletionPort and PostQueuedCompletionStatus for more info. 这篇关于如何触发WSAOVERLAPPED事件? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 17:46