BugFix: Network can not handle EPIPE error. Issue#35 #36

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2016-10-07 18:55:03 +09:00
parent d834a1a65b
commit 9de0448130
13 changed files with 246 additions and 252 deletions

View File

@@ -59,8 +59,10 @@ void BrokerRecvTask::run(void)
while (true)
{
_light->blueLight(false);
if (CHK_SIGINT)
{
WRITELOG("%s BrokerRecvTask stopped.\n", currentDateTime());
return;
}
timeout.tv_sec = 0;
@@ -72,7 +74,6 @@ void BrokerRecvTask::run(void)
/* Prepare sockets list to read */
Client* client = _gateway->getClientList()->getClient();
_light->blueLight(false);
while (client > 0)
{
@@ -115,7 +116,8 @@ void BrokerRecvTask::run(void)
if ( log(client, packet) == -1 )
{
continue;
delete packet;
goto nextClient;
}
/* post a BrokerRecvEvent */
@@ -125,13 +127,7 @@ void BrokerRecvTask::run(void)
}
else
{
_light->blueLight(false);
if ( rc == 0 )
{
delete packet;
continue;
}
else if (rc == -1)
if (rc == -1)
{
WRITELOG("%s BrokerRecvTask can't receive a packet from the broker errno=%d %s%s\n", ERRMSG_HEADER, errno, client->getClientId(), ERRMSG_FOOTER);
}
@@ -141,14 +137,14 @@ void BrokerRecvTask::run(void)
}
else if ( rc == -3 )
{
WRITELOG("%s BrokerRecvTask can't create the packet %s%s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG("%s BrokerRecvTask can't get memories for the packet %s%s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
}
delete packet;
/* disconnect the client */
if ( rc == -1 || rc == -2 )
if ( (rc == -1 || rc == -2) && client->isActive() )
{
/* disconnect the client */
packet = new MQTTGWPacket();
packet->setHeader(DISCONNECT);
ev = new Event();
@@ -158,16 +154,11 @@ void BrokerRecvTask::run(void)
}
}
}
nextClient:
client = client->getNextClient();
}
_light->blueLight(false);
}
}
else
{
_light->greenLight(false);
}
maxSock = 0;
}
}
@@ -202,6 +193,7 @@ int BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), LEFTARROW, client->getClientId(), packet->print(pbuf));
break;
default:
WRITELOG("Type=%x\n", packet->getType());
rc = -1;
break;
}