Source
zbx_asynchttppoller_config *asynchttppoller_config = zbx_malloc(NULL ,sizeof(zbx_asynchttppoller_config));
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
typedef struct
{
struct event *event;
curl_socket_t sockfd;
zbx_asynchttppoller_config *asynchttppoller_config;
}
zbx_curl_context_t;
static int start_timeout(CURLM *multi, long timeout_ms, void *userp)
{
zbx_asynchttppoller_config *asynchttppoller_config = (zbx_asynchttppoller_config *)userp;
zabbix_log(LOG_LEVEL_DEBUG, "%s() timeout:%ld", __func__, timeout_ms);
ZBX_UNUSED(multi);
if(0 > timeout_ms)
{
evtimer_del(asynchttppoller_config->curl_timeout);
}
else
{
struct timeval tv;
if(0 == timeout_ms)
timeout_ms = 1; /* 0 means directly call socket_action, but we will do it in a bit */
tv.tv_sec = timeout_ms / 1000;
tv.tv_usec = (timeout_ms % 1000) * 1000;
evtimer_del(asynchttppoller_config->curl_timeout);
evtimer_add(asynchttppoller_config->curl_timeout, &tv);
}
return 0;
}
static void check_multi_info(zbx_asynchttppoller_config *asynchttppoller_config)
{
CURLMsg *message;
int pending;
while (NULL != (message = curl_multi_info_read(asynchttppoller_config->curl_handle, &pending)))
{
zabbix_log(LOG_LEVEL_DEBUG, "pending cURL messages:%d", pending);
switch (message->msg)
{
case CURLMSG_DONE:
asynchttppoller_config->process_httpagent_result(message->easy_handle,
message->data.result, asynchttppoller_config->http_agent_arg);
break;
case CURLMSG_NONE:
case CURLMSG_LAST:
default:
zabbix_log(LOG_LEVEL_DEBUG, "curl message:%u", message->msg);
break;
}
}
}
static void on_timeout(evutil_socket_t fd, short events, void *arg)
{
int running_handles;
zbx_asynchttppoller_config *asynchttppoller_config = (zbx_asynchttppoller_config *)arg;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
ZBX_UNUSED(fd);
ZBX_UNUSED(events);
if (NULL != asynchttppoller_config->http_agent_action)
asynchttppoller_config->http_agent_action(asynchttppoller_config->http_agent_arg);