GetOverlappedResult() or ReadFile() on Socket returns TRUE with lesser number of bytes
Hi,
I am writing a TCP/IP Server application that handles several clients.
I am using the overlapped ReadFile() and WriteFile() in a single thread per client inside the Server. Every client sends data to Server in packets of size 2 kbytes each.
Server if required, sends data to a client in packets of size 2 kbytes each.
In general, this is working fine.
After calling ReadFile() which returns error code ERROR_IO_PENDING, I am using a WaitForSingleObject with Timeout for the Overlapped Read completion event.
When Overlapped event is signalled, I check the result as below:
GetOverlappedResult( ClientSocketHandle, &ovReadStruct, &dwBytesRead, FALSE);
With 20-100 ms timeout for WaitForSingleObject, I did not find any problems.
However, with 0 ms timeout, I face the following problem occasionally for a client. After few hours, it may happen for another client:
ReadFile() or GetOverlappedResult() returns TRUE with lesser number of bytes than requested.
ReadFile() is requested for 2048 bytes.
Very rarely, the Bytes read is 1460 bytes.
But, return value is TRUE!!!
Can someone explain why and how this can happen?
Is this a known behaviour of overlapped ReadFile with Sockets?
If so, how to handle this?
For overlapped operation for Serial Port, I have read in MSDN that the overlapped operation can get timed out, and hence return fewer number of bytes read till then.
But, nothing is documented about the behaviour on Sockets.
I will be thankful if some one can help me out!

