Skip to content

Commit da94327

Browse files
committed
Add curl easy socket backend: consolidate mqtt_curl into mqtt_socket.
1 parent e25d2a6 commit da94327

File tree

9 files changed

+21
-351
lines changed

9 files changed

+21
-351
lines changed

examples/mqttnet.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ mqttcurl_connect(SocketContext * ctx, const char* host, word16 port,
441441

442442
if (port == MQTT_SECURE_PORT) { use_tls = 1; }
443443

444+
/* Toggle with option, or put behind debug define? */
444445
res = curl_easy_setopt(ctx->curl, CURLOPT_VERBOSE, 1L);
445446

446447
if (res != CURLE_OK) {
@@ -636,7 +637,7 @@ static int NetWrite(void *context, const byte* buf, int buf_len,
636637
}
637638

638639
#if defined(WOLFMQTT_DEBUG_SOCKET)
639-
PRINTF("ctx->curl = %lld, sockfd = %d", (long long) ctx->curl, sockfd);
640+
PRINTF("ctx->curl = %p, sockfd = %d", (void *)ctx->curl, sockfd);
640641
#endif
641642

642643
/* A very simple retry with timeout example. This assumes the entire
@@ -703,7 +704,7 @@ static int NetRead(void *context, byte* buf, int buf_len,
703704
}
704705

705706
#if defined(WOLFMQTT_DEBUG_SOCKET)
706-
PRINTF("ctx->curl = %lld, sockfd = %d", (long long) ctx->curl, sockfd);
707+
PRINTF("ctx->curl = %p, sockfd = %d", (void *)ctx->curl, sockfd);
707708
#endif
708709

709710
/* A very simple retry with timeout example. This assumes the entire

examples/mqttnet.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
extern "C" {
2727
#endif
2828

29+
#ifdef ENABLE_MQTT_CURL
30+
#include <curl/curl.h>
31+
#endif
32+
2933
#include "examples/mqttexample.h"
3034
#include "examples/mqttport.h"
3135

src/include.am

-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55

66
lib_LTLIBRARIES+= src/libwolfmqtt.la
77

8-
if HAVE_LIBCURL
9-
src_libwolfmqtt_la_SOURCES = src/mqtt_client.c \
10-
src/mqtt_packet.c \
11-
src/mqtt_curl.c
12-
else
138
src_libwolfmqtt_la_SOURCES = src/mqtt_client.c \
149
src/mqtt_packet.c \
1510
src/mqtt_socket.c
16-
endif
1711

1812
if BUILD_SN
1913
src_libwolfmqtt_la_SOURCES += src/mqtt_sn_client.c \

src/mqtt_curl.c

-243
This file was deleted.

src/mqtt_socket.c

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include <errno.h>
3535
#endif
3636

37+
#ifdef ENABLE_MQTT_CURL
38+
#include <curl/curl.h>
39+
#endif
40+
3741
#include "wolfmqtt/mqtt_client.h"
3842
#include "wolfmqtt/mqtt_socket.h"
3943

@@ -102,6 +106,10 @@ int MqttSocket_Init(MqttClient *client, MqttNet *net)
102106
{
103107
int rc = MQTT_CODE_ERROR_BAD_ARG;
104108
if (client) {
109+
#ifdef ENABLE_MQTT_CURL
110+
curl_global_init(CURL_GLOBAL_DEFAULT);
111+
#endif
112+
105113
client->net = net;
106114
MqttClient_Flags(client, (MQTT_CLIENT_FLAG_IS_CONNECTED |
107115
MQTT_CLIENT_FLAG_IS_TLS), 0);;
@@ -534,6 +542,10 @@ int MqttSocket_Disconnect(MqttClient *client)
534542
rc = client->net->disconnect(client->net->context);
535543
}
536544
MqttClient_Flags(client, MQTT_CLIENT_FLAG_IS_CONNECTED, 0);
545+
546+
#ifdef ENABLE_MQTT_CURL
547+
curl_global_cleanup();
548+
#endif
537549
}
538550
#ifdef WOLFMQTT_DEBUG_SOCKET
539551
PRINTF("MqttSocket_Disconnect: Rc=%d", rc);

wolfmqtt/include.am

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ nobase_include_HEADERS+= \
1111
wolfmqtt/visibility.h \
1212
wolfmqtt/options.h \
1313
wolfmqtt/vs_settings.h
14-
if HAVE_LIBCURL
15-
nobase_include_HEADERS+= wolfmqtt/mqtt_curl.h
16-
endif
1714

1815
if BUILD_SN
1916
nobase_include_HEADERS+= wolfmqtt/mqtt_sn_client.h \

wolfmqtt/mqtt_client.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@
4040
#endif
4141
#include "wolfmqtt/mqtt_types.h"
4242
#include "wolfmqtt/mqtt_packet.h"
43-
#ifdef ENABLE_MQTT_CURL
44-
#include "wolfmqtt/mqtt_curl.h"
45-
#else
46-
#include "wolfmqtt/mqtt_socket.h"
47-
#endif
43+
#include "wolfmqtt/mqtt_socket.h"
4844

4945
#ifdef WOLFMQTT_SN
5046
#include "wolfmqtt/mqtt_sn_packet.h"

0 commit comments

Comments
 (0)