Comments (2)
Hi, I wrote this function.
This issue is also present in its blocking parent function, since the code is mostly taken from there and split; although it manages to get past this since as there are no more bytes to read, the socket returns 0 and the code advances gracefully. I wrote two samples to test ping, blocking and non-blocking, and the suggested patch, also fixing issue #57 , is the following: fixpong.zip
diff --git a/MQTTPacket/src/MQTTPacket.c b/MQTTPacket/src/MQTTPacket.c
index bd5f90a..4f1f95a 100644
--- a/MQTTPacket/src/MQTTPacket.c
+++ b/MQTTPacket/src/MQTTPacket.c
@@ -306,7 +306,7 @@ int MQTTPacket_read(unsigned char* buf, int buflen, int (*ge
/* 3. read the rest of the buffer using a callback to supply the rest of
if((rem_len + len) > buflen)
goto exit;
- if ((*getfn)(buf + len, rem_len) != rem_len)
+ if (rem_len && ((*getfn)(buf + len, rem_len) != rem_len))
goto exit;
header.byte = buf[0];
@@ -333,7 +333,7 @@ static int MQTTPacket_decodenb(MQTTTransport *trp)
}
do {
int frc;
- if (++(trp->len) > MAX_NO_OF_REMAINING_LENGTH_BYTES)
+ if (trp->len >= MAX_NO_OF_REMAINING_LENGTH_BYTES)
goto exit;
if ((frc=(*trp->getfn)(trp->sck, &c, 1)) == -1)
goto exit;
@@ -341,6 +341,7 @@ static int MQTTPacket_decodenb(MQTTTransport *trp)
rc = 0;
goto exit;
}
+ ++(trp->len);
trp->rem_len += (c & 127) * trp->multiplier;
trp->multiplier *= 128;
} while ((c & 128) != 0);
@@ -388,16 +389,17 @@ int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTT
++trp->state;
/*FALLTHROUGH*/
case 2:
- /* read the rest of the buffer using a callback to supply the re
- if ((frc=(*trp->getfn)(trp->sck, buf + trp->len, trp->rem_len))
- goto exit;
- if (frc == 0)
- return 0;
- trp->rem_len -= frc;
- trp->len += frc;
- if(trp->rem_len)
- return 0;
-
+ if(trp->rem_len){
+ /* read the rest of the buffer using a callback to suppl
+ if ((frc=(*trp->getfn)(trp->sck, buf + trp->len, trp->re
+ goto exit;
+ if (frc == 0)
+ return 0;
+ trp->rem_len -= frc;
+ trp->len += frc;
+ if(trp->rem_len)
+ return 0;
+ }
header.byte = buf[0];
rc = header.bits.type;
break;
Regards
PS: The samples: pingsamples.zip
from paho.mqtt.embedded-c.
I've merged the PR. I assume that this issue is now fixed.
from paho.mqtt.embedded-c.
Related Issues (20)
- Messages are not retained even if the flag is set to true HOT 2
- Suspected bug with MQTTYield() / cycle()
- Performance problem related to cycle() and MQTT_TASK HOT 2
- Is there a limit on the amount of bytes the payload must be in the publish message? HOT 6
- Are there any plans to migrate to exact-width integer types? HOT 13
- isTopicMatched() does not behave correctly for filter that terminates with wildcard /# HOT 2
- Why use `enddata - curdata` instead of `mylen` in `MQTTDeserialize_ack()`?
- MQTTPacket_decode() doesn't present errors when it should HOT 1
- Does this library support mqtt v5? HOT 6
- Memory corruptions when casting enum to `int *` HOT 1
- Client never closes socket HOT 2
- Move includes to a subdirectory HOT 3
- keepalive failed by calling MQTTYield with short timeout and short interval. HOT 4
- Potential OOB Writes in eclipse/paho.mqtt.embedded-c
- PlatformIO's last release outdate HOT 2
- Compile error when compiling MQTTV5 HOT 1
- Library linking issues HOT 2
- Facing errors while building on windows
- MQTTPacket V5
- Example MQTT Client C use SSL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paho.mqtt.embedded-c.