User login

glibcurl

This page is for programmers who want to use libcurl (a library for performing HTTP/FTP downloads) in their glib program. glib is used by the GTK+ library, and thus by all GTK applications.

This is a by-product of my work on jigdo. Currently, the code is tested and known to work under Linux and Windows.

What is glibcurl?

glibcurl consists of a small amount of C code which you can include in your program. It integrates the event loops of libcurl and glib. This means that a GTK+ program is able to wait for clicks, button presses etc. at the same time as waiting for data to arrive on the network sockets maintained by libcurl.

glibcurl could be turned into a library, but for the time being I think it is much easier for people to include it directly in their own code. It is released under a very liberal MIT/BSD-style license which makes inclusion possible for GPL-licensed and even for commercial programs.

Why is glibcurl useful?

libcurl is a thread-safe library, allowing you to start several downloads in separate threads in your GTK+/Gnome application - so why should you use something like glibcurl instead?

In my opinion, glibcurl is preferable over multiple curl-easy threads because then writing your GTK+ program will be a lot easier. With several threads, your code needs to include many additional calls to glib functions for synchronisation. For example, a mutex will be necessary if you want to display a progress bar while a download is performed.

However, when using glibcurl, you can directly update the GTK+ widgets from the curl callback function, since glibcurl causes the call to curl_multi_perform() (and thus to your callback) to happen from within the libgtk main loop, in the same way that GTK+ callbacks for button presses etc. are called.

(Under Windows, glibcurl internally uses a separate thread to wait for data arriving on network sockets, but this is hidden from the code using glibcurl - everything behaves identically under Linux and Windows.)

By the way, the name "glibcurl" is inspired by "glibwww", which does much the same thing for the libwww library.