eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
315 stars 178 forks source link

MQTTSNPacker_read - non blocking function #129

Closed krzysztofsroczynski closed 6 years ago

krzysztofsroczynski commented 6 years ago

Hi, please add non-blocking implementation of MQTTSNPacket_read() function. It is very useful if you are using single thread embedded applications.

My example (every time new release comes out I have to rewrite it again :))

int MQTTSNPacket_read_nb(unsigned char* buf, int buflen)
{
    int rc = MQTTSNPACKET_READ_ERROR;
    int len = buflen;  /* the length of the whole packet including length field */
    int lenlen = 0;
    int datalen = 0;

    /* 2. read the length.  This is variable in itself */
    lenlen = MQTTSNPacket_decode(buf, len, &datalen);
    if (datalen != len)
        goto exit; /* there was an error */

    rc = buf[lenlen]; /* return the packet type */
exit:
    return rc;
}
ty4tw commented 6 years ago

Thank you for your contribution.

icraggs commented 6 years ago

Just an observation - it's probably better to submit a pull request for code additions, as the IP checks are then done automatically. For very small contributions like this, it's not too big a deal, but a PR would still be safer.

And I reiterate Tomoaki's thanks too!