views:

30

answers:

2

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)?

A: 

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.

Viktor Svub
A: 

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.

Len Holgate
Are you sure Len? Pay careful attention to this specific question - it's a single WSASend() call and not several, thus I'd expect it to treat the WSABUF array as a single, continuous, buffer... and that's my question is actually all about.
Poni
If you have set the socket's send buffer size to zero then YOUR buffers will be locked in memory and so could cause an ENOBUFS return if the locked pages limit is exceeded, likewise neither of us are privy to the exact non-paged pool usage for this situation. The fact that you're using scatter/gather I/O is not, IMHO actually that relevant.Also, since the documentation to WSASend() doesn't say that this situation cannot cause the error that you're asking about you have to assume that it CAN occur and therefore, IMHO, my answer stands.
Len Holgate