Source
zbx_asynchttppoller_config *asynchttppoller_config = zbx_malloc(NULL ,sizeof(zbx_asynchttppoller_config));
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
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__);