Update: set Max EventQue size to avoid Buffer over flow

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2016-08-30 12:04:50 +09:00
parent 281d83af1e
commit 0f799cff7f
5 changed files with 52 additions and 31 deletions

View File

@@ -15,8 +15,8 @@
**************************************************************************************/
#include "MQTTSNGateway.h"
#include "MQTTSNGWProcess.h"
#include "SensorNetwork.h"
#include "MQTTSNGWProcess.h"
using namespace MQTTSNGW;
@@ -31,6 +31,7 @@ Gateway::Gateway()
theProcess = this;
_params.loginId = 0;
_params.password = 0;
_packetEventQue.setMaxSize(DEFAULT_INFLIGHTMESSAGE * DEFAULT_MAX_CLIENTS);
}
Gateway::~Gateway()
@@ -197,7 +198,7 @@ GatewayParams* Gateway::getGWParams(void)
=====================================*/
EventQue::EventQue()
{
_maxSize = 0;
}
EventQue::~EventQue()
@@ -205,6 +206,11 @@ EventQue::~EventQue()
}
void EventQue::setMaxSize(uint16_t maxSize)
{
_maxSize = maxSize;
}
Event* EventQue::wait(void)
{
Event* ev;
@@ -249,14 +255,15 @@ Event* EventQue::timedwait(uint16_t millsec)
int EventQue::post(Event* ev)
{
if ( ev )
if ( ev && ( _maxSize == 0 || size() < _maxSize ) )
{
_mutex.lock();
_que.post(ev);
_sem.post();
_mutex.unlock();
return 0;
}
return 0;
return 1;
}
int EventQue::size()