I'm using SetFileCompletionNotificationModes()
API to optimize my I/O completion ports loops, but it seems to not work properly.
Even if I set FILE_SKIP_COMPLETION_PORT_ON_SUCCESS for sockets and HANDLEs, an I/O port's completion callback is still called also if ReadFile()
WriteFile()
WSARecv()
WSASend()
do return synchronosly.
I'm sure that the 3 conditions that MSDN says must be true (A completion port is associated with the file handle, The file is opened for asynchronous I/O, A request returns success immediately without returning ERROR_PENDING) are met, and are all true, so why I still receive I/O completion calls?
When i call SetFileCompletionNotificationModes()
it returns success, so no errors or whatsoever, and the system is Windows 7.
How I can replicate a scenario when after I have activated SetFileCompletionNotificationModes()
on my socket/HANDLEs, I can clearly see that the I/O completion callback won't be called?
I guessed that it happens when I write few bytes on a socket, since the socket's buffer is quite bigger, I didn't full it, so another write of another few bytes shouldn't block, since there are still a lot of room in the buffer, so it should return immediately, but not with ERROR_IO_PENDING, just in a synchronous way, right? (more or less, in a similar way of unix EWOULDBLOCK/EAGAIN: when i call write()
for few bytes it returns immediately, and doesn't return EAGAIN, because there is still space in the write buffer).
Well it doesn't do that. Even for writing multiple times few bytes on a socket, it still calls the I/O completion callback, avoding the benefits of setting FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
Am I missing something important? Any clue about that?
NOTE: I know that this wont work if the socket is only compatible with Layered Service Providers (LSP) that return Installable File Systems (IFS) handles, but that's not my case, it should work. Btw I'm trying this also with pipes and files.
Shouldn't files never call I/O completion callbacks because they never block, just like in unix read()
and write()
calls on local files never returns EWOULDBLOCK/EAGAIN, so ReadFile()
and WriteFile()
with an handle set with FILE_SKIP_COMPLETION_PORT_ON_SUCCESS should return immediately?