The stream class for downloading using libcurl
.
More...
#include "nn/nlib/CurlInputStream.h"
|
CURL * | GetEasyHandle () const noexcept |
| Returns a libcurl easy_handle . More...
|
|
CURLcode | GetCurlError () const noexcept |
| Returns the error code that occurs in a function that takes a libcurl easy_handle as the argument. More...
|
|
CURLMcode | GetCurlMultiError () const noexcept |
| Returns the error code that occurs in a function that takes a libcurl multi_handle as the argument. More...
|
|
errno_t | Init (BufferSize buffer_size) noexcept |
| Initializes a stream. More...
|
|
errno_t | Init () noexcept |
| Executes Init(kBufferSize1x) .
|
|
CURLcode | SetUrl (const char *url) noexcept |
| Sets the URL to be read. More...
|
|
bool | StartDownload () noexcept |
|
|
constexpr | CurlInputStream () noexcept |
| Instantiates the object with default parameters (default constructor). The stream must be initialized with Init() .
|
|
virtual | ~CurlInputStream () noexcept override |
| Destructor. More...
|
|
errno_t | GetErrorValue () const noexcept |
| Gets the error value. More...
|
|
size_t | Pos () const noexcept |
| Returns the current position in the stream. More...
|
|
uint64_t | Pos64 () const noexcept |
| Returns the current position in the stream as a 64-bit value. More...
|
|
bool | IsEos () noexcept |
| Returns true if the stream is finished being read through to the end. If the stream has not been read through to the end, or if an error occurs, the function returns false . More...
|
|
int | Read () noexcept |
| Reads one byte of data from the stream. More...
|
|
int | Peek () noexcept |
| Reads the next byte without consuming the stream. More...
|
|
size_t | Skip (size_t nbytes) noexcept |
| Skips over the number of bytes specified by nbytes. More...
|
|
size_t | Read (void *ptr, size_t nbytes) noexcept |
| Reads the number of bytes of data specified by nbytes into the memory region specified by ptr. More...
|
|
bool | Close () noexcept |
| Closes the stream. Returns true if successful. More...
|
|
| operator bool () const |
| Returns true if no internal error has occurred.
|
|
constexpr | InputStream () noexcept |
| Instantiates the object. This function is called from the derived class.
|
|
virtual | ~InputStream () noexcept |
| Destructor. This function is called from the derived class.
|
|
The stream class for downloading using libcurl
.
- Description
- By using this class, you can handle data obtained with
libcurl
through the InputStream
interface. The following code is a common implementation for using the class.
}
stream.SetUrl("http://www.nintendo.co.jp/");
}
int c;
while ((c = stream.Read()) != -1) {
....
}
}
stream.Close();
- The transition of the object state.
- The overview of the object state transitions is described below:
Definition at line 31 of file CurlInputStream.h.
◆ ~CurlInputStream()
nn::nlib::CurlInputStream::~CurlInputStream |
( |
| ) |
|
|
overridevirtualnoexcept |
◆ GetCurlError()
nn::nlib::CurlInputStream::GetCurlError |
( |
| ) |
const |
|
noexcept |
Returns the error code that occurs in a function that takes a libcurl
easy_handle
as the argument.
- Returns
- The
CURLcode
type value.
- Description
- If the stream returns an error caused by
libcurl
, you can get the error code. For more information about the error code, see the libcurl
manual.
- See also
- http://curl.haxx.se/libcurl/c/libcurl-errors.html#CURLcode
◆ GetCurlMultiError()
nn::nlib::CurlInputStream::GetCurlMultiError |
( |
| ) |
const |
|
noexcept |
Returns the error code that occurs in a function that takes a libcurl
multi_handle
as the argument.
- Returns
- The
CURLMode
type value.
- Description
- If the stream returns an error caused by
libcurl
, you can get the error code. For more information about the error code, see the libcurl
manual.
- See also
- http://curl.haxx.se/libcurl/c/libcurl-errors.html#CURLMcode
◆ GetEasyHandle()
nn::nlib::CurlInputStream::GetEasyHandle |
( |
| ) |
const |
|
noexcept |
◆ Init()
nn::nlib::CurlInputStream::Init |
( |
BufferSize |
buffer_size | ) |
|
|
noexcept |
Initializes a stream.
- Parameters
-
[in] | buffer_size | The buffer size retained by the stream. |
- Return values
-
0 | Success. |
EALREADY | Already initialized. |
ENOMEM | Memory has failed to be allocated or the libcurl handle has failed to be initialized. |
ENOTSUP | An option has failed to be set due to reasons such as an obsolete libcurl . |
- Description
- Sets the buffer size for a stream with an argument.
buffer_size | The buffer size of a stream. |
kBufferSize1x | CURL_MAX_WRITE_SIZE |
kBufferSize2x | CURL_MAX_WRITE_SIZE * 2 |
kBufferSize3x | CURL_MAX_WRITE_SIZE * 3 |
kBufferSize4x | CURL_MAX_WRITE_SIZE * 4 |
- After allocating a stream buffer, the handle is initialized by
curl_easy_init()
, curl_multi_init()
, and curl_multi_add_handle()
. Then sets the following options with curl_easy_setopt()
.
- After executing this function, you need to obtain
easy_handle
using GetEasyHandle()
and set behavior options for URLs and others. However, never overwrite the CURLOPT_WRITEFUNCTION
and CURLOPT_WRITEDATA
settings.
◆ SetUrl()
nn::nlib::CurlInputStream::SetUrl |
( |
const char * |
url | ) |
|
|
noexcept |
◆ StartDownload()
nn::nlib::CurlInputStream::StartDownload |
( |
| ) |
|
|
noexcept |
- Returns
- Returns
true
when successful.
- Description
- Starts reading a stream by executing this function. Although you may read a stream using
Read()
instead of calling this function, the reading operation blocks until data has been received. You can use this function if you want to perform some processing after you have started reading a stream but before it is actually read.
- If the stream has failed to be read, sets an error to the stream.
The documentation for this class was generated from the following files: