Skip to content

Commit 3f37af5

Browse files
committed
Merge commit '0bff693' into curl_gh_fix
2 parents 16c3222 + 0bff693 commit 3f37af5

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

examples/mqttnet.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -737,22 +737,16 @@ mqttcurl_connect(SocketContext* sock, const char* host, word16 port,
737737

738738
if (timeout_ms != 0) {
739739
res = curl_easy_setopt(sock->curl, CURLOPT_CONNECTTIMEOUT_MS,
740-
timeout_ms);
740+
(long)timeout_ms);
741741

742742
if (res != CURLE_OK) {
743743
PRINTF("error: curl_easy_setopt(CONNECTTIMEOUT_MS, %d) "
744744
"returned %d", timeout_ms, res);
745745
return MQTT_CODE_ERROR_CURL;
746746
}
747-
748-
res = curl_easy_setopt(sock->curl, CURLOPT_TIMEOUT_MS,
749-
timeout_ms);
750-
751-
if (res != CURLE_OK) {
752-
PRINTF("error: curl_easy_setopt(TIMEOUT_MS, %d) "
753-
"returned %d", timeout_ms, res);
754-
return MQTT_CODE_ERROR_CURL;
755-
}
747+
/* Note: CURLOPT_TIMEOUT_MS is not used here because it sets a total
748+
* transfer timeout, which is not applicable with CURLOPT_CONNECT_ONLY
749+
* mode where we use curl_easy_send/recv manually after connect. */
756750
}
757751

758752
res = curl_easy_setopt(sock->curl, CURLOPT_URL, host);
@@ -763,7 +757,7 @@ mqttcurl_connect(SocketContext* sock, const char* host, word16 port,
763757
return MQTT_CODE_ERROR_CURL;
764758
}
765759

766-
res = curl_easy_setopt(sock->curl, CURLOPT_PORT, port);
760+
res = curl_easy_setopt(sock->curl, CURLOPT_PORT, (long)port);
767761

768762
if (res != CURLE_OK) {
769763
PRINTF("error: curl_easy_setopt(PORT, %d) returned: %d",
@@ -845,7 +839,7 @@ mqttcurl_connect(SocketContext* sock, const char* host, word16 port,
845839
*/
846840

847841
/* Set peer and host verification. */
848-
res = curl_easy_setopt(sock->curl, CURLOPT_SSL_VERIFYPEER, 1);
842+
res = curl_easy_setopt(sock->curl, CURLOPT_SSL_VERIFYPEER, 1L);
849843

850844
if (res != CURLE_OK) {
851845
PRINTF("error: curl_easy_setopt(SSL_VERIFYPEER) returned: %d",
@@ -856,10 +850,10 @@ mqttcurl_connect(SocketContext* sock, const char* host, word16 port,
856850
/* Only do server host verification when not running against
857851
* localhost broker. */
858852
if (XSTRCMP(host, "localhost") == 0) {
859-
res = curl_easy_setopt(sock->curl, CURLOPT_SSL_VERIFYHOST, 0);
853+
res = curl_easy_setopt(sock->curl, CURLOPT_SSL_VERIFYHOST, 0L);
860854
}
861855
else {
862-
res = curl_easy_setopt(sock->curl, CURLOPT_SSL_VERIFYHOST, 2);
856+
res = curl_easy_setopt(sock->curl, CURLOPT_SSL_VERIFYHOST, 2L);
863857
}
864858

865859
if (res != CURLE_OK) {
@@ -898,7 +892,7 @@ mqttcurl_connect(SocketContext* sock, const char* host, word16 port,
898892
}
899893
#endif
900894

901-
res = curl_easy_setopt(sock->curl, CURLOPT_CONNECT_ONLY, 1);
895+
res = curl_easy_setopt(sock->curl, CURLOPT_CONNECT_ONLY, 1L);
902896

903897
if (res != CURLE_OK) {
904898
PRINTF("error: curl_easy_setopt(CONNECT_ONLY, 1) returned: %d",

src/mqtt_socket.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ static int MqttSocket_WriteDo(MqttClient *client, const byte* buf, int buf_len,
143143

144144
rc = wolfSSL_write(client->tls.ssl, (char*)buf, buf_len);
145145
if (rc < 0) {
146-
#if defined(WOLFMQTT_DEBUG_SOCKET) || defined(WOLFSSL_ASYNC_CRYPT)
147146
int error = wolfSSL_get_error(client->tls.ssl, 0);
148-
#endif
147+
client->tls.lastError = error;
149148
#ifdef WOLFMQTT_DEBUG_SOCKET
150149
if (error != WOLFSSL_ERROR_WANT_WRITE
151150
#ifdef WOLFSSL_ASYNC_CRYPT
@@ -248,6 +247,7 @@ static int MqttSocket_ReadDo(MqttClient *client, byte* buf, int buf_len,
248247
rc = wolfSSL_read(client->tls.ssl, (char*)buf, buf_len);
249248
if (rc < 0) {
250249
int error = wolfSSL_get_error(client->tls.ssl, 0);
250+
client->tls.lastError = error;
251251
#ifdef WOLFMQTT_DEBUG_SOCKET
252252
if (error != WOLFSSL_ERROR_WANT_READ
253253
#ifdef WOLFSSL_ASYNC_CRYPT
@@ -404,6 +404,9 @@ int MqttSocket_Connect(MqttClient *client, const char* host, word16 port,
404404
#if defined(ENABLE_MQTT_TLS) && !defined(ENABLE_MQTT_CURL) && \
405405
!defined(ENABLE_MQTT_WEBSOCKET)
406406
if (use_tls) {
407+
/* Clear any previous TLS error */
408+
client->tls.lastError = 0;
409+
407410
if (client->tls.ctx == NULL) {
408411
#ifdef DEBUG_WOLFSSL
409412
wolfSSL_Debugging_ON();
@@ -502,6 +505,8 @@ int MqttSocket_Connect(MqttClient *client, const char* host, word16 port,
502505
) {
503506
return MQTT_CODE_CONTINUE;
504507
}
508+
/* Preserve the error to be used later, e.g. in net callback */
509+
client->tls.lastError = errnum;
505510
#ifdef WOLFMQTT_DEBUG_SOCKET
506511
errstr = wolfSSL_ERR_reason_error_string(errnum);
507512
#endif

wolfmqtt/mqtt_socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef struct _MqttTls {
7373
int sockRcWrite;
7474
int timeout_ms_read;
7575
int timeout_ms_write;
76+
int lastError;
7677
} MqttTls;
7778
#endif
7879

0 commit comments

Comments
 (0)