I am reading from a binary file.
char bigbuf[5000];
while (read(fd, bigbuf, 2) != 0) {
uint16_t packetSize = htons(*(uint16_t *)bigbuf);
read(fd, bigbuf + 2, packetSize - 2);
myParser.onUDPPacket(bigbuf, packetSize);
}
The packets are written in binary file are of 40 bytes, but inside onUDPPacket function I receive a packet of 61 bytes then on the second call I again receive a 60 byte packet. Now I have to write the function onUDPPacket such that on the first call it processes 40 byte of data from the 61 byte received and it has to append remaining 21 bytes in the starting of the next 60 byte of packet. How do I do this append thing ?
void Parser::onUDPPacket(const char *buf, size_t len)
{
}
Aucun commentaire:
Enregistrer un commentaire