Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSAConnect() vs ConnectEx()

I am using IOCP in my client, but I find it more convenient to use a blocking call when connecting to the server. So is there any problem in using the blocking WSAConnect() instead of the non-blocking ConnectEx() when working with IOCP?

like image 222
user6088487 Avatar asked Mar 22 '16 08:03

user6088487


1 Answers

Yes, it's perfectly fine.
a call to WSAConnect will block the thread until a connection has being created/ an error has occured. then, you can do asynchronous IO and get notification about completed packets with your application IOCP. the IOCP will not give any packets regarding WSAConnect.

Another point is that IOCP works exculsivly with Overlapped IO. if your function does not consume any memory location of OVERLAPPED struct (like WSAConnect), you can be sure that IOCP will not deal with that API call. even if OVERLAPPED supplied, that doesn't mean that the action is asynchronous and will be published in the IOCP.

you might want to take a look at Boost.Asio for C++ and libuv for C. the code then will be portable as well (and less buggish). another intresting platform is microsoft Casablanca, which is cross platform, but in my experince the performance is catastrophic.

like image 69
David Haim Avatar answered Oct 15 '22 13:10

David Haim