libktorrent  2.2.0
Public Types | Public Member Functions | List of all members
bt::PieceData Class Reference

#include <piecedata.h>

Inheritance diagram for bt::PieceData:
Inheritance graph
[legend]

Public Types

typedef QExplicitlySharedDataPointer< PieceDataPtr
 

Public Member Functions

 PieceData (Chunk *chunk, Uint32 off, Uint32 len, Uint8 *ptr, CacheFile::Ptr cache_file, bool read_only)
 
Uint8 * data ()
 Get a pointer to the data.
 
SHA1Hash generateHash () const
 
bool inUse () const
 Is the piece in use by somebody else then the cache.
 
Uint32 length () const
 Get the length of the piece.
 
bool mapped () const
 Is it a mapped into memory.
 
Uint32 offset () const
 Get the offset of the piece in the chunk.
 
bool ok () const
 Check if the data pointer is OK.
 
ChunkparentChunk ()
 Get the parent chunk of the piece.
 
Uint32 read (Uint8 *buf, Uint32 to_read, Uint32 off=0)
 
Uint32 readFromFile (File &file, Uint32 size, Uint32 off=0)
 
void setData (Uint8 *p)
 Set the data pointer.
 
void unload ()
 Unload the piece.
 
void updateHash (SHA1HashGen &hg)
 
Uint32 write (const Uint8 *buf, Uint32 buf_size, Uint32 off=0)
 
bool writeable () const
 Is this writeable.
 
Uint32 writeToFile (File &file, Uint32 size, Uint32 off=0)
 

Detailed Description

Class which holds the data of a piece of a chunk. It has a reference counter.

Definition at line 45 of file piecedata.h.

Member Function Documentation

◆ generateHash()

SHA1Hash bt::PieceData::generateHash ( ) const

Generate a SHA1Hash of this PieceData. This function protects against bus errors.

Returns
The SHA1 hash
Exceptions
BusErrorWhen reading results in a SIGBUS

◆ read()

Uint32 bt::PieceData::read ( Uint8 *  buf,
Uint32  to_read,
Uint32  off = 0 
)

Read data from the PieceData. This function should always be used for reading from a PieceData object, as it protects against bus errors.

Parameters
bufThe buffer to read into
to_readAmount of bytes to read
offOffset in the PieceData to start reading from
Returns
The number of bytes read
Exceptions
BusErrorWhen reading results in a SIGBUS

◆ readFromFile()

Uint32 bt::PieceData::readFromFile ( File file,
Uint32  size,
Uint32  off = 0 
)

Read PieceData from a File. This function protects against bus errors.

Parameters
fileThe file to read from
sizeSize to read
offOffset in PieceData to write into
Returns
The number of bytes read
Exceptions
BusErrorWhen reading results in a SIGBUS

◆ updateHash()

void bt::PieceData::updateHash ( SHA1HashGen hg)

Update a SHA1HashGen with this PieceData. This function protects against bus errors.

Parameters
hgThe SHA1HashGen to update
Exceptions
BusErrorWhen reading results in a SIGBUS

◆ write()

Uint32 bt::PieceData::write ( const Uint8 *  buf,
Uint32  buf_size,
Uint32  off = 0 
)

Write data into the PieceData. This function should always be used for writing into a PieceData object, as it protects against bus errors.

Parameters
bufThe buffer to write
sizeSize of the buffer
offOffset to write
Returns
The number of bytes written
Exceptions
BusErrorWhen writing results in a SIGBUS

◆ writeToFile()

Uint32 bt::PieceData::writeToFile ( File file,
Uint32  size,
Uint32  off = 0 
)

Save PieceData to a File. This function protects against bus errors.

Parameters
fileThe file to write to
sizeSize to write
offOffset in PieceData to write from
Returns
The number of bytes written
Exceptions
BusErrorWhen writing results in a SIGBUS

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