简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM