Re: WSAEnumProtocols call

Frediano Ziglio <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
2009/2/11 James K. Lowden <[email protected]>:
> Frediano Ziglio wrote:
>> I don't understand why we call WSAEnumProtocols in
>> winsock_initialized. I never used this function but I can guarantee
>> that WSAStartup is sufficient.
>
> I was looking for a safe way to answer this question: Has winsock been
> initialized?
>
> I'm not sure what the effect is of calling WSAStartup twice.  There isn't
> any documented error from WSAStartup that means, "hey, dummy, you already
> called WSAStartup and I'm initialized already!".
>
> I thought it was safer to call WSAEnumProtocols to discover if winsock is
> not initialized.  It must be cheap; it's only returning its configuration
> data.  And it returns a very clear answer as to whether or not winsock is
> working.
>

Oh... no, you can initialize with WSAStartup as many time you want.
Personally I never call WSACleanup and usually I call WSAStartup in
main (or similar). A variable winsock_initialized (true/false) is
usually sufficient. I realize it cause trying to cross compile FreeTDS
linker didn't find WSAEnumProtocols (in ws2_32 but not in wsock32...
perhaps I should link directly to ws2_32, wsock32 is ancien).

freddy77
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.