From e2cf453c6b51d9895c0d94f403c9905c6efab3c8 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Wed, 19 Oct 2016 17:20:22 +0900 Subject: [PATCH] Update: EventQue deleminate null Event. Signed-off-by: tomoaki --- MQTTSNGateway/README.md | 5 +-- MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp | 2 +- MQTTSNGateway/src/MQTTSNGWProcess.h | 2 +- MQTTSNGateway/src/MQTTSNGateway.cpp | 37 +++++++++----------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index 67f5e57..bc3314e 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -35,7 +35,8 @@ ClientAuthentication=NO #RootCAfile=/path/to/your_Root_CA.crt #RootCApath=/path/to/your_certs_directory/ -#CertsDirectory=/path/to/your_client_certs_directory/ +#CertKey=/path/to/your_cert.pem +#PrivateKey=/path/to/your_private-key.pem GatewayID=1 GatewayName=PahoGateway-01 @@ -59,7 +60,7 @@ ApiMode=2 Client should know the BroadcastIP and PortNo to send a SEARCHGW message. **GatewayId** is defined by GWSEARCH message. **KeepAlive** is a duration of ADVERTISE message in seconds. -when **ClientAuthentication** is YES, see MQTTSNGWClient.cpp line53, clients file specified by ClientsList is required. This file defines connect allowed clients by ClientId, IPaddress and PortNo. +when **ClientAuthentication** is YES, see MQTTSNGWClient.cpp line53, clients file specified by ClientsList is required. This file defines connect allowed clients by ClientId and SensorNetwork Address. e.g. IP address and Port No. diff --git a/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp b/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp index 65961c2..d8c482a 100644 --- a/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClientRecvTask.cpp @@ -152,7 +152,7 @@ void ClientRecvTask::log(Client* client, MQTTSNPacket* packet, MQTTSNString* id) if ( id ) { - memset((void*)cstr, 0, id->lenstring.len); + memset((void*)cstr, 0, id->lenstring.len + 1); strncpy(cstr, id->lenstring.data, id->lenstring.len) ; clientId = cstr; } diff --git a/MQTTSNGateway/src/MQTTSNGWProcess.h b/MQTTSNGateway/src/MQTTSNGWProcess.h index 7fdd52f..3ea6a45 100644 --- a/MQTTSNGateway/src/MQTTSNGWProcess.h +++ b/MQTTSNGateway/src/MQTTSNGWProcess.h @@ -207,7 +207,7 @@ public: int post(T* t) { - if ( t && ( _maxSize == 0 || size() < _maxSize )) + if ( t && ( _maxSize == 0 || _cnt < _maxSize )) { QueElement* elm = new QueElement(t); if ( _head ) diff --git a/MQTTSNGateway/src/MQTTSNGateway.cpp b/MQTTSNGateway/src/MQTTSNGateway.cpp index fbed95c..9db087c 100644 --- a/MQTTSNGateway/src/MQTTSNGateway.cpp +++ b/MQTTSNGateway/src/MQTTSNGateway.cpp @@ -315,18 +315,12 @@ void EventQue::setMaxSize(uint16_t maxSize) Event* EventQue::wait(void) { Event* ev; - while ( true ) - { - _sem.wait(); - _mutex.lock(); - ev = _que.front(); - _que.pop(); - _mutex.unlock(); - if ( ev ) - { - return ev; - } - } + _sem.wait(); + _mutex.lock(); + ev = _que.front(); + _que.pop(); + _mutex.unlock(); + return ev; } Event* EventQue::timedwait(uint16_t millsec) @@ -356,16 +350,19 @@ Event* EventQue::timedwait(uint16_t millsec) void EventQue::post(Event* ev) { - _mutex.lock(); - if ( _que.post(ev) ) + if ( ev ) { - _sem.post(); + _mutex.lock(); + if ( _que.post(ev) ) + { + _sem.post(); + } + else + { + delete ev; + } + _mutex.unlock(); } - else - { - delete ev; - } - _mutex.unlock(); } int EventQue::size()