[mb-devel] libmusicbrainz3 testing

Matthias Friedrich matt at mafr.de
Sun Jul 23 16:27:01 UTC 2006


On Sunday, 2006-07-23, Tobias Rundström wrote:
> I wrote:

>> There's one thing about libcurl I always found annoying: You
>> have to call curl_global_init() before using the library and
>> curl_global_cleanup() afterwards. Both functions should be called
>> exactly once, so you can't do that in libmb3 (in case the application
>> or some other client library uses libcurl, too).

>> The only choice you have is to ask the user to call those functions
>> himself. Because of this, curl can't be a drop-in replacement for  
>> neon.

> This is not true. XMMS2 rely on curl for media streaming and I just  
> looked through that code. We don't call any global init functions and  
> our plugin works just great. So fortunately it seems that we can have  
> a drop-in-replacement.

I'd suggest you read libcurl's documentation. From the manpages:

| All applications that use libcurl should call curl_global_init(3)
| exactly once before any libcurl function can be used. After all
| usage of libcurl is complete, it must call curl_global_cleanup(3).

The reason why it works for you is documented, too:

| If this function hasn't been invoked when curl_easy_init(3) is
| called, it will be done automatically by libcurl.

In this case you have to hope that the library is initialized in a way
that works for you (or that a different library did it for you). This
may work now, but not necessarily in the future.

More from the docs:

| You must however always use the curl_global_cleanup(3) function, as
| that cannot be called automatically for you by libcurl.

So if you don't call curl_global_cleanup(), your plugin will leave a
resource leak behind because it doesn't release the resources it had
aquired. No idea how large, but it's bad style in any case.

At first, I also suggested using libcurl, but I think luks made a good
choice with libneon.

Matthias



More information about the MusicBrainz-devel mailing list