简体   繁体   English

WSASocket()应该与IOCP一起使用吗?

[英]Should WSASocket() be used with IOCP?

I know that it is recommended to use WSAAccept() instead of accept() when creating an IOCP application. 我知道在创建IOCP应用程序时,建议使用WSAAccept()而不是accept() But I am not sure if WSASocket() belongs to the Overlapped I/O functions, or is it just another Winsock function? 但我不确定WSASocket()属于重叠I / O函数,还是只是另一个Winsock函数?

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. 我一直认为你可以通过查看socket()WSASocket()的MSDN文档来回答这个问题,特别是你不能使用socket创建一个可以与重叠I / O(和IOCP)一起使用的socket()因为只有WSASocket()允许您在创建套接字时指定WSA_FLAG_OVERLAPPED标志。 But that's incorrect as socket() creates sockets that have WSA_FLAG_OVERLAPPED set. 但这是不正确的,因为socket()创建了设置了WSA_FLAG_OVERLAPPED套接字。

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. 但是,一般来说,Windows中的berkeley / POSIX套接字函数只是为了方便那些想要编程到该API的人。 There's very little reason to use them and the native Windows APIs should be preferred. 使用它们的理由很少,应该首选本机Windows API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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