X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=httpinput.cpp;h=68b91708e7b3059eeac08d3d62088daae2d90aa4;hp=80daa1a8a220e1b5b4d93ca3be99145dc2f35854;hb=c2080e598ec887ac7b087dbc287c42a14881d667;hpb=979a284b4039b0ea74525b700b9f1089b8c4248d diff --git a/httpinput.cpp b/httpinput.cpp index 80daa1a..68b9170 100644 --- a/httpinput.cpp +++ b/httpinput.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include "parse.h" #include "serverpool.h" #include "state.pb.h" +#include "stream.h" #include "util.h" #include "version.h" @@ -77,13 +79,6 @@ HTTPInput::HTTPInput(const InputProto &serialized) string protocol; parse_url(url, &protocol, &host, &port, &path); // Don't care if it fails. - // Older versions stored the extra \r\n in the HTTP header. - // Strip it if we find it. - if (http_header.size() >= 4 && - memcmp(http_header.data() + http_header.size() - 4, "\r\n\r\n", 4) == 0) { - http_header.resize(http_header.size() - 2); - } - pthread_mutex_init(&stats_mutex, NULL); stats.url = url; stats.bytes_received = serialized.bytes_received(); @@ -535,16 +530,17 @@ void HTTPInput::process_data(char *ptr, size_t bytes) } // Now it's safe to read the header. - metacube2_block_header *hdr = reinterpret_cast(pending_data.data()); - assert(memcmp(hdr->sync, METACUBE2_SYNC, sizeof(hdr->sync)) == 0); - uint32_t size = ntohl(hdr->size); - uint16_t flags = ntohs(hdr->flags); - uint16_t expected_csum = metacube2_compute_crc(hdr); - - if (expected_csum != ntohs(hdr->csum)) { + metacube2_block_header hdr; + memcpy(&hdr, pending_data.data(), sizeof(hdr)); + assert(memcmp(hdr.sync, METACUBE2_SYNC, sizeof(hdr.sync)) == 0); + uint32_t size = ntohl(hdr.size); + uint16_t flags = ntohs(hdr.flags); + uint16_t expected_csum = metacube2_compute_crc(&hdr); + + if (expected_csum != ntohs(hdr.csum)) { log(WARNING, "[%s] Metacube checksum failed (expected 0x%x, got 0x%x), " "not reading block claiming to be %d bytes (flags=%x).", - url.c_str(), expected_csum, ntohs(hdr->csum), + url.c_str(), expected_csum, ntohs(hdr.csum), size, flags); // Drop only the first byte, and let the rest of the code handle resync.