Skater
catgrill Meidos IS NOT A CRIME! :^)
note: sadly, we've scraped our barrel of catgrill meidos, so time to move on to just the meidos I suppose
provide neko ears and tail using your imagination please Anon
For this drop we've moved over to libcurl alone. Curl really is the single best open-sauce networking library out there I'd say, hands-down. Beautiful C code, and it has a cool origins story. It's used in many billions of devices today; it certainly has industrial-scale use. It's clearly our safest bet for networking IMO.
===
From last drop, you remember we had a callback function. Now let's have a look at the caller function that uses that. First, we'll look at everything all together at once and then we'll break it all down one step at a time.
>dolldrop.cpp snippet
/** Assign curl easy options for a new @c curl handle, adding it into a @c
* curl-multi handle
*
* @param[out] multi_hdl the multi hdl that receives the new curl easy hdl
* @param[in] uri the associated uri for this easy hdl
* @param[in] hdr the target string to receive header data
*/
void cfg_hdr_hdl(CURLM* const multi_hdl,
std::string const& uri,
std::string const& hdr) {
auto curl_hdl = curl_easy_init();
curl_easy_setopt(curl_hdl, CURLOPT_WRITEFUNCTION, wrt_str_cb);
curl_easy_setopt(curl_hdl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curl_hdl, CURLOPT_HEADERDATA, &hdr);
curl_easy_setopt(curl_hdl, CURLOPT_USERAGENT, "Bumpmaster_v220604");
curl_easy_setopt(curl_hdl, CURLOPT_URL, uri.c_str());
curl_easy_setopt(curl_hdl, CURLOPT_FOLLOWLOCATION, 1L);
curl_multi_add_handle(multi_hdl, curl_hdl);
}
That first parm is a
curl multi handle. From the docs[a]:
>"With a multi handle and the multi interface you can do several simultaneous transfers in parallel. Each single transfer is built up around an easy handle. You create all the easy handles you need, and setup the appropriate options for each easy handle using curl_easy_setopt."
So, this function is called repeatedly from within a loop at the caller, and a brand new
curl easy handle[b] is created here each time through, it's options are set[c], and it is then added (attached) to the
multi_hdl parm. This is all just preliminary configuration, and once that loop in the caller completes then the downloads proper begin in parallel.
So, the function's statements in order:
auto curl_hdl = curl_easy_init();
-create a curl easy object[1]
curl_easy_setopt(curl_hdl, CURLOPT_WRITEFUNCTION, wrt_str_cb);
-specify our previous callback code[2]
curl_easy_setopt(curl_hdl, CURLOPT_NOBODY, 1L);
-don't download the request's body (just header)[3]
curl_easy_setopt(curl_hdl, CURLOPT_HEADERDATA, &hdr);
-this is the string pointer to use at callback[4]
curl_easy_setopt(curl_hdl, CURLOPT_USERAGENT, "Bumpmaster_v220604");
-Set the user-agent. Servers can see this and know what software is making the request. The version just tracks the
RW Foundations library.[5]
curl_easy_setopt(curl_hdl, CURLOPT_URL, uri.c_str());
-URI to use for this transfer[6]
curl_easy_setopt(curl_hdl, CURLOPT_FOLLOWLOCATION, 1L);
-follow any redirects the server provides[7]
curl_multi_add_handle(multi_hdl, curl_hdl);
-finally, attach the easy handle into the multi handle[8]
That's it, we've walked down the entire code listing Anon. We hope it all makes sense what's going on here.
>tl;dr
A) create a curl easy object
B) set it's options
C) add it to a curl multi object
D) lather, rinse, repeat
We also began a new sublibrary for
RW Foundations this time:
RW Intuit. As Anon pointed out (
>>16515), a robowaifu's intuition is something that just comes 'naturally' to her, and operates
very fast. No 'thinking things through'. You can expect that when it's time comes, lots and lots of focus on time/space efficiencies will be invested in this library tbh.
Well, I hope things are going well for you Anon. Keep the prize in mind, pursue your robowaifu dreams earnestly and with vigor.
Onward noble Knight! :^)
Until next time then, cheers.
===
>version.log
v.220604
---------------
-begin Intuit; rw::atashi::cognate
-add wrt_strm_cb(), cfg_body_hdl() utility funcs; dolldrop
-add pull_bodies_multi_g(); dolldrop
-add pull_anon_body() call-chain; bumpmaster, dolldrop
-mv curl_global_init() call into preflight(); dolldrop
-add Json empty check in thrd_posts(); bumpmaster
-add missing function stamp() calls; bumpmaster, dolldrop
-rm all curlcpp-dependent functions; bumpmaster, dolldrop, dollnet
-rm all curlcpp lib calls; bumpmaster, dolldrop, dollnet
-fully rm curlcpp library dependency; meson.build
>rw_foundations-v220604.tar.xz.sha256sum
acab50c8cb3966fb6aeaf6fa79c472114728bea7fe4cd0e6b7fb06fac8984833 *rw_foundations-v220604.tar.xz
>backup drop
https://files.catbox.moe/y1ji9q.7z
===
1. curl_easy_init - Start a libcurl easy session
https://curl.se/libcurl/c/curl_easy_init.html
2. CURLOPT_WRITEFUNCTION - callback for writing received data
https://curl.se/libcurl/c/CURLOPT_WRITEFUNCTION.html
3. CURLOPT_NOBODY - do the download request without getting the body
https://curl.se/libcurl/c/CURLOPT_NOBODY.html
4. CURLOPT_HEADERDATA - pointer to pass to header callback
https://curl.se/libcurl/c/CURLOPT_HEADERDATA.html
5. CURLOPT_USERAGENT - HTTP user-agent header
https://curl.se/libcurl/c/CURLOPT_USERAGENT.html
6. CURLOPT_URL - URL for this transfer
https://curl.se/libcurl/c/CURLOPT_URL.html
7. CURLOPT_FOLLOWLOCATION - follow HTTP 3xx redirects
https://curl.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html
8. curl_multi_add_handle - add an easy handle to a multi session
https://curl.se/libcurl/c/curl_multi_add_handle.html
a. libcurl-multi - how to use the multi interface
https://curl.se/libcurl/c/libcurl-multi.html
b. libcurl-easy - easy interface overview
https://curl.se/libcurl/c/libcurl-easy.html
c. curl_easy_setopt - set options for a curl easy handle
https://curl.se/libcurl/c/curl_easy_setopt.html