Subject: Re: c-ares on windows - error 11

Re: c-ares on windows - error 11

From: <codemstr_at_ptd.net>
Date: 2005-06-18

"MagicalTux (admin)" <admin@FF.st> said:

> Right, WSAStartup wasn't called (I just added the resolver addon and
> tried to test it alone... guess it's my fault).
>
> Well, I guess WSAStartup should be called only once in a program...

Nope. The only rule is that you must call WSACleanup the same number of times
as WSAStartup was called. So if WSAStartup is called twice, you just call
WSACleanup twice. In fact there could be situations where you MUST call it
twice. Say your app uses version 1.0 of Winsocks whereas a library uses 2.0.
The library needs to call WSAStartup with MAKEWORD(2,0), you called it with
MAKEWORD(1,0) which won't give it the access it needs. As the MSDN says, if
you specify an old version and try to use functions from the new version,
they may be inaccessible.

The documentation specifically talks about calling WSAStartup multiple times
for the purposes of libraries (DLLs):
An application must call one WSACleanup call for every successful WSAStartup
call to allow third-party DLLs to make use of a WS2_32.DLL on behalf of an
application.

Note the part about third-party DLLs, that's exactly what the issue is here.

So basically, we can add WSAStartup to ares_init[_options] so long as we also
add WSACleanup to ares_destroy. I think that would make the code cleaner and
more portable. Unless someone can come up with a reason why this is a bad
idea?

Dominick Meglio

-- 
_______________________________________________
http://cool.haxx.se/mailman/listinfo/c-ares
Received on Sat Jun 18 01:59:13 2005