Update: EventQue deleminate null Event.

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2016-10-19 17:20:22 +09:00
parent 143b2ef90b
commit e2cf453c6b
4 changed files with 22 additions and 24 deletions

View File

@@ -35,7 +35,8 @@ ClientAuthentication=NO
#RootCAfile=/path/to/your_Root_CA.crt #RootCAfile=/path/to/your_Root_CA.crt
#RootCApath=/path/to/your_certs_directory/ #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 GatewayID=1
GatewayName=PahoGateway-01 GatewayName=PahoGateway-01
@@ -59,7 +60,7 @@ ApiMode=2
Client should know the BroadcastIP and PortNo to send a SEARCHGW message. Client should know the BroadcastIP and PortNo to send a SEARCHGW message.
**GatewayId** is defined by GWSEARCH message. **GatewayId** is defined by GWSEARCH message.
**KeepAlive** is a duration of ADVERTISE message in seconds. **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.

View File

@@ -152,7 +152,7 @@ void ClientRecvTask::log(Client* client, MQTTSNPacket* packet, MQTTSNString* id)
if ( 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) ; strncpy(cstr, id->lenstring.data, id->lenstring.len) ;
clientId = cstr; clientId = cstr;
} }

View File

@@ -207,7 +207,7 @@ public:
int post(T* t) int post(T* t)
{ {
if ( t && ( _maxSize == 0 || size() < _maxSize )) if ( t && ( _maxSize == 0 || _cnt < _maxSize ))
{ {
QueElement<T>* elm = new QueElement<T>(t); QueElement<T>* elm = new QueElement<T>(t);
if ( _head ) if ( _head )

View File

@@ -315,18 +315,12 @@ void EventQue::setMaxSize(uint16_t maxSize)
Event* EventQue::wait(void) Event* EventQue::wait(void)
{ {
Event* ev; Event* ev;
while ( true )
{
_sem.wait(); _sem.wait();
_mutex.lock(); _mutex.lock();
ev = _que.front(); ev = _que.front();
_que.pop(); _que.pop();
_mutex.unlock(); _mutex.unlock();
if ( ev )
{
return ev; return ev;
}
}
} }
Event* EventQue::timedwait(uint16_t millsec) Event* EventQue::timedwait(uint16_t millsec)
@@ -356,6 +350,8 @@ Event* EventQue::timedwait(uint16_t millsec)
void EventQue::post(Event* ev) void EventQue::post(Event* ev)
{ {
if ( ev )
{
_mutex.lock(); _mutex.lock();
if ( _que.post(ev) ) if ( _que.post(ev) )
{ {
@@ -366,6 +362,7 @@ void EventQue::post(Event* ev)
delete ev; delete ev;
} }
_mutex.unlock(); _mutex.unlock();
}
} }
int EventQue::size() int EventQue::size()