Skip to content

Commit

Permalink
Merge pull request #106 from learn-more/msvc_build
Browse files Browse the repository at this point in the history
Msvc build fixes
  • Loading branch information
LiamBindle authored Oct 2, 2020
2 parents 06a45d7 + 2ab6c31 commit a8a6aa0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<C_COMPILER_ID:MSVS>:ws2_32>
$<$<C_COMPILER_ID:MSVC>:ws2_32>
)

if(MQTT_C_BearSSL_SUPPORT)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion include/mqtt_pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ extern "C" {
#endif
#elif defined(_MSC_VER)
#include <limits.h>
#include <winsock2.h>
#include <windows.h>
#include <time.h>
#include <stdint.h>
#include <winsock2.h>

typedef SSIZE_T ssize_t;
#define MQTT_PAL_HTONS(s) htons(s)
Expand Down
11 changes: 6 additions & 5 deletions src/mqtt_pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -235,21 +235,22 @@ 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". */
return MQTT_ERROR_SOCKET_ERROR;
}
} while (!BIO_should_read(fd));

return (ssize_t)(buf - start);
return (ssize_t)(bufptr - start);
}

#elif defined(__unix__) || defined(__APPLE__)
Expand Down

0 comments on commit a8a6aa0

Please sign in to comment.