BugFix: Exclusive control the close of TCPIP

This commit is contained in:
tomoaki
2016-07-23 05:56:55 +09:00
parent 5605ae0294
commit 464187a08b
4 changed files with 12 additions and 4 deletions

View File

@@ -109,7 +109,10 @@ void BrokerRecvTask::run(void)
rc = packet->recv(client->getNetwork()); rc = packet->recv(client->getNetwork());
if ( rc > 0 ) if ( rc > 0 )
{ {
log(client, packet); if ( log(client, packet) == -1 )
{
continue;
}
/* post a BrokerRecvEvent */ /* post a BrokerRecvEvent */
ev = new Event(); ev = new Event();
@@ -161,10 +164,11 @@ void BrokerRecvTask::run(void)
/** /**
* write message content into stdout or Ringbuffer * write message content into stdout or Ringbuffer
*/ */
void BrokerRecvTask::log(Client* client, MQTTGWPacket* packet) int BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
{ {
char pbuf[SIZEOF_LOG_PACKET * 3]; char pbuf[SIZEOF_LOG_PACKET * 3];
char msgId[6]; char msgId[6];
int rc = 0;
switch (packet->getType()) switch (packet->getType())
{ {
@@ -189,7 +193,8 @@ void BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
WRITELOG(FORMAT_GR_NL, currentDateTime(), packet->getName(), LEFTARROW, client->getClientId(), packet->print(pbuf)); WRITELOG(FORMAT_GR_NL, currentDateTime(), packet->getName(), LEFTARROW, client->getClientId(), packet->print(pbuf));
break; break;
default: default:
WRITELOG(FORMAT_GR_NL, currentDateTime(), "UNKOWN_TYPE", LEFTARROW, client->getClientId(), packet->print(pbuf)); rc = -1;
break; break;
} }
return rc;
} }

View File

@@ -37,7 +37,7 @@ public:
void run(void); void run(void);
private: private:
void log(Client*, MQTTGWPacket*); int log(Client*, MQTTGWPacket*);
Gateway* _gateway; Gateway* _gateway;
LightIndicator* _light; LightIndicator* _light;

View File

@@ -57,6 +57,7 @@ bool TCPStack::isValid()
void TCPStack::close() void TCPStack::close()
{ {
_mutex.lock();
if (_sockfd > 0) if (_sockfd > 0)
{ {
::close(_sockfd); ::close(_sockfd);
@@ -67,6 +68,7 @@ void TCPStack::close()
_addrinfo = 0; _addrinfo = 0;
} }
} }
_mutex.unlock();
} }

View File

@@ -59,6 +59,7 @@ public:
private: private:
int _sockfd; int _sockfd;
addrinfo* _addrinfo; addrinfo* _addrinfo;
Mutex _mutex;
}; };
/*======================================== /*========================================