问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/44136191/windivert-connection-loss