Calling WSARecv with an address of WSABUF.buf+TotalReceivedBytes will have very weird results. I use this method to overcome buffer copying.
TotalReceivedBytes is just a per io variable to hold each user totalbytes
received through GetQueuedCompletionStatus then each time i add lpNumberOfBytes
to my defined variable. But when this happens and the TotalReceivedBytes is not DWORD aligned for example 0x1015 returned from GetQueuedCompletionStatus
function this causes the GetQueuedCompletionStatus to stop returning and sleeps forever and even the close socket events wont wake it up.
This had led me to memory leaking as the buffers and per IO resources never freed up. But it works well if the TotalReceivedBytes were 0x2000 but i can not control how many to
receive i used WSARecv with 0x2000 buffer size but it just returns data received 0x1015 on the first call.
So how do i overcome this problem? should i always reallocate buffer using heap functions? but this makes the app slow. What is the solution to this problem?
What I have tried:
Tried to use timeout value on
GetQueuedCompletionStatus
but it returns with 0 GetLastError reports WAIT_TIMEOUT. And
lpNumberOfBytes
returns 0 as well which skips my WSARecv call and so the data stuck there never polled out.
using dynamic buffer reallocation each time through HeapRealloc works fine but this has too much overhead when too many WSARecv called.