Commit f682f809 authored by Ian Roddis's avatar Ian Roddis

Moving to dynamic ingestion buffer on the heap to accept larger files.

parent efe54d9e
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <memory>
#include <sys/timerfd.h> #include <sys/timerfd.h>
...@@ -699,7 +700,7 @@ namespace Private { ...@@ -699,7 +700,7 @@ namespace Private {
State parse(); State parse();
ArrayStreamBuf<Const::MaxBuffer> buffer; ArrayStreamBuf<char> buffer;
StreamCursor cursor; StreamCursor cursor;
protected: protected:
......
...@@ -76,54 +76,38 @@ public: ...@@ -76,54 +76,38 @@ public:
}; };
template<size_t N, typename CharT = char> // Make the buffer dynamic
template<typename CharT = char>
class ArrayStreamBuf : public StreamBuf<CharT> { class ArrayStreamBuf : public StreamBuf<CharT> {
public: public:
typedef StreamBuf<CharT> Base; typedef StreamBuf<CharT> Base;
ArrayStreamBuf() ArrayStreamBuf()
: size(0)
{ {
memset(bytes, 0, N); bytes.clear();
Base::setg(bytes, bytes, bytes + N); Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
} }
template<size_t M> template<size_t M>
ArrayStreamBuf(char (&arr)[M]) { ArrayStreamBuf(char (&arr)[M]) {
static_assert(M <= N, "Source array exceeds maximum capacity"); bytes.clear();
memcpy(bytes, arr, M); std::copy(arr, arr + M, std::back_inserter(bytes));
size = M; Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
Base::setg(bytes, bytes, bytes + M);
} }
bool feed(const char* data, size_t len) { bool feed(const char* data, size_t len) {
if (size + len > N) { std::copy(data, data + len, std::back_inserter(bytes));
return false; Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
}
memcpy(bytes + size, data, len);
CharT *cur = nullptr;
if (this->gptr()) {
cur = this->gptr();
} else {
cur = bytes + size;
}
Base::setg(bytes, cur, bytes + size + len);
size += len;
return true; return true;
} }
void reset() { void reset() {
memset(bytes, 0, N); bytes.clear();
size = 0; Base::setg(bytes.data(), bytes.data(), bytes.data());
Base::setg(bytes, bytes, bytes);
} }
private: private:
char bytes[N]; std::vector<CharT> bytes;
size_t size;
}; };
struct Buffer { struct Buffer {
......
...@@ -356,7 +356,7 @@ Transport::handleIncoming(const std::shared_ptr<Connection>& connection) { ...@@ -356,7 +356,7 @@ Transport::handleIncoming(const std::shared_ptr<Connection>& connection) {
else { else {
totalBytes += bytes; totalBytes += bytes;
if (totalBytes > Const::MaxBuffer) { if (totalBytes > Const::MaxBuffer) {
std::cerr << "Too long packet" << std::endl; std::cerr << "Client: Too long packet" << std::endl;
break; break;
} }
} }
......
...@@ -150,11 +150,9 @@ Transport::handleIncoming(const std::shared_ptr<Peer>& peer) { ...@@ -150,11 +150,9 @@ Transport::handleIncoming(const std::shared_ptr<Peer>& peer) {
} }
else { else {
totalBytes += bytes; //totalBytes += bytes;
if (totalBytes >= Const::MaxBuffer) { handler_->onInput(buffer, bytes, peer);
std::cerr << "Too long packet" << std::endl; //if (totalBytes >= Const::MaxBuffer) { std::cerr << "Transport: Too long packet" << std::endl; break; }
break;
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment