diff --git a/MQTTSNGateway/src/MQTTSNGWClient.cpp b/MQTTSNGateway/src/MQTTSNGWClient.cpp index c0a7d03..31d65ce 100644 --- a/MQTTSNGateway/src/MQTTSNGWClient.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClient.cpp @@ -735,6 +735,7 @@ uint16_t Topic::getTopicId(void) bool Topic::isMatch(string* topicName) { string::size_type tlen = _topicName->size(); + if (topicName->size() < tlen - 2) { return false; diff --git a/MQTTSNGateway/src/MQTTSNGWVersion.h b/MQTTSNGateway/src/MQTTSNGWVersion.h index 6989e2c..6506300 100644 --- a/MQTTSNGateway/src/MQTTSNGWVersion.h +++ b/MQTTSNGateway/src/MQTTSNGWVersion.h @@ -17,6 +17,6 @@ #ifndef MQTTSNGWVERSION_H_IN_ #define MQTTSNGWVERSION_H_IN_ -#define PAHO_GATEWAY_VERSION "1.0.0" +#define PAHO_GATEWAY_VERSION "1.0.1" #endif /* MQTTSNGWVERSION_H_IN_ */ diff --git a/MQTTSNGateway/src/linux/xbee/SensorNetwork.cpp b/MQTTSNGateway/src/linux/xbee/SensorNetwork.cpp index 65b9946..00bbb36 100644 --- a/MQTTSNGateway/src/linux/xbee/SensorNetwork.cpp +++ b/MQTTSNGateway/src/linux/xbee/SensorNetwork.cpp @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include "SensorNetwork.h" #include "MQTTSNGWProcess.h" @@ -238,6 +241,10 @@ int XBee::recv(uint8_t* buf, uint16_t bufLen, SensorNetAddress* clientAddr) _sem.post(); } } + else + { + return 0; + } } } @@ -451,15 +458,21 @@ bool SerialPort::send(unsigned char b) bool SerialPort::recv(unsigned char* buf) { - if (read(_fd, buf, 1) == 0) - { - return false; - } - else - { - D_NWSTACK( " %02x",buf[0] ); - return true; - } + struct timeval timeout; + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(_fd, &rfds); + timeout.tv_sec = 0; + timeout.tv_usec = 500000; // 500ms + if ( select(1, &rfds, 0, 0, &timeout) > 0 ) + { + if (read(_fd, buf, 1) > 0) + { + D_NWSTACK( " %02x",buf[0] ); + return true; + } + } + return false; } void SerialPort::flush(void)