1#if !defined(__MQTT_PAL_H__)
28#if defined(__cplusplus)
36#if defined(__unix__) || defined(__APPLE__) || defined(__NuttX__)
41 #include <arpa/inet.h>
44 #define MQTT_PAL_HTONS(s) htons(s)
45 #define MQTT_PAL_NTOHS(s) ntohs(s)
47 #define MQTT_PAL_TIME() time(NULL)
49 typedef time_t mqtt_pal_time_t;
50 typedef pthread_mutex_t mqtt_pal_mutex_t;
52 #define MQTT_PAL_MUTEX_INIT(mtx_ptr) pthread_mutex_init(mtx_ptr, NULL)
53 #define MQTT_PAL_MUTEX_LOCK(mtx_ptr) pthread_mutex_lock(mtx_ptr)
54 #define MQTT_PAL_MUTEX_UNLOCK(mtx_ptr) pthread_mutex_unlock(mtx_ptr)
56 #if !defined(MQTT_USE_CUSTOM_SOCKET_HANDLE)
57 #if defined(MQTT_USE_MBEDTLS)
58 struct mbedtls_ssl_context;
59 typedef struct mbedtls_ssl_context *mqtt_pal_socket_handle;
60 #elif defined(MQTT_USE_WOLFSSL)
61 #include <wolfssl/ssl.h>
62 typedef WOLFSSL* mqtt_pal_socket_handle;
63 #elif defined(MQTT_USE_BIO)
64 #include <openssl/bio.h>
65 typedef BIO* mqtt_pal_socket_handle;
66 #elif defined(MQTT_USE_BEARSSL)
69 typedef struct _bearssl_context {
70 br_ssl_client_context sc;
71 br_x509_minimal_context xc;
74 br_x509_trust_anchor *anchOut;
76 int (*low_read)(
void *read_context,
unsigned char *buf,
size_t len);
77 int (*low_write)(
void *write_context,
const unsigned char *buf,
size_t len);
80 typedef bearssl_context* mqtt_pal_socket_handle;
82 typedef int mqtt_pal_socket_handle;
85#elif defined(_MSC_VER) || defined(WIN32)
92 typedef SSIZE_T ssize_t;
93 #define MQTT_PAL_HTONS(s) htons(s)
94 #define MQTT_PAL_NTOHS(s) ntohs(s)
96 #define MQTT_PAL_TIME() time(NULL)
98 typedef time_t mqtt_pal_time_t;
99 typedef CRITICAL_SECTION mqtt_pal_mutex_t;
101 #define MQTT_PAL_MUTEX_INIT(mtx_ptr) InitializeCriticalSection(mtx_ptr)
102 #define MQTT_PAL_MUTEX_LOCK(mtx_ptr) EnterCriticalSection(mtx_ptr)
103 #define MQTT_PAL_MUTEX_UNLOCK(mtx_ptr) LeaveCriticalSection(mtx_ptr)
106 #if !defined(MQTT_USE_CUSTOM_SOCKET_HANDLE)
107 #if defined(MQTT_USE_BIO)
108 #include <openssl/bio.h>
109 typedef BIO* mqtt_pal_socket_handle;
111 typedef SOCKET mqtt_pal_socket_handle;
118ssize_t
mqtt_pal_sendall(mqtt_pal_socket_handle fd,
const void* buf,
size_t len,
int flags);
123#if defined(__cplusplus)
ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void *buf, size_t bufsz, int flags)
ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void *buf, size_t len, int flags)
UNIX-like platform support.