WinDivert连接丢失 [英] WinDivert connection loss

查看:175
本文介绍了WinDivert连接丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2015中使用WinDivert 1.1.8 MSVC x64以及 P/Invoke wrapper for C#创建一个简单的等待时间模拟器,但是当执行带宽密集型任务(如速度测试)时,连接将失败.

输出

ERROR_IO_PENDING 997(0x3E5)重叠的I/O操作正在进行中.

ERROR_INSUFFICIENT_BUFFER 122(0x7A)传递给系统调用的数据区域太小.

注释

x64远程调试是否可能导致死锁?

可能使WinDivert队列不堪重负吗?

更新

我尝试了并行线程,这会产生相同的错误.

Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), x => RunDiversion());

更新2

在进一步测试代码之后,违规行可能是:

packet.CopyTo(newpacket.data, 0);

更新3

CPU堆栈 WinDivert队列可能需要编组吗?

解决方案

您应该使用WinDivertRecvEx而不是WinDivertRecv以避免重叠的I/O.另外,您在多线程应用程序上使用Queue<T>,我相信您应该改用ConcurrentQueue<T>.

我认为x64调试器也可能会引起问题.我正在运行该应用程序而未进行调试,并且可以正常运行(CTRL + F5).

工作代码: https://gist.github.com/fahminlb33/16f69460466eb07f88e7588a285fb4f8 /p>

I am using WinDivert 1.1.8 MSVC x64 in Visual Studio 2015 along with a P/Invoke wrapper for C# to create a simple latency simulator, but the connection fails when performing bandwidth intensive tasks, such as a speedtest.

Output

ERROR_IO_PENDING 997 (0x3E5) Overlapped I/O operation is in progress.

ERROR_INSUFFICIENT_BUFFER 122 (0x7A) The data area passed to a system call is too small.

Notes

Possible deadlocking caused by x64 remote debugging?

Possibly overwhelming the WinDivert queue?

Update

I have tried parallel threading and this produced the same errors.

Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), x => RunDiversion());

Update 2

After further testing the code the offending line may be:

packet.CopyTo(newpacket.data, 0);

Update 3

CPU Stack WinDivert queue possibly needs marshalling?

解决方案

You should be using WinDivertRecvEx instead of WinDivertRecv to avoid overlapped I/O. Also, you're using Queue<T> on multithreaded app, which I believe you should use ConcurrentQueue<T> instead.

I think x64 debugger may cause problems too. I'm running the app without debugging and it works (CTRL+F5).

Working code: https://gist.github.com/fahminlb33/16f69460466eb07f88e7588a285fb4f8

这篇关于WinDivert连接丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆