diff --git a/include/socketserver.h b/include/socketserver.h index 44ccda1e..c71ed34b 100644 --- a/include/socketserver.h +++ b/include/socketserver.h @@ -29,31 +29,32 @@ //--------------------------------------------------------------------------- #pragma once -#include -#include -#include -#include -#include -#include -#include -#include #include "ledbuffer.h" +#include +#include +#include +#include +#include +#include +#include +#include + extern "C" { #include "uzlib/src/uzlib.h" } -#define STANDARD_DATA_HEADER_SIZE 24 // Size of the header for expanded data -#define COMPRESSED_HEADER_SIZE 16 // Size of the header for compressed data -#define LED_DATA_SIZE sizeof(CRGB) // Data size of an LED (24 bits or 3 bytes) +#define STANDARD_DATA_HEADER_SIZE 24 // Size of the header for expanded data +#define COMPRESSED_HEADER_SIZE 16 // Size of the header for compressed data +#define LED_DATA_SIZE sizeof(CRGB) // Data size of an LED (24 bits or 3 bytes) -// We allocate whatever the max packet is, and use it to validate incoming packets, so right now it's set to the maxiumum +// We allocate whatever the max packet is, and use it to validate incoming packets, so right now it's set to the maximum // LED data packet you could have (header plus 3 RGBs per NUM_LED) #define MAXIMUM_PACKET_SIZE (STANDARD_DATA_HEADER_SIZE + LED_DATA_SIZE * NUM_LEDS) // Header plus 24 bits per actual LED -#define COMPRESSED_HEADER (0x44415645) // asci "DAVE" as header +#define COMPRESSED_HEADER (0x44415645) // ASCII "DAVE" as header bool ProcessIncomingData(std::unique_ptr & payloadData, size_t payloadLength); @@ -61,7 +62,7 @@ bool ProcessIncomingData(std::unique_ptr & payloadData, size_t paylo // SocketResponse // -// Response data sent back to server ever time we receive a packet +// Response data sent back to server every time we receive a packet struct SocketResponse { uint32_t size; // 4 @@ -139,7 +140,7 @@ class SocketServer return false; } - // When an error occurs and we close and reopen the port, we need to specify reuse flags + // When an error occurs, and we close and reopen the port, we need to specify reuse flags // or it might be too soon to use the port again, since close doesn't actually close it // until the socket is no longer in use. @@ -206,7 +207,7 @@ class SocketServer // Read data from the socket until we have _bcNeeded bytes in the buffer int cbRead = 0; - do + do { cbRead = read(socket, (uint8_t *) _pBuffer.get() + _cbReceived, cbNeeded - _cbReceived); } while (cbRead < 0 && errno == EINTR); @@ -237,12 +238,12 @@ class SocketServer // // Use unzlib to decompress a memory buffer - bool DecompressBuffer(const uint8_t * pBuffer, size_t cBuffer, uint8_t * pOutput, size_t expectedOutputSize) const + static bool DecompressBuffer(const uint8_t * pBuffer, size_t cBuffer, uint8_t * pOutput, size_t expectedOutputSize) { debugV("Compressed Data: %02X %02X %02X %02X...", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); struct uzlib_uncomp d = { 0 }; - uzlib_uncompress_init(&d, NULL, 0); + uzlib_uncompress_init(&d, nullptr, 0); d.source = pBuffer; d.source_limit = pBuffer + cBuffer;