I'm writing a network-related module for a larger project. It's cross-platform, and the Windows implementation uses Winsock2.

I'm having some trouble figuring out the best way to handle the need to call WSAStartup()/WSACleanup(). If these things were reference-counted in some way, then the correct thing would be obvious; just make sure to call WSAStartup() in my object's constructor and WSACleanup() in the destructor. However, they aren't as far as I can tell, which makes calling WSACleanup() at any time perilous. An unrelated part of the code might also be trying to use sockets, and I don't want to rip them out from under it! I'm guessing, but I'm not certain, that calling WSAStartup() multiple times does no harm.

Any tips on best practices here?