1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_STMEM_H
10 #define SQUID_STMEM_H
11 
12 #include "Range.h"
13 #include "splay.h"
14 
15 class mem_node;
16 
17 class StoreIOBuffer;
18 
19 class mem_hdr
20 {
21 
22 public:
23     mem_hdr();
24     ~mem_hdr();
25     void freeContent();
26     int64_t lowestOffset () const;
27     int64_t endOffset () const;
28     int64_t freeDataUpto (int64_t);
29     ssize_t copy (StoreIOBuffer const &) const;
30     bool hasContigousContentRange(Range<int64_t> const &range) const;
31     /* success or fail */
32     bool write (StoreIOBuffer const &);
33     void dump() const;
34     size_t size() const;
35     /* Not an iterator - thus the start, not begin() */
36     mem_node const *start() const;
37     mem_node *getBlockContainingLocation (int64_t location) const;
38     /* access the contained nodes - easier than punning
39      * as a contianer ourselves
40      */
41     const Splay<mem_node *> &getNodes() const;
42     char * NodeGet(mem_node * aNode);
43 
44     /* Only for use of MemObject */
45     void internalAppend(const char *data, int len);
46 
47     static Splay<mem_node *>::SPLAYCMP NodeCompare;
48 
49 private:
50     void debugDump() const;
51     bool unlink(mem_node *aNode);
52     void makeAppendSpace();
53     int appendToNode(mem_node *aNode, const char *data, int maxLength);
54     void appendNode (mem_node *aNode);
55     size_t copyAvailable(mem_node *aNode, int64_t location, size_t amount, char *target) const;
56     bool unionNotEmpty (StoreIOBuffer const &);
57     mem_node *nodeToRecieve(int64_t offset);
58     size_t writeAvailable(mem_node *aNode, int64_t location, size_t amount, char const *source);
59     int64_t inmem_hi;
60     Splay<mem_node *> nodes;
61 };
62 
63 #endif /* SQUID_STMEM_H */
64 
65