diff options
author | Sam Bingner <sam@bingner.com> | 2018-12-26 13:07:23 -1000 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2018-12-26 14:51:59 -1000 |
commit | 59c3e0b998fd69532159d8dc416109cf50651482 (patch) | |
tree | 2e58bef1273e4d3542c168980e4a2d793e170045 /methods/http.h | |
parent | ac0d26d4e39da16bdbf575637fd3d4b24a7fb4b8 (diff) | |
parent | 2aa218273eb6009880e987f90d3e24b8efb04642 (diff) |
Merge nitotv apt fixes into 1.4.81.4.8+nitotv
Diffstat (limited to 'methods/http.h')
-rw-r--r-- | methods/http.h | 98 |
1 files changed, 3 insertions, 95 deletions
diff --git a/methods/http.h b/methods/http.h index c79a6454e..3b491dfda 100644 --- a/methods/http.h +++ b/methods/http.h @@ -26,101 +26,6 @@ class FileFd; class HttpMethod; class Hashes; -class CircleBuf -{ - unsigned char *Buf; - unsigned long long Size; - unsigned long long InP; - unsigned long long OutP; - std::string OutQueue; - unsigned long long StrPos; - unsigned long long MaxGet; - struct timeval Start; - - static unsigned long long BwReadLimit; - static unsigned long long BwTickReadData; - static struct timeval BwReadTick; - static const unsigned int BW_HZ; - - unsigned long long LeftRead() const - { - unsigned long long Sz = Size - (InP - OutP); - if (Sz > Size - (InP%Size)) - Sz = Size - (InP%Size); - return Sz; - } - unsigned long long LeftWrite() const - { - unsigned long long Sz = InP - OutP; - if (InP > MaxGet) - Sz = MaxGet - OutP; - if (Sz > Size - (OutP%Size)) - Sz = Size - (OutP%Size); - return Sz; - } - void FillOut(); - - public: - Hashes *Hash; - // total amount of data that got written so far - unsigned long long TotalWriten; - - // Read data in - bool Read(int Fd); - bool Read(std::string const &Data); - - // Write data out - bool Write(int Fd); - bool WriteTillEl(std::string &Data,bool Single = false); - - // Control the write limit - void Limit(long long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;} - bool IsLimit() const {return MaxGet == OutP;}; - void Print() const {cout << MaxGet << ',' << OutP << endl;}; - - // Test for free space in the buffer - bool ReadSpace() const {return Size - (InP - OutP) > 0;}; - bool WriteSpace() const {return InP - OutP > 0;}; - - void Reset(); - // Dump everything - void Stats(); - - CircleBuf(HttpMethod const * const Owner, unsigned long long Size); - ~CircleBuf(); -}; - -struct HttpServerState: public ServerState -{ - // This is the connection itself. Output is data FROM the server - CircleBuf In; - CircleBuf Out; - int ServerFd; - - protected: - virtual bool ReadHeaderLines(std::string &Data) APT_OVERRIDE; - virtual bool LoadNextResponse(bool const ToFile, RequestState &Req) APT_OVERRIDE; - virtual bool WriteResponse(std::string const &Data) APT_OVERRIDE; - - public: - virtual void Reset() APT_OVERRIDE; - - virtual bool RunData(RequestState &Req) APT_OVERRIDE; - virtual bool RunDataToDevNull(RequestState &Req) APT_OVERRIDE; - - virtual bool Open() APT_OVERRIDE; - virtual bool IsOpen() APT_OVERRIDE; - virtual bool Close() APT_OVERRIDE; - virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE; - virtual Hashes * GetHashes() APT_OVERRIDE; - virtual bool Die(RequestState &Req) APT_OVERRIDE; - virtual bool Flush(FileFd * const File) APT_OVERRIDE; - virtual bool Go(bool ToFile, RequestState &Req) APT_OVERRIDE; - - HttpServerState(URI Srv, HttpMethod *Owner); - virtual ~HttpServerState() {Close();}; -}; - class HttpMethod : public BaseHttpMethod { public: @@ -132,10 +37,13 @@ class HttpMethod : public BaseHttpMethod protected: std::string AutoDetectProxyCmd; + FileFd *File; public: friend struct HttpServerState; + int Loop(); + explicit HttpMethod(std::string &&pProg); }; |