From c3e8470812dc78f34bb1ae00c08ac2b24a8d4db8 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Wed, 26 Oct 2016 09:24:48 +0900 Subject: [PATCH] BugFix of Issue #35, #38 Signed-off-by: tomoaki --- MQTTSNGateway/src/MQTTSNGWClient.cpp | 5 ++--- MQTTSNGateway/src/MQTTSNGateway.cpp | 18 +++++++++++------- MQTTSNGateway/src/MQTTSNGateway.h | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/MQTTSNGateway/src/MQTTSNGWClient.cpp b/MQTTSNGateway/src/MQTTSNGWClient.cpp index 55fb3b2..136c51b 100644 --- a/MQTTSNGateway/src/MQTTSNGWClient.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClient.cpp @@ -865,7 +865,6 @@ Topic* Topics::add(MQTTSN_topicid* topicid) { Topic* topic; uint16_t id = 0; - string* topicName = 0; if (topicid->type != MQTTSN_TOPIC_TYPE_NORMAL) { @@ -879,8 +878,8 @@ Topic* Topics::add(MQTTSN_topicid* topicid) } else { - topicName = new string(topicid->data.long_.name, topicid->data.long_.len); - topic = add(topicName); + string topicName = string(topicid->data.long_.name, topicid->data.long_.len); + topic = add(&topicName); } return topic; } diff --git a/MQTTSNGateway/src/MQTTSNGateway.cpp b/MQTTSNGateway/src/MQTTSNGateway.cpp index 5ed7103..d3a76e0 100644 --- a/MQTTSNGateway/src/MQTTSNGateway.cpp +++ b/MQTTSNGateway/src/MQTTSNGateway.cpp @@ -314,15 +314,19 @@ void EventQue::setMaxSize(uint16_t maxSize) Event* EventQue::wait(void) { - Event* ev; - if ( _que.size() == 0 ) + Event* ev = 0; + + while(ev == 0) { - _sem.wait(); + if ( _que.size() == 0 ) + { + _sem.wait(); + } + _mutex.lock(); + ev = _que.front(); + _que.pop(); + _mutex.unlock(); } - _mutex.lock(); - ev = _que.front(); - _que.pop(); - _mutex.unlock(); return ev; } diff --git a/MQTTSNGateway/src/MQTTSNGateway.h b/MQTTSNGateway/src/MQTTSNGateway.h index c5bdc1c..cd742c8 100644 --- a/MQTTSNGateway/src/MQTTSNGateway.h +++ b/MQTTSNGateway/src/MQTTSNGateway.h @@ -25,7 +25,7 @@ namespace MQTTSNGW /*================================= * Starting prompt ==================================*/ -#define GATEWAY_VERSION " * Version: 0.9.3" +#define GATEWAY_VERSION " * Version: 0.9.4" #define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway" #define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"