Skip to content

Commit

Permalink
Enable testing of non-blocking using the WOLFMQTT_TEST_NONBLOCK macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Mar 24, 2022
1 parent 824a113 commit 1840eb3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/macos-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ jobs:
run: make
- name: make check
run: make check
- name: configure with Non-Block
run: ./configure --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK"
- name: make
run: make
- name: make check
run: make check
- name: configure with Non-Block and Multi-threading
run: ./configure --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK"
- name: make
run: make
- name: make check
run: make check
12 changes: 12 additions & 0 deletions .github/workflows/ubuntu-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ jobs:
run: make
- name: make check
run: make check
- name: configure with Non-Block
run: ./configure --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK"
- name: make
run: make
- name: make check
run: make check
- name: configure with Non-Block and Multi-threading
run: ./configure --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK"
- name: make
run: make
- name: make check
run: make check
6 changes: 3 additions & 3 deletions commit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RESULT=$?

# make sure multithread with non-blocking is okay
echo -e "\n\nTesting multithread with non-block config...\n\n"
./configure --enable-mt;
./configure --enable-mt --enable-nonblock CFLAGS="-DWOLFMQTT_TEST_NONBLOCK";
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nTest './configure --enable-mt --enable-nonblock' failed" && exit 1

Expand All @@ -73,7 +73,7 @@ RESULT=$?

# make sure non-blocking plus TLS is okay
echo -e "\n\nTesting Non-Blocking TLS config as well...\n\n"
./configure --enable-nonblock --enable-tls;
./configure --enable-nonblock --enable-tls CFLAGS="-DWOLFMQTT_TEST_NONBLOCK";
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nTest './configure --enable-nonblock --enable-tls' failed" && exit 1

Expand All @@ -83,7 +83,7 @@ RESULT=$?

# make sure non-blocking is okay
echo -e "\n\nTesting Non-Blocking config too...\n\n"
./configure --enable-nonblock --disable-tls;
./configure --enable-nonblock --disable-tls CFLAGS="-DWOLFMQTT_TEST_NONBLOCK";
RESULT=$?
[ $RESULT -ne 0 ] && echo -e "\n\nTest './configure --enable-nonblock --disable-tls' failed" && exit 1

Expand Down
7 changes: 2 additions & 5 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,10 +1461,6 @@ int MqttClient_Connect(MqttClient *client, MqttConnect *mc_connect)
return rc;
}

#ifdef WOLFMQTT_TEST_NONBLOCK
static int testNbAlt = 0;
#endif

static int MqttClient_Publish_ReadPayload(MqttClient* client,
MqttPublish* publish, int timeout_ms)
{
Expand Down Expand Up @@ -1517,7 +1513,8 @@ static int MqttClient_Publish_ReadPayload(MqttClient* client,

/* make sure there is something to read */
if (msg_len > 0) {
#ifdef WOLFMQTT_TEST_NONBLOCK
#if defined(WOLFMQTT_NONBLOCK) && defined(WOLFMQTT_TEST_NONBLOCK)
static int testNbAlt = 0;
if (!testNbAlt) {
testNbAlt = 1;
return MQTT_CODE_CONTINUE;
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ int MqttPacket_Read(MqttClient *client, byte* rx_buf, int rx_buf_len,
case MQTT_PK_BEGIN:
{
client->read.pos = 0;
client->packet.header_len = 2;
client->packet.header_len = MQTT_PACKET_HEADER_MIN_SIZE;
client->packet.remain_len = 0;

/* Read fix header portion */
Expand Down
9 changes: 9 additions & 0 deletions src/mqtt_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ static int MqttSocket_ReadDo(MqttClient *client, byte* buf, int buf_len,
{
int rc;

#if defined(WOLFMQTT_NONBLOCK) && defined(WOLFMQTT_TEST_NONBLOCK)
static int testNbAlt = 0;
if (!testNbAlt) {
testNbAlt = 1;
return MQTT_CODE_CONTINUE;
}
testNbAlt = 0;
#endif

#ifdef ENABLE_MQTT_TLS
if (client->flags & MQTT_CLIENT_FLAG_IS_TLS) {
client->tls.timeout_ms = timeout_ms;
Expand Down

0 comments on commit 1840eb3

Please sign in to comment.