CURLSHOPT_LOCKFUNC(3)
π CURLSHOPT_LOCKFUNC(3) β like, the mutex lock callback one, bestie
okay so real talk: this is a page from Library Functions Manual (that's the manual name, you're welcome β¨) and it's all about CURLSHOPT_LOCKFUNC β the lock callback your share object needs when you're out here living that multithreaded life. π§΅π
πΈ NAME πΈ
CURLSHOPT_LOCKFUNC β the mutex lock callback, periodt π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
void lockcb(CURL *handle, curl_lock_data data, curl_lock_access access,
void *clientp);
CURLSHcode curl_share_setopt(CURLSH *share, CURLSHOPT_LOCKFUNC, lockcb);
π¦ DESCRIPTION π¦
So you're setting a mutex lock callback on the share object β the whole point is to let that share object get used by multiple threads at the same time without everything going feral. π₯ And heads up: there's a matching CURLSHOPT_UNLOCKFUNC(3) callback that gets called when the mutex is released again, so likeβ¦ they're a pair, iykyk. π«Ά
The lockcb argument must be a pointer to a function that matches the prototype shown up there β¬οΈ exactly. No improvising, bestie. And here's what the callback gets handed:
handleβ this is the currently active easy handle in use when the share object is intended to get used. main character energy, honestly πdataβ tells you what kind of data libcurl wants to lock. And fr fr: make sure your callback uses a different lock for each kind of data. Not me stressing this. Okay maybe me stressing this. πaccessβ defines what access type libcurl wants βsharedorsingle. pick your vibe π«clientpβ the private pointer you set withCURLSHOPT_USERDATA(3). libcurl itself does not use this pointer, it's all yours, do whatever π
π PROTOCOLS π
This functionality affects all supported protocols β every single one, no cap πβ¨
π EXAMPLE π
extern void mutex_lock(CURL *handle, curl_lock_data data,
curl_lock_access access, void *clientp);
int main(void)
{
CURLSHcode sh;
CURLSH *share = curl_share_init();
sh = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, mutex_lock);
if(sh)
printf("Error: %s\n", curl_share_strerror(sh));
}
look at her go π§ she's iconic, she's setting the lock function, she's even handling the error like a responsible queen π
β AVAILABILITY β
Added in curl 7.10.3 β vintage, but make it cute π
π RETURN VALUE π
CURLSHE_OK (zero) means the option was set properly π β non-zero means an error occurred π. Peep libcurl-errors(3) for the full list with descriptions if you wanna know exactly what went wrong.
no cap: zero = slay, non-zero = go read the error page, bestie π«Ά
π₯ SEE ALSO π₯
okay that's the whole page, you ate that π β¨ this lil masterpiece is brought to you by libcurl, dated 2026-10-12 β mwah, go forth and lock your mutexes responsibly, bestie π¦π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms