amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
}
- *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
- tcp.sendPacket(sendBuffer, amountReceived + 4);
- log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
+ if (!amountReceived)
+ {
+ sendULONG(0);
+ log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
+ }
+ else
+ {
+ *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
+ tcp.sendPacket(sendBuffer, amountReceived + 4);
+ log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
+ }
return 1;
}
cChannel* channel = channelFromNumber(channelNumber);
if (!channel)
{
- UCHAR sendBuffer[4];
- *(ULONG*)&sendBuffer[0] = htonl(4);
- *(ULONG*)&sendBuffer[4] = htonl(0);
- tcp.sendPacket(sendBuffer, 8);
+ sendULONG(0);
log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
return 1;
}
#endif
if (!Schedules)
{
- UCHAR sendBuffer[8];
- *(ULONG*)&sendBuffer[0] = htonl(4);
- *(ULONG*)&sendBuffer[4] = htonl(0);
- tcp.sendPacket(sendBuffer, 8);
+ sendULONG(0);
log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
return 1;
}
const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
if (!Schedule)
{
- UCHAR sendBuffer[8];
- *(ULONG*)&sendBuffer[0] = htonl(4);
- *(ULONG*)&sendBuffer[4] = htonl(0);
- tcp.sendPacket(sendBuffer, 8);
+ sendULONG(0);
log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
return 1;
}
log->log("Client", Log::DEBUG, "Got all event data");
- // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
- *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
-
- tcp.sendPacket(sendBuffer, sendBufferUsed);
- log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
+ if (sendBufferUsed == sizeof(ULONG))
+ {
+ // No data
+ sendULONG(0);
+ log->log("Client", Log::DEBUG, "Written 0 because no data");
+ }
+ else
+ {
+ // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
+ *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
+ tcp.sendPacket(sendBuffer, sendBufferUsed);
+ log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
+ }
free(sendBuffer);