1

I know that it is recommended to use WSAAccept() instead of accept() when creating an IOCP application. But I am not sure if WSASocket() belongs to the Overlapped I/O functions, or is it just another Winsock function?

1 Answers1

3

I always thought that you could answer this question by looking at the MSDN docs for socket() and WSASocket() and, specifically that you couldn't create a socket that can be used with overlapped I/O (and IOCPs) using socket() as only WSASocket() allows you to specify the WSA_FLAG_OVERLAPPED flag when you create the socket. But that's incorrect as socket() creates sockets that have WSA_FLAG_OVERLAPPED set.

However, in general the berkeley/POSIX sockets functions in Windows are just there as a convenience to people who want to program to that API. There's very little reason to use them and the native Windows APIs should be preferred.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
  • 5
    Actually, the documentation for `socket()` says: "The socket that is created will have the overlapped attribute as a default". –  Mar 09 '15 at 18:30
  • Does it. I've never noticed that. Thanks for telling me! I've adjusted the answer – Len Holgate Mar 09 '15 at 20:51
  • So there is no such thing as functions that only belongs to Overlapped I/O, but rather there are the `WSAxxx()` functions which can be used for Overlapped I/O, but can also be used for non Overlapped I/O. And there are the berkeley/POSIX functions which do not support Overlapped I/O. Is my assumption correct? –  Mar 09 '15 at 21:59
  • A socket needs to be created with the correct flag set to be usable with overlapped I/O functions in a way that results in overlapped I/O occurring. You can create a socket without the overlapped flag and pass it to WSASend() and use it for a synchronous, non overlapped send. Equally you can pass a socket WITH the overlapped flag set to WSASend() and also request a synchronous send rather than an overlapped send. What you can't do is pass a socket without the flag set and request an overlapped send. The POSIX functions do not support overlapped I/O and IOCP as these are Windows only concepts. – Len Holgate Mar 09 '15 at 22:18