What is the cost of WSAStartup and WSACleanup?

I have a C ++ win32 program that uses sockets to load some data from a server.

Before using sockets on Windows, WSAStartup is called. MSDN says: "There must be a WSACleanup call for every successful WSAStartup call. Only the final call to the WSACleanup function does the actual cleanup."

The easiest way for me is to call WSAStartup / WSACleanup every time I load the data world from the server. In most cases, there will only be one connection at a time, so WSACleanup will actually perform the cleanup.

That's why I wonder what the cost of WSAStartup and WSACleanup are? I want to do the actual cleanup. If the WSAStartup and WSACleanup calls are made in a short time compared to the entire socket connection, I can use a simple method. If not, I should only take care of calling WSACleanup when I exit the program.

+7
winapi sockets tcp wsastartup
source share
3 answers

WSAStartup () loads the necessary DLLs. But if the DLL is already loaded, WSAStartup () just increments the counter. WSACleanup () decreases the counter and frees the dll after the counter reaches zero.

You must call WSAStartup () in the init function of your application and WSACleanup () before exiting the application.

+12
source share

Use RAII to download them only once when the application starts, and then release them on exit ...

+3
source share

Just call WSAStartup once and never clean. Seriously, this is a kind of piece of the remaining architecture from Win3.1 and Win32.

+2
source share

All Articles