StoreIOBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_STOREIOBUFFER_H
10 #define SQUID_SRC_STOREIOBUFFER_H
11 
12 #include "base/Range.h"
13 #include "MemBuf.h"
14 
16 {
17 
18 public:
19  StoreIOBuffer():length(0), offset (0), data (nullptr) {flags.error = 0;}
20 
21  StoreIOBuffer(size_t aLength, int64_t anOffset, char *someData) :
22  length (aLength), offset (anOffset), data (someData) {
23  flags.error = 0;
24  }
25 
26  /* Create a StoreIOBuffer from a MemBuf and offset */
27  /* NOTE that MemBuf still "owns" the pointers, StoreIOBuffer is just borrowing them */
28  StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset) :
29  length(aMemBuf->contentSize()),
30  offset (anOffset),
31  data(aMemBuf->content()) {
32  flags.error = 0;
33  }
34 
35  StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset, size_t anLength) :
36  length(anLength),
37  offset (anOffset),
38  data(aMemBuf->content()) {
39  flags.error = 0;
40  }
41 
44  }
45 
47  StoreIOBuffer &positionAt(const int64_t newOffset) { offset = newOffset; return *this; }
48 
49  void dump() const {
50  if (fwrite(data, length, 1, stderr)) {}
51  if (fwrite("\n", 1, 1, stderr)) {}
52  }
53 
54  struct {
55  unsigned error:1;
56  } flags;
57  size_t length;
58  int64_t offset;
59  char *data;
60 };
61 
62 inline
63 std::ostream &
64 operator <<(std::ostream &os, const StoreIOBuffer &b)
65 {
66  return os << "ioBuf(@" << b.offset << ", len=" << b.length << ", " <<
67  (void*)b.data << (b.flags.error ? ", ERR" : "") << ')';
68 }
69 
70 #endif /* SQUID_SRC_STOREIOBUFFER_H */
71 
struct StoreIOBuffer::@130 flags
Range< int64_t > range() const
Definition: StoreIOBuffer.h:42
StoreIOBuffer(size_t aLength, int64_t anOffset, char *someData)
Definition: StoreIOBuffer.h:21
int64_t offset
Definition: StoreIOBuffer.h:58
StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset, size_t anLength)
Definition: StoreIOBuffer.h:35
StoreIOBuffer & positionAt(const int64_t newOffset)
convenience method for changing the offset of a being-configured buffer
Definition: StoreIOBuffer.h:47
StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset)
Definition: StoreIOBuffer.h:28
Definition: Range.h:18
Definition: MemBuf.h:23
unsigned error
Definition: StoreIOBuffer.h:55
void dump() const
Definition: StoreIOBuffer.h:49
std::ostream & operator<<(std::ostream &os, const StoreIOBuffer &b)
Definition: StoreIOBuffer.h:64

 

Introduction

Documentation

Support

Miscellaneous