From ee4c05de3061d1d7abfd1710823442cbc0cfbf46 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 5 Jul 2008 23:40:07 +0200 Subject: [PATCH] add method to ensure buffer capacity --- CollectionReader.cpp | 12 ++++++++++++ CollectionReader.h | 1 + 2 files changed, 13 insertions(+) diff --git a/CollectionReader.cpp b/CollectionReader.cpp index 4aa5173..f58e5bc 100644 --- a/CollectionReader.cpp +++ b/CollectionReader.cpp @@ -71,6 +71,18 @@ ED2KLink* CollectionReader::getNextLink() { return NULL; } +bool CollectionReader::ensureBufferCapacity(size_t byteCount) { + while (!readerInput->isEOF() && (growingBuffer.getRemaining() < byteCount)) { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] only %d bytes remaning, need at least %d, reading more bytes.\n", __FILE__, __LINE__, growingBuffer.getRemaining(), byteCount); + readMoreBytes(); + } + if (readerInput->isEOF() && (growingBuffer.getRemaining() < byteCount)) { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] need %d more bytes, but file is EOF.\n", __FILE__, __LINE__, (byteCount - growingBuffer.getRemaining())); + return false; + } + return true; +} + void CollectionReader::readMoreBytes() { char buffer[1024]; size_t readBytes; diff --git a/CollectionReader.h b/CollectionReader.h index ef71c72..72f652a 100644 --- a/CollectionReader.h +++ b/CollectionReader.h @@ -19,6 +19,7 @@ public: private: void identifyCollectionType(); bool isLineBreakPresent(); + bool ensureBufferCapacity(size_t byteCount); void readMoreBytes(); private: -- 2.7.4