WSAConnect () vs ConnectEx ()

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

+5
source share
1 answer

Yes, that's great.
a WSAConnect call will block the thread until a connection is made / an error has occurred. then you can do asynchronous I / O and get notified of completed packages with your IOCP application. IOCP will not forward any packets regarding WSAConnect .

Another point is that IOCP works exclusively with Overlapped IO. if your function does not consume OVERLAPPED struct memory OVERLAPPED (e.g. WSAConnect ), you can be sure that IOCP will not deal with this API call. even if OVERLAPPED supplied, this does not mean that the action is asynchronous and will be published in IOCP.

you can take a look at Boost.Asio for C ++ and libuv for C. The code will also be portable (and less complicated). another interesting platform is microsoft Casablanca , which is cross-platform, but in my experience, performance is disastrous.

+4
source

Source: https://habr.com/ru/post/1245532/


All Articles