[freetds] WSAEnumProtocols call

Frediano Ziglio freddy77 at gmail.com
Wed Feb 11 09:45:04 EST 2009


2009/2/11 James K. Lowden <jklowden at freetds.org>:
> 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



More information about the FreeTDS mailing list