Question

Say I post the following WSASend call (Windows I/O completion ports without callback functions):

void send_data()
{
    WSABUF wsaBuff[2];
    wsaBuff[0].len = 20;
    wsaBuff[1].len = 25;
    WSASend(sock, &wsaBuff[0], 2, ......);
}

When I get the "write_done" notification from the completion port, is it possible that wsaBuff[1] will be sent completely (25 bytes) yet wsaBuff[0] will be only partially sent (say 7 bytes)?

Was it helpful?

Solution

As WSASend is the preferred way of doing overlapped socket IO, it would not make any sense if it completed while incomplete - the completion notification/routine/event is the only way for the application to cleanup/recycle the used structures.

Also: NO, it's not possible, a single WSASend call is still a single IO call, regardless of the buffers used.

OTHER TIPS

As I've said before, in a reply to one of your other very similar questions, the only time this is likely to fail is in low resource situations (non-paged pool or locked pages limit issues most likely) where you might get a partial completion and an error return of ENOBUFS. And again, as I've said before, in 10 years of IOCP development work I've never seen this as a problem in production, only in situations where we have been stress testing a system to death (quite literally sometimes as non-paged pool exhaustion can sometimes cause badly behaved drivers to blue screen the box).

I would suggest that you simply add some code to log the failure, close the socket and that's it, you've dealt with the possibility of the failure and can move on. I'd be surprised if your failure handling code is ever executed. But you can be confident that you'll know if it is and once you can reproduce the issue you can spend more time thinking about if you really need to handle it any better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top