How do I handle partial write completions from overlapped I/O using I/O Completion Ports
On Windows I/O completion ports, say I do this:
void function()
{
WSASend("1111"); // A
WSASend("2222"); // B
WSASend("3333"); // C
}
If I got a "write-complete" that s开发者_运维知识库ays 3 bytes of WSASend() A were sent, is it possible that right after that I'll get a "write-complete" that tells me that some or all of B & C were sent, or will TCP will hold them until I re-issue a WSASend() call with the rest of A's data? Or will TCP complete it automatically?
I've been developing client and server systems with IOCP for over 10 years now and I've never seen a partial write completion in normal usage. You CAN get them but if you do then the chances are your server is hosed anyway; you'll likely get a write completion with an error of ENOBUFS which tends to mean that you've exhausted non-paged pool or exceeded the locked pages limit.
IMHO you should manage your resources such that you never hit these operating system limits.
If a write completion returns less than the number of bytes that you think you should have written then there's not really much that you can do to recover if you have more writes pending. In the example in your question if A failed then you could only really shutdown the connection as B and C might succeed. In practice you don't have to worry about more than this.
If you know that you don't have any more writes pending on that connection then you COULD issue another write to write the subsequent data.
And TCP doesn't come into this at all.
精彩评论