#ifndef ZABBIX_ZBXCOMMS_H
#define ZABBIX_ZBXCOMMS_H
#include "zbxalgo.h"
#include "zbxtime.h"
#define ZBX_IPV4_MAX_CIDR_PREFIX 32
#define ZBX_IPV6_MAX_CIDR_PREFIX 128
#ifdef _WINDOWS
# define zbx_socket_last_error() WSAGetLastError()
# define ZBX_PROTO_ERROR SOCKET_ERROR
# define ZBX_SOCKET_TO_INT(s) ((int)(s))
#else
# define zbx_socket_last_error() errno
# define ZBX_PROTO_ERROR -1
# define ZBX_SOCKET_TO_INT(s) (s)
#endif
#ifdef _WINDOWS
# if !defined(POLLIN)
# define POLLIN 0x001
# endif
# if !defined(POLLPRI)
# define POLLPRI 0x002
# endif
# if !defined(POLLOUT)
# define POLLOUT 0x004
# endif
# if !defined(POLLERR)
# define POLLERR 0x008
# endif
# if !defined(POLLHUP)
# define POLLHUP 0x010
# endif
# if !defined(POLLNVAL)
# define POLLNVAL 0x020
# endif
# if !defined(POLLRDNORM)
# define POLLRDNORM 0x040
# endif
# if !defined(POLLWRNORM)
# define POLLWRNORM 0x100
# endif
typedef struct
{
SOCKET fd;
short events;
short revents;
}
zbx_pollfd_t;
int zbx_socket_poll(zbx_pollfd_t* fds, unsigned long fds_num, int timeout);
#else
# define zbx_socket_poll(x, y, z) poll(x, y, z)
typedef struct pollfd zbx_pollfd_t;
#endif
void zbx_tcp_init_hints(struct addrinfo *hints, int socktype, int flags);
int zbx_socket_had_nonblocking_error(void);
#ifdef _WINDOWS
typedef SOCKET ZBX_SOCKET;
#else
typedef int ZBX_SOCKET;