diff --git a/CMakeLists.txt b/CMakeLists.txt index fddf772..43798d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,13 +11,13 @@ option(MQTT_C_TESTS "Build MQTT-C tests?" OFF) list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # MQTT-C library -add_library(mqttc STATIC +add_library(mqttc STATIC src/mqtt_pal.c src/mqtt.c ) target_include_directories(mqttc PUBLIC include) target_link_libraries(mqttc PUBLIC - $<$:ws2_32> + $<$:ws2_32> ) if(MQTT_C_BearSSL_SUPPORT) @@ -89,7 +89,7 @@ if(MQTT_C_EXAMPLES) endif() # Build tests -if(MQTT_C_TESTS) +if(MQTT_C_TESTS) find_path(CMOCKA_INCLUDE_DIR cmocka.h) find_library(CMOCKA_LIBRARY cmocka) if((NOT CMOCKA_INCLUDE_DIR) OR (NOT CMOCKA_LIBRARY)) diff --git a/include/mqtt_pal.h b/include/mqtt_pal.h index 7a16f20..dbfd341 100644 --- a/include/mqtt_pal.h +++ b/include/mqtt_pal.h @@ -117,10 +117,10 @@ extern "C" { #endif #elif defined(_MSC_VER) #include + #include #include #include #include - #include typedef SSIZE_T ssize_t; #define MQTT_PAL_HTONS(s) htons(s) diff --git a/src/mqtt_pal.c b/src/mqtt_pal.c index 6335360..a273384 100644 --- a/src/mqtt_pal.c +++ b/src/mqtt_pal.c @@ -223,7 +223,7 @@ ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len, int flags) { size_t sent = 0; while(sent < len) { - int tmp = BIO_write(fd, buf + sent, len - sent); + int tmp = BIO_write(fd, (const char*)buf + sent, len - sent); if (tmp > 0) { sent += (size_t) tmp; } else if (tmp <= 0 && !BIO_should_retry(fd)) { @@ -235,13 +235,14 @@ ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len, } ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int flags) { - const void *const start = buf; + const char* const start = buf; + char* bufptr = buf; int rv; do { - rv = BIO_read(fd, buf, bufsz); + rv = BIO_read(fd, bufptr, bufsz); if (rv > 0) { /* successfully read bytes from the socket */ - buf += rv; + bufptr += rv; bufsz -= rv; } else if (!BIO_should_retry(fd)) { /* an error occurred that wasn't "nothing to read". */ @@ -249,7 +250,7 @@ ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int } } while (!BIO_should_read(fd)); - return (ssize_t)(buf - start); + return (ssize_t)(bufptr - start); } #elif defined(__unix__) || defined(__APPLE__)