examples: omit forward declarations, apply misc fixes

- reorder functions to not need forward declarations.
- sync `ephiperfifo.c` and `evhiperfifo.c`.
- drop redundant casts for `calloc()` return value.
- ephiperfifo: silence unused variable warning.
- fix indent and apply clang-format more.

Closes #20296
This commit is contained in:
Viktor Szakats 2026-01-13 18:17:42 +01:00
parent df246eeb8f
commit 8680a07589
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
6 changed files with 158 additions and 161 deletions

View file

@ -41,50 +41,6 @@ struct curl_context {
curl_socket_t sockfd;
};
static void curl_perform(int fd, short event, void *arg);
static struct curl_context *create_curl_context(curl_socket_t sockfd)
{
struct curl_context *context;
context = (struct curl_context *)malloc(sizeof(*context));
context->sockfd = sockfd;
context->event = event_new(base, sockfd, 0, curl_perform, context);
return context;
}
static void destroy_curl_context(struct curl_context *context)
{
event_del(context->event);
event_free(context->event);
free(context);
}
static void add_download(const char *url, int num)
{
char filename[50];
FILE *file;
CURL *curl;
snprintf(filename, sizeof(filename), "%d.download", num);
file = fopen(filename, "wb");
if(!file) {
fprintf(stderr, "Error opening %s\n", filename);
return;
}
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
curl_easy_setopt(curl, CURLOPT_PRIVATE, file);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_multi_add_handle(multi, curl);
fprintf(stderr, "Added download %s -> %s\n", url, filename);
}
static void check_multi_info(void)
{
char *done_url;
@ -141,6 +97,48 @@ static void curl_perform(int fd, short event, void *arg)
check_multi_info();
}
static struct curl_context *create_curl_context(curl_socket_t sockfd)
{
struct curl_context *context;
context = (struct curl_context *)malloc(sizeof(*context));
context->sockfd = sockfd;
context->event = event_new(base, sockfd, 0, curl_perform, context);
return context;
}
static void destroy_curl_context(struct curl_context *context)
{
event_del(context->event);
event_free(context->event);
free(context);
}
static void add_download(const char *url, int num)
{
char filename[50];
FILE *file;
CURL *curl;
snprintf(filename, sizeof(filename), "%d.download", num);
file = fopen(filename, "wb");
if(!file) {
fprintf(stderr, "Error opening %s\n", filename);
return;
}
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
curl_easy_setopt(curl, CURLOPT_PRIVATE, file);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_multi_add_handle(multi, curl);
fprintf(stderr, "Added download %s -> %s\n", url, filename);
}
static void on_timeout(evutil_socket_t fd, short events, void *arg)
{
int running_handles;