diff --git a/examples/aws/awsiot.c b/examples/aws/awsiot.c index 28d0b41..5f8d701 100644 --- a/examples/aws/awsiot.c +++ b/examples/aws/awsiot.c @@ -768,7 +768,6 @@ exit: /* so overall tests can pull in test function */ -#ifndef NO_MAIN_DRIVER #ifdef USE_WINDOWS_API #include /* for ctrl handler */ @@ -796,7 +795,11 @@ exit: } #endif +#ifdef NO_MAIN_DRIVER + int awsiot_main(int argc, char** argv) +#else int main(int argc, char** argv) +#endif /* NO_MAIN_DRIVER */ { int rc; #ifdef ENABLE_AWSIOT_EXAMPLE @@ -849,5 +852,3 @@ exit: return (rc == 0) ? 0 : EXIT_FAILURE; } - -#endif /* NO_MAIN_DRIVER */ diff --git a/examples/aws/awsiot.h b/examples/aws/awsiot.h index 090e8aa..75aa8ed 100644 --- a/examples/aws/awsiot.h +++ b/examples/aws/awsiot.h @@ -22,10 +22,22 @@ #ifndef WOLFMQTT_AWSIOT_H #define WOLFMQTT_AWSIOT_H +#ifdef __cplusplus +extern "C" { +#endif + #include "examples/mqttexample.h" /* Exposed functions */ int awsiot_test(MQTTCtx *mqttCtx); +#ifdef NO_MAIN_DRIVER +int awsiot_main(int argc, char** argv); +#endif + +#ifdef __cplusplus +} +#endif + #endif /* WOLFMQTT_AWSIOT_H */ diff --git a/examples/azure/azureiothub.h b/examples/azure/azureiothub.h index ef341a4..6c6aa81 100644 --- a/examples/azure/azureiothub.h +++ b/examples/azure/azureiothub.h @@ -22,10 +22,18 @@ #ifndef WOLFMQTT_AZUREIOTHUB_H #define WOLFMQTT_AZUREIOTHUB_H +#ifdef __cplusplus +extern "C" { +#endif + #include "examples/mqttexample.h" /* Exposed functions */ int azureiothub_test(MQTTCtx *mqttCtx); +#ifdef __cplusplus +} +#endif + #endif /* WOLFMQTT_AZUREIOTHUB_H */ diff --git a/examples/firmware/firmware.h b/examples/firmware/firmware.h index a98bf35..6154028 100644 --- a/examples/firmware/firmware.h +++ b/examples/firmware/firmware.h @@ -1,6 +1,30 @@ +/* firmware.h + * + * Copyright (C) 2006-2023 wolfSSL Inc. + * + * This file is part of wolfMQTT. + * + * wolfMQTT 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. + * + * wolfMQTT 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-1335, USA + */ + #ifndef WOLFMQTT_FIRMWARE_H #define WOLFMQTT_FIRMWARE_H +#ifdef __cplusplus +extern "C" { +#endif #define FIRMWARE_TOPIC_NAME "wolfMQTT/example/firmware" #define FIRMWARE_MAX_BUFFER 2048 @@ -18,5 +42,8 @@ typedef struct _FirmwareHeader { word32 fwLen; } WOLFMQTT_PACK FirmwareHeader; +#ifdef __cplusplus +} +#endif #endif /* WOLFMQTT_FIRMWARE_H */ diff --git a/examples/mqttclient/mqttclient.h b/examples/mqttclient/mqttclient.h index 25de259..a203253 100644 --- a/examples/mqttclient/mqttclient.h +++ b/examples/mqttclient/mqttclient.h @@ -22,11 +22,18 @@ #ifndef WOLFMQTT_MQTTCLIENT_H #define WOLFMQTT_MQTTCLIENT_H +#ifdef __cplusplus +extern "C" { +#endif + #include "examples/mqttexample.h" /* Exposed functions */ int mqttclient_test(MQTTCtx *mqttCtx); +#ifdef __cplusplus +} +#endif #endif /* WOLFMQTT_MQTTCLIENT_H */ diff --git a/examples/mqttnet.c b/examples/mqttnet.c index bc2b104..3c37c5f 100644 --- a/examples/mqttnet.c +++ b/examples/mqttnet.c @@ -711,7 +711,7 @@ static int NetRead_ex(void *context, byte* buf, int buf_len, int timeout_ms, byte peek) { SocketContext *sock = (SocketContext*)context; - MQTTCtx* mqttCtx = sock->mqttCtx; + MQTTCtx* mqttCtx; int rc = -1, timeout = 0; SOERROR_T so_error = 0; int bytes = 0; @@ -722,8 +722,6 @@ static int NetRead_ex(void *context, byte* buf, int buf_len, struct timeval tv; #endif - (void)mqttCtx; - if (context == NULL || buf == NULL || buf_len <= 0) { return MQTT_CODE_ERROR_BAD_ARG; } @@ -735,6 +733,9 @@ static int NetRead_ex(void *context, byte* buf, int buf_len, flags |= MSG_PEEK; } + mqttCtx = sock->mqttCtx; + (void)mqttCtx; + #ifndef WOLFMQTT_NO_TIMEOUT /* Setup timeout */ setup_timeout(&tv, timeout_ms); diff --git a/examples/mqttport.h b/examples/mqttport.h index f7dc52a..487cdbf 100644 --- a/examples/mqttport.h +++ b/examples/mqttport.h @@ -23,6 +23,10 @@ #ifndef WOLFMQTT_PORT_H #define WOLFMQTT_PORT_H +#ifdef __cplusplus +extern "C" { +#endif + /* FreeRTOS TCP */ #ifdef FREERTOS_TCP #include "FreeRTOS.h" @@ -252,10 +256,15 @@ #ifndef GET_SOCK_ERROR #define GET_SOCK_ERROR(f,s,o,e) \ socklen_t len = sizeof(so_error); \ - getsockopt((f), (s), (o), &(e), &len) + if (getsockopt((f), (s), (o), &(e), &len)) \ + rc = -1 #endif #ifndef SOCK_EQ_ERROR #define SOCK_EQ_ERROR(e) (((e) == EWOULDBLOCK) || ((e) == EAGAIN)) #endif +#ifdef __cplusplus +} +#endif + #endif /* WOLFMQTT_PORT_H */ diff --git a/examples/mqttsimple/mqttsimple.h b/examples/mqttsimple/mqttsimple.h index bcb7c1d..921e7eb 100644 --- a/examples/mqttsimple/mqttsimple.h +++ b/examples/mqttsimple/mqttsimple.h @@ -22,9 +22,16 @@ #ifndef WOLFMQTT_SIMPLE_H #define WOLFMQTT_SIMPLE_H +#ifdef __cplusplus +extern "C" { +#endif + /* Exposed functions */ int mqttsimple_test(void); +#ifdef __cplusplus +} +#endif #endif /* WOLFMQTT_SIMPLE_H */ diff --git a/examples/multithread/multithread.h b/examples/multithread/multithread.h index 55613b3..b6bde7c 100644 --- a/examples/multithread/multithread.h +++ b/examples/multithread/multithread.h @@ -22,11 +22,18 @@ #ifndef WOLFMQTT_MULTITHREAD_H #define WOLFMQTT_MULTITHREAD_H +#ifdef __cplusplus +extern "C" { +#endif + #include "examples/mqttexample.h" /* Exposed functions */ int multithread_test(MQTTCtx *mqttCtx); +#ifdef __cplusplus +} +#endif #endif /* WOLFMQTT_MULTITHREAD_H */ diff --git a/examples/sn-client/sn-client.h b/examples/sn-client/sn-client.h index 341b84f..03aa4a9 100644 --- a/examples/sn-client/sn-client.h +++ b/examples/sn-client/sn-client.h @@ -22,6 +22,10 @@ #ifndef WOLFMQTT_SNCLIENT_H #define WOLFMQTT_SNCLIENT_H +#ifdef __cplusplus +extern "C" { +#endif + #include "examples/mqttexample.h" @@ -30,5 +34,8 @@ int sn_test(MQTTCtx *mqttCtx); int sn_testQoSn1(MQTTCtx *mqttCtx); int sn_multithread_test(MQTTCtx *mqttCtx); +#ifdef __cplusplus +} +#endif #endif /* WOLFMQTT_SNCLIENT_H */ diff --git a/examples/wiot/wiot.h b/examples/wiot/wiot.h index 8c99211..be631c2 100755 --- a/examples/wiot/wiot.h +++ b/examples/wiot/wiot.h @@ -22,11 +22,18 @@ #ifndef WOLFMQTT_WIOT_H #define WOLFMQTT_WIOT_H +#ifdef __cplusplus +extern "C" { +#endif + #include "examples/mqttexample.h" /* Exposed functions */ int wiot_test(MQTTCtx *mqttCtx); +#ifdef __cplusplus +} +#endif #endif /* WOLFMQTT_WIOT_H */