Hello everyone,
I'm currently working on a project where I am using WinSock to create both UDP and TCP sockets. The sockets are set in non-blocking mode using ioctl, and I am using overlapped operations with an I/O Completion Port (IOCP) to handle asynchronous network communication.
The Scenario:
I use WSASendTo
for UDP and WSASend
for TCP to send data. These operations are performed asynchronously, and I expect to receive callbacks on the IOCP once the operations are completed. However, I have encountered a situation where I still get a call back on the IOCP even if the operation completes synchronously which is as per documented behavior.
I came across the API function SetFileCompletionNotificationModes
, which can be used to set specific modes for I/O completion notifications. One of the options for SetFileCompletionNotificationModes
is the FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
flag, which, according to the documentation, prevents IOCP callbacks for operations that complete synchronously.
My Questions are:
- Is it always true that using
FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
with SetFileCompletionNotificationModes
will prevent callbacks from the IOCP on successful synchronous completion of WSASendTo
/WSASend
operations? Does it guarantee no callback when an operation completes synchronously?
- Is this the recommended way to handle synchronous completions? Should I rely on this API to avoid unnecessary IOCP callbacks, or is there a better or more standard way to manage this behavior?
I would appreciate any insights or recommendations from those who have experience with IOCP and WinSock, especially regarding how to best optimize this scenario and avoid redundant callbacks when operations complete synchronously.
Thanks in advance!