CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cvmfs::MemSink Class Reference

#include <sink_mem.h>

Inheritance diagram for cvmfs::MemSink:
Collaboration diagram for cvmfs::MemSink:

Public Member Functions

 MemSink ()
 
 MemSink (size_t size)
 
virtual ~MemSink ()
 
virtual int64_t Write (const void *buf, uint64_t sz)
 
virtual int Reset ()
 
virtual int Purge ()
 
virtual bool IsValid ()
 
virtual int Flush ()
 
virtual bool Reserve (size_t size)
 
virtual bool RequiresReserve ()
 
virtual std::string Describe ()
 
void Adopt (size_t size, size_t pos, unsigned char *data, bool is_owner=true)
 
size_t size ()
 
size_t pos ()
 
unsigned char * data ()
 
- Public Member Functions inherited from cvmfs::Sink
virtual ~Sink ()
 
void Release ()
 

Static Public Attributes

static const size_t kMaxMemSize = 1024ul * 1024ul
 

Private Member Functions

void FreeData ()
 

Private Attributes

size_t size_
 
size_t pos_
 
unsigned char * data_
 
const size_t max_size_
 

Additional Inherited Members

- Protected Member Functions inherited from cvmfs::Sink
 Sink (bool is_owner)
 
- Protected Attributes inherited from cvmfs::Sink
bool is_owner_
 

Detailed Description

MemSink is a data sink that writes to a unsigned char* buffer. The buffer has a fixed size, as such reservation of space is necessary. It can use Adopt() to write to a different buffer.

By default, MemSink is the owner of the buffer and takes care of its creation and deletion.

Definition at line 27 of file sink_mem.h.

Constructor & Destructor Documentation

cvmfs::MemSink::MemSink ( )
inline

Definition at line 29 of file sink_mem.h.

cvmfs::MemSink::MemSink ( size_t  size)
explicit

Definition at line 16 of file sink_mem.cc.

virtual cvmfs::MemSink::~MemSink ( )
inlinevirtual

Definition at line 32 of file sink_mem.h.

Here is the call graph for this function:

Member Function Documentation

void cvmfs::MemSink::Adopt ( size_t  size,
size_t  pos,
unsigned char *  data,
bool  is_owner = true 
)

Allows the sink to adopt data that was initialized outside this class. The sink can become the new owner of the data, or not.

Definition at line 123 of file sink_mem.cc.

Here is the call graph for this function:

unsigned char* cvmfs::MemSink::data ( )
inline
std::string cvmfs::MemSink::Describe ( )
virtual

Return a string representation describing the type of sink and its status

Implements cvmfs::Sink.

Definition at line 112 of file sink_mem.cc.

Here is the call graph for this function:

virtual int cvmfs::MemSink::Flush ( )
inlinevirtual

Commit data to the sink

Returns
success = 0 failure = -errno

Implements cvmfs::Sink.

Definition at line 76 of file sink_mem.h.

void cvmfs::MemSink::FreeData ( )
inlineprivate

Definition at line 130 of file sink_mem.h.

Referenced by Adopt(), Reserve(), and ~MemSink().

Here is the caller graph for this function:

bool cvmfs::MemSink::IsValid ( )
virtual
Returns
true if the object is correctly initialized.

Implements cvmfs::Sink.

Definition at line 67 of file sink_mem.cc.

size_t cvmfs::MemSink::pos ( )
inline
virtual int cvmfs::MemSink::Purge ( )
inlinevirtual

Purges all resources leaving the sink in an invalid state. More aggressive version of Reset(). For some sinks and depending on owner status it might do the same as Reset().

Returns
Success = 0 Failure = -errno

Implements cvmfs::Sink.

Definition at line 62 of file sink_mem.h.

Here is the call graph for this function:

virtual bool cvmfs::MemSink::RequiresReserve ( )
inlinevirtual

Returns if the specific sink type needs reservation of (data) space

Returns
true - reservation is needed false - no reservation is needed

Implements cvmfs::Sink.

Definition at line 104 of file sink_mem.h.

bool cvmfs::MemSink::Reserve ( size_t  size)
virtual

Reserves new space in sinks that require reservation (see RequiresReserve)

Successful if the requested size is smaller than already space reserved, or if the sink is the owner of the data and can allocate enough new space.

Note
If successful, always resets the current position to 0.

Fails if 1) sink is not the owner of the data and more than the current size is requested 2) more space is requested than allowed (max_size_)

Returns
success = true failure = false

Implements cvmfs::Sink.

Definition at line 88 of file sink_mem.cc.

Here is the call graph for this function:

int cvmfs::MemSink::Reset ( )
virtual

Truncate all written data and start over at position zero.

Returns
Success = 0 Failure = -errno

Implements cvmfs::Sink.

Definition at line 52 of file sink_mem.cc.

Referenced by download::DownloadManager::ProbeHosts(), and Purge().

Here is the caller graph for this function:

size_t cvmfs::MemSink::size ( )
inline

Definition at line 120 of file sink_mem.h.

Referenced by Adopt(), and Reserve().

Here is the caller graph for this function:

int64_t cvmfs::MemSink::Write ( const void *  buf,
uint64_t  sz 
)
virtual

Appends data to the sink If the sink is too small and

  • the sink is the owner of data_: sink size is increased
  • the sink is NOT the owner of data_: fails with -ENOSPC
Returns
on success: number of bytes written (can be less than requested) on failure: -errno.

Appends data to the sink If the sink is too small and

  • the sink is the owner of data_: sink size is doubled
  • the sink is NOT the owner of data_: fails with -ENOSPC
Returns
on success: number of bytes written on failure: -errno.

Implements cvmfs::Sink.

Definition at line 30 of file sink_mem.cc.

Member Data Documentation

unsigned char* cvmfs::MemSink::data_
private

Definition at line 138 of file sink_mem.h.

Referenced by Adopt(), data(), FreeData(), IsValid(), MemSink(), Reserve(), Reset(), and Write().

const size_t cvmfs::MemSink::kMaxMemSize = 1024ul * 1024ul
static

Do not download files larger than 1M into memory.

Definition at line 127 of file sink_mem.h.

const size_t cvmfs::MemSink::max_size_
private

Definition at line 139 of file sink_mem.h.

Referenced by Reserve().

size_t cvmfs::MemSink::pos_
private

Definition at line 137 of file sink_mem.h.

Referenced by Adopt(), Describe(), IsValid(), pos(), Reserve(), Reset(), and Write().

size_t cvmfs::MemSink::size_
private

Definition at line 136 of file sink_mem.h.

Referenced by Adopt(), Describe(), IsValid(), Reserve(), Reset(), size(), and Write().


The documentation for this class was generated from the following files: