]> git.ipfire.org Git - thirdparty/squid.git/blame - src/StoreIOBuffer.h
NoNewGlobals for MapLabel (#1746)
[thirdparty/squid.git] / src / StoreIOBuffer.h
CommitLineData
c8be6d7b 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
c8be6d7b 3 *
bbc27441
AJ
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.
c8be6d7b 7 */
8
ff9d9458
FC
9#ifndef SQUID_SRC_STOREIOBUFFER_H
10#define SQUID_SRC_STOREIOBUFFER_H
2512d159 11
21dfc374 12#include "base/Range.h"
d0df2779 13#include "MemBuf.h"
c8be6d7b 14
62e76326 15class StoreIOBuffer
16{
17
528b2c61 18public:
aee3523a 19 StoreIOBuffer():length(0), offset (0), data (nullptr) {flags.error = 0;}
62e76326 20
47f6e231 21 StoreIOBuffer(size_t aLength, int64_t anOffset, char *someData) :
f53969cc 22 length (aLength), offset (anOffset), data (someData) {
63326655 23 flags.error = 0;
62e76326 24 }
25
d0df2779 26 /* Create a StoreIOBuffer from a MemBuf and offset */
27 /* NOTE that MemBuf still "owns" the pointers, StoreIOBuffer is just borrowing them */
47f6e231 28 StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset) :
f53969cc
SM
29 length(aMemBuf->contentSize()),
30 offset (anOffset),
31 data(aMemBuf->content()) {
d0df2779 32 flags.error = 0;
33 }
34
0ad2b63b 35 StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset, size_t anLength) :
f53969cc
SM
36 length(anLength),
37 offset (anOffset),
38 data(aMemBuf->content()) {
0ad2b63b
CT
39 flags.error = 0;
40 }
41
26ac0430 42 Range<int64_t> range() const {
47f6e231 43 return Range<int64_t>(offset, offset + length);
2512d159 44 }
45
122a6e3c
AR
46 /// convenience method for changing the offset of a being-configured buffer
47 StoreIOBuffer &positionAt(const int64_t newOffset) { offset = newOffset; return *this; }
48
26ac0430
AJ
49 void dump() const {
50 if (fwrite(data, length, 1, stderr)) {}
51 if (fwrite("\n", 1, 1, stderr)) {}
d0df2779 52 }
53
26ac0430 54 struct {
3d0ac046
HN
55 unsigned error:1;
56 } flags;
c8be6d7b 57 size_t length;
47f6e231 58 int64_t offset;
c8be6d7b 59 char *data;
60};
61
8822ebee
AR
62inline
63std::ostream &
64operator <<(std::ostream &os, const StoreIOBuffer &b)
65{
66 return os << "ioBuf(@" << b.offset << ", len=" << b.length << ", " <<
d9fc6862 67 (void*)b.data << (b.flags.error ? ", ERR" : "") << ')';
8822ebee
AR
68}
69
ff9d9458 70#endif /* SQUID_SRC_STOREIOBUFFER_H */
f53969cc 71