mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-14 07:56:52 +01:00
BugFix: stop Process mechanism of ProcessFramework.
Update: DISCONNECT procedure for NonActive clients. Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -345,6 +345,11 @@ bool Network::connect(const char* host, const char* port, const char* caPath, co
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_session)
|
||||
{
|
||||
rc = SSL_set_session(_ssl, _session);
|
||||
}
|
||||
|
||||
if (!SSL_set_fd(_ssl, getSock()))
|
||||
{
|
||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||
@@ -352,11 +357,9 @@ bool Network::connect(const char* host, const char* port, const char* caPath, co
|
||||
SSL_free(_ssl);
|
||||
}
|
||||
|
||||
//SSL_set_options(_ssl, SSL_OP_NO_TICKET);
|
||||
|
||||
if ( cert )
|
||||
{
|
||||
if ( SSL_use_certificate_file(_ssl, cert, SSL_FILETYPE_PEM) <= 0 )
|
||||
if ( SSL_use_certificate_file(_ssl, cert, SSL_FILETYPE_PEM) != 1 )
|
||||
{
|
||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||
WRITELOG("SSL_use_certificate_file() %s %s\n", cert, errmsg);
|
||||
@@ -367,7 +370,7 @@ bool Network::connect(const char* host, const char* port, const char* caPath, co
|
||||
}
|
||||
if ( prvkey )
|
||||
{
|
||||
if ( SSL_use_PrivateKey_file(_ssl, prvkey, SSL_FILETYPE_PEM) <= 0 )
|
||||
if ( SSL_use_PrivateKey_file(_ssl, prvkey, SSL_FILETYPE_PEM) != 1 )
|
||||
{
|
||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||
WRITELOG("SSL_use_PrivateKey_file() %s %s\n", prvkey, errmsg);
|
||||
@@ -386,11 +389,6 @@ bool Network::connect(const char* host, const char* port, const char* caPath, co
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_session)
|
||||
{
|
||||
rc = SSL_set_session(_ssl, _session);
|
||||
}
|
||||
|
||||
if (SSL_connect(_ssl) != 1)
|
||||
{
|
||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||
@@ -426,7 +424,7 @@ bool Network::connect(const char* host, const char* port, const char* caPath, co
|
||||
|
||||
if (_session == 0)
|
||||
{
|
||||
_session = SSL_get1_session(_ssl);
|
||||
//_session = SSL_get1_session(_ssl);
|
||||
}
|
||||
_numOfInstance++;
|
||||
_sslValid = true;
|
||||
|
||||
@@ -160,12 +160,11 @@ Semaphore::Semaphore(const char* name, unsigned int val)
|
||||
{
|
||||
throw Exception( -1, "Semaphore can't be created.");
|
||||
}
|
||||
_name = (char*) calloc(strlen(name + 1), 1);
|
||||
_name = strdup(name);
|
||||
if (_name == NULL)
|
||||
{
|
||||
throw Exception( -1, "Semaphore can't allocate memories.");
|
||||
}
|
||||
_name = strdup(name);
|
||||
}
|
||||
|
||||
Semaphore::~Semaphore()
|
||||
@@ -174,7 +173,7 @@ Semaphore::~Semaphore()
|
||||
{
|
||||
sem_close(_psem);
|
||||
sem_unlink(_name);
|
||||
free((void*) _name);
|
||||
free(_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -243,12 +242,18 @@ RingBuffer::RingBuffer(const char* keyDirectory)
|
||||
{
|
||||
int fp = 0;
|
||||
string fileName = keyDirectory + string(MQTTSNGW_RINGBUFFER_KEY);
|
||||
fp = open(fileName.c_str(), O_CREAT, 0);
|
||||
close(fp);
|
||||
fp = open(fileName.c_str(), O_CREAT, S_IRGRP);
|
||||
if ( fp > 0 )
|
||||
{
|
||||
close(fp);
|
||||
}
|
||||
|
||||
fileName = keyDirectory + string(MQTTSNGW_RB_MUTEX_KEY);
|
||||
fp = open(fileName.c_str(), O_CREAT, 0);
|
||||
close(fp);
|
||||
fp = open(fileName.c_str(), O_CREAT, S_IRGRP);
|
||||
if ( fp > 0 )
|
||||
{
|
||||
close(fp);
|
||||
}
|
||||
|
||||
key_t key = ftok(MQTTSNGW_RINGBUFFER_KEY, 1);
|
||||
|
||||
@@ -302,10 +307,6 @@ RingBuffer::~RingBuffer()
|
||||
{
|
||||
shmctl(_shmid, IPC_RMID, NULL);
|
||||
}
|
||||
if (_pmx > 0)
|
||||
{
|
||||
delete _pmx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -314,6 +315,11 @@ RingBuffer::~RingBuffer()
|
||||
shmdt(_shmaddr);
|
||||
}
|
||||
}
|
||||
|
||||
if (_pmx > 0)
|
||||
{
|
||||
delete _pmx;
|
||||
}
|
||||
}
|
||||
|
||||
void RingBuffer::put(char* data)
|
||||
@@ -469,14 +475,11 @@ void RingBuffer::reset()
|
||||
=====================================*/
|
||||
Thread::Thread()
|
||||
{
|
||||
_stopProcessEvent = theMultiTaskProcess->getStopProcessEvent();
|
||||
_threadID = 0;
|
||||
}
|
||||
|
||||
Thread::~Thread()
|
||||
{
|
||||
pthread_cancel(_threadID);
|
||||
pthread_join(_threadID, 0);
|
||||
}
|
||||
|
||||
void* Thread::_run(void* runnable)
|
||||
@@ -508,10 +511,6 @@ int Thread::start(void)
|
||||
|
||||
void Thread::stopProcess(void)
|
||||
{
|
||||
_stopProcessEvent->post();
|
||||
theMultiTaskProcess->threadStoped();
|
||||
}
|
||||
|
||||
void Thread::cancel(void)
|
||||
{
|
||||
pthread_cancel(_threadID);
|
||||
}
|
||||
|
||||
@@ -101,17 +101,12 @@ public:
|
||||
virtual void EXECRUN(){}
|
||||
};
|
||||
|
||||
|
||||
#define MAGIC_WORD_FOR_THREAD \
|
||||
public: void EXECRUN() \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
run(); \
|
||||
} \
|
||||
catch(Exception& ex) \
|
||||
{ \
|
||||
ex.writeMessage();\
|
||||
stopProcess(); \
|
||||
} \
|
||||
catch(...) \
|
||||
@@ -132,13 +127,10 @@ public:
|
||||
static bool equals(pthread_t*, pthread_t*);
|
||||
virtual void initialize(int argc, char** argv);
|
||||
void stopProcess(void);
|
||||
void cancel(void);
|
||||
void waitStop(void);
|
||||
private:
|
||||
pthread_t _threadID;
|
||||
Semaphore* _stopProcessEvent;
|
||||
|
||||
static void* _run(void*);
|
||||
|
||||
pthread_t _threadID;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,16 @@ SensorNetAddress::~SensorNetAddress()
|
||||
|
||||
}
|
||||
|
||||
uint32_t SensorNetAddress::getIpAddress(void)
|
||||
{
|
||||
return _IpAddr;
|
||||
}
|
||||
|
||||
uint16_t SensorNetAddress::getPortNo(void)
|
||||
{
|
||||
return _portNo;
|
||||
}
|
||||
|
||||
void SensorNetAddress::setAddress(uint32_t IpAddr, uint16_t port)
|
||||
{
|
||||
_IpAddr = IpAddr;
|
||||
@@ -96,12 +106,10 @@ SensorNetAddress& SensorNetAddress::operator =(SensorNetAddress& addr)
|
||||
============================================*/
|
||||
SensorNetwork::SensorNetwork()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SensorNetwork::~SensorNetwork()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int SensorNetwork::unicast(const uint8_t* payload, uint16_t payloadLength, SensorNetAddress* sendToAddr)
|
||||
@@ -302,10 +310,12 @@ int UDPPort::broadcast(const uint8_t* buf, uint32_t length)
|
||||
|
||||
int UDPPort::recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr)
|
||||
{
|
||||
struct timeval timeout;
|
||||
fd_set recvfds;
|
||||
int maxSock = 0;
|
||||
int rc = 0;
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 1000000; // 1 sec
|
||||
FD_ZERO(&recvfds);
|
||||
FD_SET(_sockfdUnicast, &recvfds);
|
||||
FD_SET(_sockfdMulticast, &recvfds);
|
||||
@@ -319,15 +329,17 @@ int UDPPort::recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr)
|
||||
maxSock = _sockfdUnicast;
|
||||
}
|
||||
|
||||
select(maxSock + 1, &recvfds, 0, 0, 0);
|
||||
|
||||
if (FD_ISSET(_sockfdUnicast, &recvfds))
|
||||
int rc = 0;
|
||||
if ( select(maxSock + 1, &recvfds, 0, 0, &timeout) > 0 )
|
||||
{
|
||||
rc = recvfrom(_sockfdUnicast, buf, len, 0, addr);
|
||||
}
|
||||
else if (FD_ISSET(_sockfdMulticast, &recvfds))
|
||||
{
|
||||
rc = recvfrom(_sockfdMulticast, buf, len, 0, &_grpAddr);
|
||||
if (FD_ISSET(_sockfdUnicast, &recvfds))
|
||||
{
|
||||
rc = recvfrom(_sockfdUnicast, buf, len, 0, addr);
|
||||
}
|
||||
else if (FD_ISSET(_sockfdMulticast, &recvfds))
|
||||
{
|
||||
rc = recvfrom(_sockfdMulticast, buf, len, 0, &_grpAddr);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -41,14 +41,8 @@ public:
|
||||
~SensorNetAddress();
|
||||
void setAddress(uint32_t IpAddr, uint16_t port);
|
||||
int setAddress(string* data);
|
||||
uint32_t getIpAddress(void)
|
||||
{
|
||||
return _IpAddr;
|
||||
}
|
||||
uint16_t getPortNo(void)
|
||||
{
|
||||
return _portNo;
|
||||
}
|
||||
uint16_t getPortNo(void);
|
||||
uint32_t getIpAddress(void);
|
||||
bool isMatch(SensorNetAddress* addr);
|
||||
SensorNetAddress& operator =(SensorNetAddress& addr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user