libcurl
libcurl is a C library for transferring data over URLs (HTTP, FTP, SMTP, and more). It’s the engine behind the curl command and ships with bindings for most languages. From ECE459 L05.
Why two interfaces?
A single blocking request is easy to reason about. But a crawler or API gateway wants to fan out thousands of requests without one slow server stalling the rest. libcurl offers two shapes for the two use cases.
Easy interface. Synchronous, one request at a time:
curl_easy_init()creates a handlecurl_easy_setopt()configures it (URL, headers, callbacks)curl_easy_perform()blocks until the transfer finishescurl_easy_cleanup()frees the handle
Multi interface. Asynchronous, many requests in flight on one thread:
curl_multi_init()creates a multi handle- Add many easy handles with
curl_multi_add_handle() curl_multi_perform()drives all active transfers without blockingcurl_multi_wait()parks until at least one handle has work
When to reach for multi
Any time you’d otherwise spawn a thread per outbound request. One multi handle can manage thousands of connections with a single OS thread, avoiding per-thread stack overhead and race conditions.