Mana
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Net::Download Class Reference

#include <download.h>

Classes

struct  State
 

Public Member Functions

 Download (const std::string &url)
 
 ~Download ()
 
void addHeader (const char *header)
 
void noCache ()
 Convience method for adding no-cache headers.
 
void setFile (const std::string &filename, std::optional< unsigned long > adler32={})
 
void setUseBuffer ()
 
bool start ()
 Starts the download thread.
 
void cancel ()
 Cancels the download.
 
std::string_view getBuffer () const
 Returns a view on the downloaded data.
 
State getState ()
 
const char * getError () const
 

Static Public Member Functions

static unsigned long fadler32 (FILE *file)
 Calculates the Alder-32 checksum for the given file.
 

Static Private Member Functions

static int downloadProgress (void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
 A libcurl callback for reporting progress.
 
static size_t writeBuffer (char *ptr, size_t size, size_t nmemb, void *stream)
 A libcurl callback for writing to memory.
 
static int downloadThread (void *ptr)
 

Private Attributes

ThreadSafe< StatemState
 
std::string mUrl
 
bool mCancel = false
 
bool mMemoryWrite = false
 
std::string mFileName
 
std::optional< unsigned long > mAdler
 
SDL_Thread * mThread = nullptr
 
curl_slist * mHeaders = nullptr
 
char mError [CURL_ERROR_SIZE]
 
size_t mDownloadedBytes = 0
 Byte count currently downloaded in mMemoryBuffer.
 
char * mBuffer = nullptr
 Buffer for files downloaded to memory.
 

Detailed Description

Definition at line 43 of file download.h.

Constructor & Destructor Documentation

◆ Download()

Net::Download::Download ( const std::string &  url)

Definition at line 62 of file download.cpp.

◆ ~Download()

Net::Download::~Download ( )

Definition at line 68 of file download.cpp.

Member Function Documentation

◆ addHeader()

void Net::Download::addHeader ( const char *  header)

Definition at line 77 of file download.cpp.

◆ cancel()

void Net::Download::cancel ( )

Cancels the download.

Returns immediately, the canceled status will be noted in the next available update call.

Definition at line 126 of file download.cpp.

◆ downloadProgress()

int Net::Download::downloadProgress ( void *  clientp,
curl_off_t  dltotal,
curl_off_t  dlnow,
curl_off_t  ultotal,
curl_off_t  ulnow 
)
staticprivate

A libcurl callback for reporting progress.

Definition at line 141 of file download.cpp.

◆ downloadThread()

int Net::Download::downloadThread ( void *  ptr)
staticprivate

Definition at line 174 of file download.cpp.

◆ fadler32()

unsigned long Net::Download::fadler32 ( FILE *  file)
static

Calculates the Alder-32 checksum for the given file.

Definition at line 41 of file download.cpp.

◆ getBuffer()

std::string_view Net::Download::getBuffer ( ) const

Returns a view on the downloaded data.

Definition at line 132 of file download.cpp.

◆ getError()

const char * Net::Download::getError ( ) const
inline

Definition at line 122 of file download.h.

◆ getState()

Download::State Net::Download::getState ( )
inline

Definition at line 117 of file download.h.

◆ noCache()

void Net::Download::noCache ( )

Convience method for adding no-cache headers.

Definition at line 84 of file download.cpp.

◆ setFile()

void Net::Download::setFile ( const std::string &  filename,
std::optional< unsigned long >  adler32 = {} 
)

Definition at line 90 of file download.cpp.

◆ setUseBuffer()

void Net::Download::setUseBuffer ( )

Definition at line 100 of file download.cpp.

◆ start()

bool Net::Download::start ( )

Starts the download thread.

Returns
whether the thread could be created

Definition at line 107 of file download.cpp.

◆ writeBuffer()

size_t Net::Download::writeBuffer ( char *  ptr,
size_t  size,
size_t  nmemb,
void *  stream 
)
staticprivate

A libcurl callback for writing to memory.

Definition at line 159 of file download.cpp.

Member Data Documentation

◆ mAdler

std::optional<unsigned long> Net::Download::mAdler
private

Definition at line 105 of file download.h.

◆ mBuffer

char* Net::Download::mBuffer = nullptr
private

Buffer for files downloaded to memory.

Definition at line 114 of file download.h.

◆ mCancel

bool Net::Download::mCancel = false
private

Definition at line 102 of file download.h.

◆ mDownloadedBytes

size_t Net::Download::mDownloadedBytes = 0
private

Byte count currently downloaded in mMemoryBuffer.

Definition at line 111 of file download.h.

◆ mError

char Net::Download::mError[CURL_ERROR_SIZE]
private

Definition at line 108 of file download.h.

◆ mFileName

std::string Net::Download::mFileName
private

Definition at line 104 of file download.h.

◆ mHeaders

curl_slist* Net::Download::mHeaders = nullptr
private

Definition at line 107 of file download.h.

◆ mMemoryWrite

bool Net::Download::mMemoryWrite = false
private

Definition at line 103 of file download.h.

◆ mState

ThreadSafe<State> Net::Download::mState
private

Definition at line 100 of file download.h.

◆ mThread

SDL_Thread* Net::Download::mThread = nullptr
private

Definition at line 106 of file download.h.

◆ mUrl

std::string Net::Download::mUrl
private

Definition at line 101 of file download.h.


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