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 @@
#include <vector>
#include <sstream>
#include <algorithm>
#include <memory>
#include <sys/timerfd.h>
......@@ -699,7 +700,7 @@ namespace Private {
State parse();
ArrayStreamBuf<Const::MaxBuffer> buffer;
ArrayStreamBuf<char> buffer;
StreamCursor cursor;
protected:
......
......@@ -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> {
public:
typedef StreamBuf<CharT> Base;
ArrayStreamBuf()
: size(0)
{
memset(bytes, 0, N);
Base::setg(bytes, bytes, bytes + N);
bytes.clear();
Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
}
template<size_t M>
ArrayStreamBuf(char (&arr)[M]) {
static_assert(M <= N, "Source array exceeds maximum capacity");
memcpy(bytes, arr, M);
size = M;
Base::setg(bytes, bytes, bytes + M);
bytes.clear();
std::copy(arr, arr + M, std::back_inserter(bytes));
Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
}
bool feed(const char* data, size_t len) {
if (size + len > N) {
return false;
}
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;
std::copy(data, data + len, std::back_inserter(bytes));
Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
return true;
}
void reset() {
memset(bytes, 0, N);
size = 0;
Base::setg(bytes, bytes, bytes);
bytes.clear();
Base::setg(bytes.data(), bytes.data(), bytes.data());
}
private:
char bytes[N];
size_t size;
std::vector<CharT> bytes;
};
struct Buffer {
......
......@@ -356,7 +356,7 @@ Transport::handleIncoming(const std::shared_ptr<Connection>& connection) {
else {
totalBytes += bytes;
if (totalBytes > Const::MaxBuffer) {
std::cerr << "Too long packet" << std::endl;
std::cerr << "Client: Too long packet" << std::endl;
break;
}
}
......
......@@ -150,11 +150,9 @@ Transport::handleIncoming(const std::shared_ptr<Peer>& peer) {
}
else {
totalBytes += bytes;
if (totalBytes >= Const::MaxBuffer) {
std::cerr << "Too long packet" << std::endl;
break;
}
//totalBytes += bytes;
handler_->onInput(buffer, bytes, peer);
//if (totalBytes >= Const::MaxBuffer) { std::cerr << "Transport: Too long packet" << std::endl; 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