GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/network/sink.h
Date: 2025-06-22 02:36:02
Exec Total Coverage
Lines: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_NETWORK_SINK_H_
6 #define CVMFS_NETWORK_SINK_H_
7
8 #include <stdint.h>
9
10 #include <string>
11
12 namespace cvmfs {
13
14 /**
15 * A data sink that behaves like a writable file descriptor with a custom
16 * implementation.
17 */
18 class Sink {
19 protected:
20 9071 explicit Sink(bool is_owner) : is_owner_(is_owner) { }
21
22 public:
23 18142 virtual ~Sink() { }
24 /**
25 * Appends data to the sink
26 *
27 * @returns on success: number of bytes written (can be less than requested)
28 * on failure: -errno.
29 */
30 virtual int64_t Write(const void *buf, uint64_t sz) = 0;
31
32 /**
33 * Truncate all written data and start over at position zero.
34 *
35 * @returns Success = 0
36 * Failure = -errno
37 */
38 virtual int Reset() = 0;
39
40 /**
41 * Purges all resources leaving the sink in an invalid state.
42 * More aggressive version of Reset().
43 * For some sinks and depending on owner status it might do
44 * the same as Reset().
45 *
46 * @returns Success = 0
47 * Failure = -errno
48 */
49 virtual int Purge() = 0;
50
51 /**
52 * @returns true if the object is correctly initialized.
53 */
54 virtual bool IsValid() = 0;
55
56 /**
57 * Release ownership of the sink's resource
58 */
59 3182 void Release() { is_owner_ = false; }
60
61 /**
62 * Commit data to the sink
63 * @returns Success = 0
64 * Failure = -errno
65 */
66 virtual int Flush() = 0;
67
68 /**
69 * Reserves new space in sinks that require reservation (see RequiresReserve)
70 *
71 * Successful if the requested size is smaller than already space reserved, or
72 * if the sink is the owner of the data and can allocate enough new space.
73 *
74 * @note If successful, always resets the current position to 0.
75 *
76 * Fails if
77 * 1) sink is not the owner of the data and more than the current size is
78 * requested
79 * 2) more space is requested than allowed (max_size_)
80 *
81 * @returns success = true
82 * failure = false
83 */
84 virtual bool Reserve(size_t size) = 0;
85
86 /**
87 * Returns if the specific sink type needs reservation of (data) space
88 *
89 * @returns true - reservation is needed
90 * false - no reservation is needed
91 */
92 virtual bool RequiresReserve() = 0;
93
94 /**
95 * Return a string representation describing the type of sink and its status
96 */
97 virtual std::string Describe() = 0;
98
99 protected:
100 bool is_owner_;
101 };
102
103 } // namespace cvmfs
104
105 #endif // CVMFS_NETWORK_SINK_H_
106