Search code examples
c++socketswinsockiocpoverlapped-io

Should WSASocket() be used with IOCP?


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?


Solution

  • 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.