add libcurl basic example
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <alsa/control.h>
|
||||
#include <alsa/pcm.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
// NOTE: find this via `arecord -l`
|
||||
#define ALSA_MIC_HARDWARE_DEVICE "hw:3"
|
||||
@@ -13,6 +14,32 @@ void print_pcm_state(snd_pcm_t *pcm_handle) {
|
||||
printf("State of pcm handle: %s\n", state_name);
|
||||
}
|
||||
|
||||
size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
|
||||
size_t total_size = size * nmemb;
|
||||
printf("%.*s", (int)total_size, (char*)contents);
|
||||
return total_size;
|
||||
}
|
||||
|
||||
void test_request() {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
curl = curl_easy_init();
|
||||
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com");
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
fprintf(stderr, "curl failed: %s\n", curl_easy_strerror(res));
|
||||
return;
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
snd_pcm_t *pcm_handle = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user