Remove the nested read loops in FastCGIConn, hide complexity inside StreamBuffer

This commit is contained in:
Ian Gulliver
2019-04-28 17:50:44 +00:00
parent 323cfc15a5
commit 45e5570959
10 changed files with 73 additions and 51 deletions

View File

@@ -8,23 +8,19 @@ class ConstBuffer {
ConstBuffer(const char *buf, size_t len);
[[nodiscard]] size_t ReadMaxLen() const;
[[nodiscard]] const char *Read(size_t len);
[[nodiscard]] virtual const char *Read(size_t len);
template<class T> [[nodiscard]] const T *ReadObj();
bool Discard(size_t len); // like Read() but don't use the result
void ResetRead(); // next read from last commit
void Commit(); // commit read position
protected:
const char *const_buf_;
size_t len_;
size_t start_ = 0;
size_t commit_ = 0;
};
class Buffer : public ConstBuffer {
public:
Buffer(const char *buf, size_t len) = delete;
Buffer(char *buf, size_t size, size_t len);
Buffer(size_t size);
@@ -32,9 +28,9 @@ class Buffer : public ConstBuffer {
[[nodiscard]] size_t WriteMaxLen() const;
void Wrote(size_t len);
void Consume(); // discard up to last commit
void Commit(); // commit read position
private:
protected:
std::unique_ptr<char> own_buf_;
char *buf_;
const size_t size_;