MQTT-C: include/mqtt_pal.h Source File

MQTT-C

mqtt_pal.h
Go to the documentation of this file.
1 #ifndef __MQTT_PAL_H__
2 #define __MQTT_PAL_H__
3
4 /*
5 MIT License
6
7 Copyright(c) 2018 Liam Bindle
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files(the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions :
15
16 The above copyright notice and this permission notice shall be included in all
17 copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 SOFTWARE.
26 */
27
67 /* UNIX-like platform support */
68 #ifdef __unix__
69 #include <limits.h>
70 #include <string.h>
71 #include <stdarg.h>
72 #include <time.h>
73 #include <arpa/inet.h>
74 #include <pthread.h>
75
76 #define MQTT_PAL_HTONS(s) htons(s)
77 #define MQTT_PAL_NTOHS(s) ntohs(s)
78
79 #define MQTT_PAL_TIME() time(NULL)
80
81 typedef time_t mqtt_pal_time_t;
82 typedef pthread_mutex_t mqtt_pal_mutex_t;
83
84 #define MQTT_PAL_MUTEX_INIT(mtx_ptr) pthread_mutex_init(mtx_ptr, NULL)
85 #define MQTT_PAL_MUTEX_LOCK(mtx_ptr) pthread_mutex_lock(mtx_ptr)
86 #define MQTT_PAL_MUTEX_UNLOCK(mtx_ptr) pthread_mutex_unlock(mtx_ptr)
87
88 #ifndef MQTT_USE_CUSTOM_SOCKET_HANDLE
89 #ifdef MQTT_USE_BIO
90 #include <openssl/bio.h>
91 typedef BIO* mqtt_pal_socket_handle;
92 #else
93 typedef int mqtt_pal_socket_handle;
94 #endif
95 #endif
96 #endif
97
109 ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len, int flags);
110
122 ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int flags);
123
124 #endif
mqtt_pal_sendall
ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void *buf, size_t len, int flags)
Sends all the bytes in a buffer.
mqtt_pal_recvall
ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void *buf, size_t bufsz, int flags)
Non-blocking receive all the byte available.