BugFix: MQTT packets wiith no payload can't be received collectly.

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2017-07-28 14:33:41 +09:00
parent 3425a4d441
commit 7099531e0e
3 changed files with 22 additions and 18 deletions

View File

@@ -204,23 +204,26 @@ int MQTTGWPacket::recv(Network* network)
multiplier *= 128;
} while ((c & 128) != 0);
/* allocate buffer */
_data = (unsigned char*)calloc(_remainingLength, 1);
if ( !_data )
if ( _remainingLength > 0 )
{
return -3;
}
/* allocate buffer */
_data = (unsigned char*)calloc(_remainingLength, 1);
if ( !_data )
{
return -3;
}
/* read Payload */
int remlen = network->recv(_data, _remainingLength);
/* read Payload */
int remlen = network->recv(_data, _remainingLength);
if (remlen == -1 )
{
return -1;
}
else if ( remlen != _remainingLength )
{
return -2;
if (remlen == -1 )
{
return -1;
}
else if ( remlen != _remainingLength )
{
return -2;
}
}
return 1 + len + _remainingLength;
}