-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add curl easy socket backend. #380
Conversation
configure.ac
Outdated
|
||
if test "x$ENABLED_CURL" = "xyes"; then | ||
if test "x$ENABLED_TLS" = "xyes"; then | ||
AC_MSG_ERROR([--enable-tls and --enable-curl are incompatible]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these really need to be incompatible? Just seems odd to forcefully have to disable TLS here to get the CURL easy sockets to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the last update --enable-curl
and --enable-tls
are allowed now. It disables some examples that aren't expected to work with curl. And when curl is enabled some of the lower level TLS code in src/mqtt_socket.c
is gated out.
src/mqtt_curl.c
Outdated
#include <errno.h> | ||
#endif | ||
|
||
#include "wolfmqtt/mqtt_client.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must support building sources directly. This while file needs wrapped with ENABLE_MQTT_CURL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
examples/mqttcurl.c
Outdated
|
||
if (ctx->curl == NULL) { | ||
PRINTF("error: curl_easy_init returned NULL"); | ||
return MQTT_CODE_ERROR_MEMORY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor to single return point. Can't you leak handles returning early?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Refactored the setopt and curl_easy_perform to a separate function, and the handle is cleaned up if that function fails.
src/mqtt_curl.c
Outdated
} | ||
|
||
return rc; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some compilers complain when there is no blank line at the eof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a section to the readme about using the libcurl option?
The client and firmware tests work with Will add a github action now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. Looking forward to the GitHub CI action being in place.
examples/mqttnet.c
Outdated
|
||
FD_SET(sockfd, &errfd); | ||
|
||
if(for_recv) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Please use if (
... add space.
examples/mqttnet.c
Outdated
return MQTT_CODE_ERROR_BAD_ARG; | ||
} | ||
|
||
/* Toggle with option, or put behind debug define? */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap with DEBUG_WOLFMQTT
Added the curl ubuntu CI test in a separate workflow (The The new workflow tests these combinations:
|
@@ -534,6 +544,10 @@ int MqttSocket_Disconnect(MqttClient *client) | |||
rc = client->net->disconnect(client->net->context); | |||
} | |||
MqttClient_Flags(client, MQTT_CLIENT_FLAG_IS_CONNECTED, 0); | |||
|
|||
#ifdef ENABLE_MQTT_CURL | |||
curl_global_cleanup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this now be in mqttnet.c or maybe MqttClient_DeInit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think mqttnet.c is too low level.
Would want it somewhere higher level where it's among the first/last functions called on init/exit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mqtt_socket just seemed natural because that's where we call wolfSSL_Init/cleanup.
@@ -34,6 +34,10 @@ | |||
#include <errno.h> | |||
#endif | |||
|
|||
#ifdef ENABLE_MQTT_CURL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can likely be removed if curl_global_cleanup
is moved
examples/mqttnet.c
Outdated
mqttcurl_connect(SocketContext * sock, const char* host, word16 port, | ||
int timeout_ms) | ||
{ | ||
CURLcode res = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples/mqttnet.c:435:14: error: cannot initialize a variable of type 'CURLcode' with an rvalue of type 'int'
CURLcode res = 0;
^ ~
examples/mqttnet.c:647:21: error: cannot initialize a variable of type 'CURLcode' with an rvalue of type 'int'
CURLcode res = 0;
^ ~
examples/mqttnet.c:714:21: error: cannot initialize a variable of type 'CURLcode' with an rvalue of type 'int'
CURLcode res = 0;
^ ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./configure --enable-all --enable-curl
produces build errors:
examples/mqttnet.c: In function ‘SN_ClientNet_Init’:
examples/mqttnet.c:1442:24: error: ‘SN_NetConnect’ undeclared (first use in this function); did you mean ‘NetConnect’?
1442 | net->connect = SN_NetConnect;
| ^~~~~~~~~~~~~
| NetConnect
examples/mqttnet.c:1442:24: note: each undeclared identifier is reported only once for each function it appears in
examples/mqttnet.c:1445:21: error: ‘NetPeek’ undeclared (first use in this function)
1445 | net->peek = NetPeek;
| ^~~~~~~
I think several of these combinations need to be rejected in configure.ac. Looking at this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In examples/mqttclient/mqttclient
, the client gets into the "Read loop" and fails to send messages typed. Also the client never sends a ping, just exits on timeout:
MQTT Waiting for message...
MQTT Message: Topic wolfMQTT/example/testTopic, Qos 0, Len 4
Payload (0 - 4) printing 4 bytes:
test
MQTT Message: Done
test
error: recvd 0 bytes, expected 2
Network Error Callback: Error (libcurl) (error -16)
MQTT Message Wait: Error (libcurl) (-16)
MQTT Disconnect: Success (0)
MQTT Socket Disconnect: Success (0)
Also, I'll document more clearly which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@embhorn when you are happy merge please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic!
Description
Added libcurl easy socket backend support for testing purposes.
Built with:
Prereqs
--enable-curl
and installed to/usr/local
.--with-wolfssl
and installed to/usr/local
.Testing
Added new curl easy socket example to
examples/mqttnet.c
, gated behindENABLE_MQTT_CURL
. If using TLS a CAfile can be passed in with -A:Also test with:
These tests are enabled and work with
--enable-curl
:scripts/firmware.test
scripts/client.test
These tests work as well if they are enabled:
scripts/multithread.test
scripts/nbclient.test