#include "zbxcommon.h"
#ifdef HAVE_IPCSERVICE
#ifdef HAVE_LIBEVENT
# include <event2/event.h>
# include <event2/thread.h>
# include <event2/util.h>
#endif
#include "zbxipcservice.h"
#include "zbxalgo.h"
#include "zbxstr.h"
#define ZBX_IPC_PATH_MAX sizeof(((struct sockaddr_un *)0)->sun_path)
#define ZBX_IPC_DATA_DUMP_SIZE 128
static char ipc_path[ZBX_IPC_PATH_MAX] = {0};
static size_t ipc_path_root_len = 0;
#define ZBX_IPC_CLIENT_STATE_NONE 0
#define ZBX_IPC_CLIENT_STATE_QUEUED 1
#define ZBX_IPC_ASYNC_SOCKET_STATE_NONE 0
#define ZBX_IPC_ASYNC_SOCKET_STATE_TIMEOUT 1
#define ZBX_IPC_ASYNC_SOCKET_STATE_ERROR 2
struct zbx_ipc_client
{
zbx_ipc_socket_t csocket;
zbx_ipc_service_t *service;
zbx_uint32_t rx_header[2];
unsigned char *rx_data;
zbx_uint32_t rx_bytes;
zbx_queue_ptr_t rx_queue;
struct event *rx_event;
zbx_uint32_t tx_header[2];
unsigned char *tx_data;
zbx_uint32_t tx_bytes;
zbx_queue_ptr_t tx_queue;
struct event *tx_event;
zbx_uint64_t id;
unsigned char state;
void *userdata;
zbx_uint32_t refcount;
};
ZBX_PTR_VECTOR_IMPL(ipc_client_ptr, zbx_ipc_client_t *)
#define ZBX_IPC_HEADER_SIZE (int)(sizeof(zbx_uint32_t) * 2)
#define ZBX_IPC_MESSAGE_CODE 0
#define ZBX_IPC_MESSAGE_SIZE 1
#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x2000000
typedef int evutil_socket_t;
static struct event *event_new(struct event_base *ev, evutil_socket_t fd, short what,
void(*cb_func)(int, short, void *), void *cb_arg)
{
struct event *event;
event = zbx_malloc(NULL, sizeof(struct event));
event_set(event, fd, what, cb_func, cb_arg);
event_base_set(ev, event);