Audacity 3.2.0
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
audacity::network_manager::CurlResponse Class Referencefinal

#include <CurlResponse.h>

Inheritance diagram for audacity::network_manager::CurlResponse:
[legend]
Collaboration diagram for audacity::network_manager::CurlResponse:
[legend]

Public Member Functions

 CurlResponse (RequestVerb verb, const Request &request, CurlHandleManager *handleManager) noexcept
 
bool isFinished () const noexcept override
 
unsigned getHTTPCode () const noexcept override
 
NetworkError getError () const noexcept override
 
std::string getErrorString () const override
 
bool headersReceived () const noexcept override
 
bool hasHeader (const std::string &headerName) const noexcept override
 
std::string getHeader (const std::string &headerName) const override
 
const HeadersListgetHeaders () const noexcept override
 
const CookiesListgetCookies () const noexcept override
 
const RequestgetRequest () const noexcept override
 
std::string getURL () const override
 
void abort () noexcept override
 
void setOnDataReceivedCallback (RequestCallback callback) override
 
void setRequestFinishedCallback (RequestCallback callback) override
 
virtual void setDownloadProgressCallback (ProgressCallback callback) override
 Set the download progress callback. More...
 
virtual void setUploadProgressCallback (ProgressCallback callback) override
 Set the upload progress callback. More...
 
uint64_t getBytesAvailable () const noexcept override
 
uint64_t readData (void *buffer, uint64_t maxBytesCount) override
 
void setPayload (RequestPayloadStreamPtr payload)
 
void setForm (std::unique_ptr< MultipartData > form)
 
void perform ()
 
- Public Member Functions inherited from audacity::network_manager::IResponse
virtual ~IResponse ()=default
 
virtual bool isFinished () const noexcept=0
 
virtual unsigned getHTTPCode () const noexcept=0
 
virtual NetworkError getError () const noexcept=0
 
virtual std::string getErrorString () const =0
 
virtual bool headersReceived () const noexcept=0
 
virtual bool hasHeader (const std::string &headerName) const noexcept=0
 
virtual std::string getHeader (const std::string &headerName) const =0
 
virtual const HeadersListgetHeaders () const noexcept=0
 
virtual const CookiesListgetCookies () const noexcept=0
 
virtual const RequestgetRequest () const noexcept=0
 
virtual std::string getURL () const =0
 
virtual void abort () noexcept=0
 
virtual void setOnDataReceivedCallback (RequestCallback callback)=0
 
virtual void setRequestFinishedCallback (RequestCallback callback)=0
 
virtual void setDownloadProgressCallback (ProgressCallback callback)=0
 Set the download progress callback. More...
 
virtual void setUploadProgressCallback (ProgressCallback callback)=0
 Set the upload progress callback. More...
 
virtual uint64_t getBytesAvailable () const noexcept=0
 
virtual uint64_t readData (void *buffer, uint64_t maxBytesCount)=0
 
template<typename RetVal = std::vector<uint8_t>>
RetVal readAll ()
 
void Cancel () override
 
- Public Member Functions inherited from audacity::concurrency::ICancellable
virtual ~ICancellable ()=default
 
virtual void Cancel ()=0
 

Static Private Member Functions

static size_t WriteCallback (const uint8_t *ptr, size_t size, size_t nmemb, CurlResponse *userdata) noexcept
 
static size_t HeaderCallback (const char *buffer, size_t size, size_t nitems, CurlResponse *userdata) noexcept
 
static int CurlProgressCallback (CurlResponse *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) noexcept
 

Private Attributes

RequestVerb mVerb
 
Request mRequest
 
CurlHandleManagermHandleManager
 
CurlHandleManager::HandlemCurrentHandle { nullptr }
 
std::mutex mCallbackMutex
 
RequestCallback mOnDataReceivedCallback
 
RequestCallback mRequestFinishedCallback
 
ProgressCallback mDownloadProgressCallback
 
ProgressCallback mUploadProgressCallback
 
std::mutex mHeadersMutex
 
HeadersList mResponseHeaders
 
CookiesList mResponseCookies
 
std::mutex mDataBufferMutex
 
std::deque< uint8_t > mDataBuffer
 
std::recursive_mutex mStatusMutex
 
NetworkError mNetworkError { NetworkError::NoError }
 
std::string mErrorString
 
unsigned mHttpCode { 0 }
 
RequestPayloadStreamPtr mPayload
 
std::unique_ptr< MultipartDatamForm
 
bool mHeadersReceived { false }
 
bool mRequestFinished { false }
 
bool mAbortRequested { false }
 

Additional Inherited Members

- Public Types inherited from audacity::network_manager::IResponse
using RequestCallback = std::function< void(IResponse *)>
 
using ProgressCallback = std::function< void(int64_t current, int64_t expected)>
 

Detailed Description

Definition at line 35 of file CurlResponse.h.

Constructor & Destructor Documentation

◆ CurlResponse()

audacity::network_manager::CurlResponse::CurlResponse ( RequestVerb  verb,
const Request request,
CurlHandleManager handleManager 
)
noexcept

Definition at line 94 of file CurlResponse.cpp.

95 : mVerb(verb),
96 mRequest(request),
97 mHandleManager (handleManager)
98{
99}

Member Function Documentation

◆ abort()

void audacity::network_manager::CurlResponse::abort ( )
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 165 of file CurlResponse.cpp.

166{
167 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
168 mAbortRequested = true;
169}

References mAbortRequested, and mStatusMutex.

◆ CurlProgressCallback()

int audacity::network_manager::CurlResponse::CurlProgressCallback ( CurlResponse clientp,
curl_off_t  dltotal,
curl_off_t  dlnow,
curl_off_t  ultotal,
curl_off_t  ulnow 
)
staticprivatenoexcept

Definition at line 446 of file CurlResponse.cpp.

449{
450 {
451 std::lock_guard<std::recursive_mutex> lock(clientp->mStatusMutex);
452
453 if (clientp->mAbortRequested)
454 return -1;
455 }
456
457 std::lock_guard<std::mutex> callbackLock(clientp->mCallbackMutex);
458
459 if (dltotal > 0 && clientp->mDownloadProgressCallback)
460 clientp->mDownloadProgressCallback(dlnow, dltotal);
461
462 if (ultotal > 0 && clientp->mUploadProgressCallback)
463 clientp->mUploadProgressCallback(ulnow, ultotal);
464
465 return CURLE_OK;
466}

Referenced by perform().

Here is the caller graph for this function:

◆ getBytesAvailable()

uint64_t audacity::network_manager::CurlResponse::getBytesAvailable ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 205 of file CurlResponse.cpp.

206{
207 std::lock_guard<std::mutex> lock (mDataBufferMutex);
208 return mDataBuffer.size ();
209}

References mDataBuffer, and mDataBufferMutex.

Referenced by setOnDataReceivedCallback().

Here is the caller graph for this function:

◆ getCookies()

const CookiesList & audacity::network_manager::CurlResponse::getCookies ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 149 of file CurlResponse.cpp.

150{
151 std::lock_guard<std::mutex> lock (mHeadersMutex);
152 return mResponseCookies;
153}

References mHeadersMutex, and mResponseCookies.

◆ getError()

NetworkError audacity::network_manager::CurlResponse::getError ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 113 of file CurlResponse.cpp.

114{
115 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
116 return mNetworkError;
117}

References mNetworkError, and mStatusMutex.

◆ getErrorString()

std::string audacity::network_manager::CurlResponse::getErrorString ( ) const
overridevirtual

Implements audacity::network_manager::IResponse.

Definition at line 119 of file CurlResponse.cpp.

120{
121 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
122 return mErrorString;
123}

References mErrorString, and mStatusMutex.

◆ getHeader()

std::string audacity::network_manager::CurlResponse::getHeader ( const std::string &  headerName) const
overridevirtual

Implements audacity::network_manager::IResponse.

Definition at line 137 of file CurlResponse.cpp.

138{
139 std::lock_guard<std::mutex> lock (mHeadersMutex);
140 return mResponseHeaders.getHeaderValue (headerName);
141}
std::string getHeaderValue(const std::string &headerName) const

References audacity::network_manager::HeadersList::getHeaderValue(), mHeadersMutex, and mResponseHeaders.

Here is the call graph for this function:

◆ getHeaders()

const HeadersList & audacity::network_manager::CurlResponse::getHeaders ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 143 of file CurlResponse.cpp.

144{
145 std::lock_guard<std::mutex> lock (mHeadersMutex);
146 return mResponseHeaders;
147}

References mHeadersMutex, and mResponseHeaders.

◆ getHTTPCode()

unsigned audacity::network_manager::CurlResponse::getHTTPCode ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 107 of file CurlResponse.cpp.

108{
109 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
110 return mHttpCode;
111}

References mHttpCode, and mStatusMutex.

◆ getRequest()

const Request & audacity::network_manager::CurlResponse::getRequest ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 155 of file CurlResponse.cpp.

156{
157 return mRequest;
158}

References mRequest.

◆ getURL()

std::string audacity::network_manager::CurlResponse::getURL ( ) const
overridevirtual

Implements audacity::network_manager::IResponse.

Definition at line 160 of file CurlResponse.cpp.

161{
162 return mRequest.getURL ();
163}
const std::string & getURL() const noexcept
Definition: Request.cpp:41

References audacity::network_manager::Request::getURL(), and mRequest.

Here is the call graph for this function:

◆ hasHeader()

bool audacity::network_manager::CurlResponse::hasHeader ( const std::string &  headerName) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 131 of file CurlResponse.cpp.

132{
133 std::lock_guard<std::mutex> lock (mHeadersMutex);
134 return mResponseHeaders.hasHeader (headerName);
135}
bool hasHeader(const std::string &headerName) const noexcept

◆ HeaderCallback()

size_t audacity::network_manager::CurlResponse::HeaderCallback ( const char *  buffer,
size_t  size,
size_t  nitems,
CurlResponse userdata 
)
staticprivatenoexcept

Definition at line 407 of file CurlResponse.cpp.

408{
409 {
410 std::lock_guard<std::recursive_mutex> lock (request->mStatusMutex);
411
412 if (request->mAbortRequested)
413 return 0;
414
415 // HeaderCallback is called by the handle
416 assert (request->mCurrentHandle != nullptr);
417
418 if (request->mCurrentHandle != nullptr)
419 request->mHttpCode = request->mCurrentHandle->getHTTPCode ();
420 }
421
422 size = size * nitems;
423
424 if (size < 2)
425 return 0;
426
427 const Header header = Header::Parse (std::string (buffer, size - 2));
428
429 std::lock_guard<std::mutex> lock (request->mHeadersMutex);
430
431 if (header.hasSameName ("Set-Cookie"))
432 {
433 request->mResponseCookies.addCookie (Cookie::Parse (header.Value));
434 }
435 else
436 {
437 if (header.hasSameName ("Keep-Alive"))
438 request->mCurrentHandle->markKeepAlive ();
439
440 request->mResponseHeaders.addHeader (header);
441 }
442
443 return size;
444}
A string pair, representing HTTP header.
static Header Parse(const std::string &header)
Definition: HeadersList.cpp:81

References audacity::network_manager::Header::hasSameName(), audacity::network_manager::Cookie::Parse(), audacity::network_manager::Header::Parse(), size, and audacity::network_manager::Header::Value.

Referenced by perform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headersReceived()

bool audacity::network_manager::CurlResponse::headersReceived ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 125 of file CurlResponse.cpp.

126{
127 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
128 return mHeadersReceived;
129}

References mHeadersReceived, and mStatusMutex.

◆ isFinished()

bool audacity::network_manager::CurlResponse::isFinished ( ) const
overridevirtualnoexcept

Implements audacity::network_manager::IResponse.

Definition at line 101 of file CurlResponse.cpp.

102{
103 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
104 return mRequestFinished;
105}

References mRequestFinished, and mStatusMutex.

◆ perform()

void audacity::network_manager::CurlResponse::perform ( )

Definition at line 243 of file CurlResponse.cpp.

244{
245 CurlHandleManager::Handle handle = mHandleManager->getHandle (mVerb, mRequest.getURL ());
246
247 handle.setOption (CURLOPT_WRITEFUNCTION, WriteCallback);
248 handle.setOption (CURLOPT_WRITEDATA, this);
249
250 handle.setOption (CURLOPT_HEADERFUNCTION, HeaderCallback);
251 handle.setOption (CURLOPT_HEADERDATA, this);
252
253 handle.setOption (CURLOPT_XFERINFOFUNCTION, CurlProgressCallback);
254 handle.setOption (CURLOPT_XFERINFODATA, this);
255
256 handle.setOption (CURLOPT_FOLLOWLOCATION, mRequest.getMaxRedirects () == 0 ? 0 : 1);
257 handle.setOption (CURLOPT_MAXREDIRS, mRequest.getMaxRedirects ());
258
259 handle.setOption (CURLOPT_NOPROGRESS, 0L);
260
261 handle.setOption (CURLOPT_CONNECTTIMEOUT_MS,
262 std::chrono::duration_cast<std::chrono::milliseconds> (mRequest.getTimeout()).count ()
263 );
264
265 handle.appendCookies (mRequest.getCookies ());
266
267 curl_mime* mimeList = nullptr;
268
269 if (mForm != nullptr)
270 {
271 mimeList = curl_mime_init(handle.getCurlHandle());
272
273 for (size_t i = 0; i < mForm->GetPartsCount(); ++i)
274 {
275 auto part = mForm->GetPart(i);
276
277 curl_mimepart* curlPart = curl_mime_addpart(mimeList);
278
279 const auto& headers = part->GetHeaders();
280
281 if (headers.getHeadersCount() > 0)
282 {
283 curl_slist* partHeaders = nullptr;
284
285 for (auto header : headers)
286 {
287 partHeaders = curl_slist_append(
288 partHeaders, (header.Name + ": " + header.Value).c_str());
289 }
290
291 curl_mime_headers(curlPart, partHeaders, 1);
292 }
293
294 curl_mime_data_cb(
295 curlPart, part->GetSize(), curl_read_callback(MimePartRead),
296 curl_seek_callback(MimePartSeek), nullptr, part);
297 }
298
299 curl_easy_setopt(handle.getCurlHandle(), CURLOPT_MIMEPOST, mimeList);
300 }
301 else if (mPayload != nullptr && mPayload->HasData())
302 {
303 if (const auto payloadSize = mPayload->GetDataSize(); payloadSize > 0)
304 {
305 handle.appendHeader({ "Transfer-Encoding", std::string() });
306 handle.appendHeader(
307 { "Content-Length", std::to_string(payloadSize) });
308
310 handle.setOption(CURLOPT_POSTFIELDSIZE_LARGE, payloadSize);
311 else
312 handle.setOption(CURLOPT_INFILESIZE_LARGE, payloadSize);
313 }
314
315 handle.setOption (CURLOPT_READFUNCTION, DataStreamRead);
316 handle.setOption (CURLOPT_READDATA, mPayload.get());
317
318 handle.setOption (CURLOPT_SEEKFUNCTION, DataStreamSeek);
319 handle.setOption (CURLOPT_SEEKDATA, mPayload.get());
320 }
322 {
323 handle.setOption (CURLOPT_POSTFIELDS, "");
324 handle.setOption (CURLOPT_POSTFIELDSIZE, 0);
325 }
326
327 auto cleanupMime = finally(
328 [mimeList]() {
329 if (mimeList != nullptr)
330 curl_mime_free(mimeList);
331 });
332
333 handle.appendHeaders (mRequest.getHeaders ());
334
335 mCurrentHandle = &handle;
336 const auto result = handle.perform ();
337 mCurrentHandle = nullptr;
338
339 {
340 std::lock_guard<std::recursive_mutex> lock (mStatusMutex);
341
342 if (result.Code != CURLE_OK)
343 {
344 const auto it = errorsMap.find (result.Code);
345
346 mNetworkError = it != errorsMap.end () ? it->second : NetworkError::UnknownError;
347 mErrorString = result.Message;
348 }
349 else
350 {
351 if (mHttpCode == 0)
352 mHttpCode = handle.getHTTPCode ();
353 if (mHttpCode >= 400)
355 }
356
357 mRequestFinished = true;
358 }
359
360 std::lock_guard<std::mutex> lock (mCallbackMutex);
361
364
369}
CURLcode setOption(CURLoption option, Args... value) noexcept
Handle getHandle(RequestVerb verb, const std::string &url)
static size_t WriteCallback(const uint8_t *ptr, size_t size, size_t nmemb, CurlResponse *userdata) noexcept
std::unique_ptr< MultipartData > mForm
Definition: CurlResponse.h:108
static int CurlProgressCallback(CurlResponse *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) noexcept
static size_t HeaderCallback(const char *buffer, size_t size, size_t nitems, CurlResponse *userdata) noexcept
CurlHandleManager::Handle * mCurrentHandle
Definition: CurlResponse.h:85
Timeout getTimeout() const noexcept
Definition: Request.cpp:98
const HeadersList & getHeaders() const noexcept
Definition: Request.cpp:58
const CookiesList & getCookies() noexcept
Definition: Request.cpp:75
size_t getMaxRedirects() const noexcept
Definition: Request.cpp:87
size_t MimePartRead(char *ptr, size_t size, size_t nmemb, MultipartData::Part *stream)
int MimePartSeek(MultipartData::Part *stream, curl_off_t offs, int origin) noexcept
int DataStreamSeek(RequestPayloadStream *stream, curl_off_t offs, int origin)
size_t DataStreamRead(char *ptr, size_t size, size_t nmemb, RequestPayloadStream *stream)
static const std::map< CURLcode, NetworkError > errorsMap

References audacity::network_manager::CurlHandleManager::Handle::appendCookies(), audacity::network_manager::CurlHandleManager::Handle::appendHeader(), audacity::network_manager::CurlHandleManager::Handle::appendHeaders(), CurlProgressCallback(), audacity::network_manager::anonymous_namespace{CurlResponse.cpp}::DataStreamRead(), audacity::network_manager::anonymous_namespace{CurlResponse.cpp}::DataStreamSeek(), audacity::network_manager::anonymous_namespace{CurlResponse.cpp}::errorsMap, audacity::network_manager::Request::getCookies(), audacity::network_manager::CurlHandleManager::Handle::getCurlHandle(), audacity::network_manager::CurlHandleManager::getHandle(), audacity::network_manager::Request::getHeaders(), audacity::network_manager::CurlHandleManager::Handle::getHTTPCode(), audacity::network_manager::Request::getMaxRedirects(), audacity::network_manager::Request::getTimeout(), audacity::network_manager::Request::getURL(), HeaderCallback(), audacity::network_manager::HTTPError, mCallbackMutex, mCurrentHandle, mDownloadProgressCallback, mErrorString, mForm, mHandleManager, mHttpCode, audacity::network_manager::anonymous_namespace{CurlResponse.cpp}::MimePartRead(), audacity::network_manager::anonymous_namespace{CurlResponse.cpp}::MimePartSeek(), mNetworkError, mOnDataReceivedCallback, mPayload, mRequest, mRequestFinished, mRequestFinishedCallback, mStatusMutex, mUploadProgressCallback, mVerb, audacity::network_manager::Patch, audacity::network_manager::CurlHandleManager::Handle::perform(), audacity::network_manager::Post, audacity::network_manager::Put, audacity::network_manager::CurlHandleManager::Handle::setOption(), audacity::network_manager::UnknownError, and WriteCallback().

Here is the call graph for this function:

◆ readData()

uint64_t audacity::network_manager::CurlResponse::readData ( void *  buffer,
uint64_t  maxBytesCount 
)
overridevirtual

Implements audacity::network_manager::IResponse.

Definition at line 211 of file CurlResponse.cpp.

212{
213 if (buffer == nullptr || maxBytesCount == 0)
214 return 0;
215
216 std::lock_guard<std::mutex> lock (mDataBufferMutex);
217
218 if (mDataBuffer.empty ())
219 return 0;
220
221 maxBytesCount = std::min<uint64_t> (maxBytesCount, mDataBuffer.size ());
222
223 const auto begin = mDataBuffer.begin ();
224 const auto end = begin + maxBytesCount;
225
226 std::copy (begin, end, static_cast<uint8_t*> (buffer));
227
228 mDataBuffer.erase (begin, end);
229
230 return maxBytesCount;
231}
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References details::begin(), staffpad::vo::copy(), details::end(), mDataBuffer, and mDataBufferMutex.

Here is the call graph for this function:

◆ setDownloadProgressCallback()

void audacity::network_manager::CurlResponse::setDownloadProgressCallback ( ProgressCallback  callback)
overridevirtual

Set the download progress callback.

Implements audacity::network_manager::IResponse.

Definition at line 193 of file CurlResponse.cpp.

194{
195 std::lock_guard<std::mutex> callbackLock(mCallbackMutex);
196 mDownloadProgressCallback = std::move(callback);
197}

References mCallbackMutex, and mDownloadProgressCallback.

◆ setForm()

void audacity::network_manager::CurlResponse::setForm ( std::unique_ptr< MultipartData form)

Definition at line 238 of file CurlResponse.cpp.

239{
240 mForm = std::move(form);
241}

References mForm.

◆ setOnDataReceivedCallback()

void audacity::network_manager::CurlResponse::setOnDataReceivedCallback ( RequestCallback  callback)
overridevirtual

Implements audacity::network_manager::IResponse.

Definition at line 171 of file CurlResponse.cpp.

172{
173 std::lock_guard<std::mutex> lock (mCallbackMutex);
174
175 mOnDataReceivedCallback = std::move (callback);
176
179}
uint64_t getBytesAvailable() const noexcept override

References getBytesAvailable(), mCallbackMutex, and mOnDataReceivedCallback.

Here is the call graph for this function:

◆ setPayload()

void audacity::network_manager::CurlResponse::setPayload ( RequestPayloadStreamPtr  payload)

Definition at line 233 of file CurlResponse.cpp.

234{
235 mPayload = std::move(payload);
236}

References mPayload.

◆ setRequestFinishedCallback()

void audacity::network_manager::CurlResponse::setRequestFinishedCallback ( RequestCallback  callback)
overridevirtual

Implements audacity::network_manager::IResponse.

Definition at line 181 of file CurlResponse.cpp.

182{
183 std::lock_guard<std::mutex> callbackLock (mCallbackMutex);
184
185 mRequestFinishedCallback = std::move (callback);
186
187 std::lock_guard<std::recursive_mutex> statusLock (mStatusMutex);
188
191}

References mCallbackMutex, mRequestFinished, mRequestFinishedCallback, and mStatusMutex.

◆ setUploadProgressCallback()

void audacity::network_manager::CurlResponse::setUploadProgressCallback ( ProgressCallback  callback)
overridevirtual

Set the upload progress callback.

Implements audacity::network_manager::IResponse.

Definition at line 199 of file CurlResponse.cpp.

200{
201 std::lock_guard<std::mutex> callbackLock(mCallbackMutex);
202 mUploadProgressCallback = std::move(callback);
203}

References mCallbackMutex, and mUploadProgressCallback.

◆ WriteCallback()

size_t audacity::network_manager::CurlResponse::WriteCallback ( const uint8_t *  ptr,
size_t  size,
size_t  nmemb,
CurlResponse userdata 
)
staticprivatenoexcept

Definition at line 372 of file CurlResponse.cpp.

373{
374 {
375 std::lock_guard<std::recursive_mutex> lock (request->mStatusMutex);
376
377 if (request->mAbortRequested)
378 return 0;
379
380 if (!request->mHeadersReceived)
381 {
382 request->mHeadersReceived = true;
383
384 // WriteCallback is called by the handle
385 assert (request->mCurrentHandle != nullptr);
386
387 if (request->mCurrentHandle != nullptr)
388 request->mHttpCode = request->mCurrentHandle->getHTTPCode ();
389 }
390 }
391
392 size *= nmemb;
393
394 {
395 std::lock_guard<std::mutex> lock (request->mDataBufferMutex);
396 request->mDataBuffer.insert (request->mDataBuffer.end (), ptr, ptr + size);
397 }
398
399 std::lock_guard<std::mutex> lock (request->mCallbackMutex);
400
401 if (request->mOnDataReceivedCallback)
402 request->mOnDataReceivedCallback (request);
403
404 return size;
405}

References nmemb, and size.

Referenced by perform().

Here is the caller graph for this function:

Member Data Documentation

◆ mAbortRequested

bool audacity::network_manager::CurlResponse::mAbortRequested { false }
private

Definition at line 112 of file CurlResponse.h.

Referenced by abort().

◆ mCallbackMutex

std::mutex audacity::network_manager::CurlResponse::mCallbackMutex
mutableprivate

◆ mCurrentHandle

CurlHandleManager::Handle* audacity::network_manager::CurlResponse::mCurrentHandle { nullptr }
private

Definition at line 85 of file CurlResponse.h.

Referenced by perform().

◆ mDataBuffer

std::deque<uint8_t> audacity::network_manager::CurlResponse::mDataBuffer
private

Definition at line 98 of file CurlResponse.h.

Referenced by getBytesAvailable(), and readData().

◆ mDataBufferMutex

std::mutex audacity::network_manager::CurlResponse::mDataBufferMutex
mutableprivate

Definition at line 97 of file CurlResponse.h.

Referenced by getBytesAvailable(), and readData().

◆ mDownloadProgressCallback

ProgressCallback audacity::network_manager::CurlResponse::mDownloadProgressCallback
private

Definition at line 90 of file CurlResponse.h.

Referenced by perform(), and setDownloadProgressCallback().

◆ mErrorString

std::string audacity::network_manager::CurlResponse::mErrorString
private

Definition at line 103 of file CurlResponse.h.

Referenced by getErrorString(), and perform().

◆ mForm

std::unique_ptr<MultipartData> audacity::network_manager::CurlResponse::mForm
private

Definition at line 108 of file CurlResponse.h.

Referenced by perform(), and setForm().

◆ mHandleManager

CurlHandleManager* audacity::network_manager::CurlResponse::mHandleManager
private

Definition at line 83 of file CurlResponse.h.

Referenced by perform().

◆ mHeadersMutex

std::mutex audacity::network_manager::CurlResponse::mHeadersMutex
mutableprivate

Definition at line 93 of file CurlResponse.h.

Referenced by getCookies(), getHeader(), and getHeaders().

◆ mHeadersReceived

bool audacity::network_manager::CurlResponse::mHeadersReceived { false }
private

Definition at line 110 of file CurlResponse.h.

Referenced by headersReceived().

◆ mHttpCode

unsigned audacity::network_manager::CurlResponse::mHttpCode { 0 }
private

Definition at line 105 of file CurlResponse.h.

Referenced by getHTTPCode(), and perform().

◆ mNetworkError

NetworkError audacity::network_manager::CurlResponse::mNetworkError { NetworkError::NoError }
private

Definition at line 102 of file CurlResponse.h.

Referenced by getError(), and perform().

◆ mOnDataReceivedCallback

RequestCallback audacity::network_manager::CurlResponse::mOnDataReceivedCallback
private

Definition at line 88 of file CurlResponse.h.

Referenced by perform(), and setOnDataReceivedCallback().

◆ mPayload

RequestPayloadStreamPtr audacity::network_manager::CurlResponse::mPayload
private

Definition at line 107 of file CurlResponse.h.

Referenced by perform(), and setPayload().

◆ mRequest

Request audacity::network_manager::CurlResponse::mRequest
private

Definition at line 82 of file CurlResponse.h.

Referenced by getRequest(), getURL(), and perform().

◆ mRequestFinished

bool audacity::network_manager::CurlResponse::mRequestFinished { false }
private

Definition at line 111 of file CurlResponse.h.

Referenced by isFinished(), perform(), and setRequestFinishedCallback().

◆ mRequestFinishedCallback

RequestCallback audacity::network_manager::CurlResponse::mRequestFinishedCallback
private

Definition at line 89 of file CurlResponse.h.

Referenced by perform(), and setRequestFinishedCallback().

◆ mResponseCookies

CookiesList audacity::network_manager::CurlResponse::mResponseCookies
private

Definition at line 95 of file CurlResponse.h.

Referenced by getCookies().

◆ mResponseHeaders

HeadersList audacity::network_manager::CurlResponse::mResponseHeaders
private

Definition at line 94 of file CurlResponse.h.

Referenced by getHeader(), and getHeaders().

◆ mStatusMutex

std::recursive_mutex audacity::network_manager::CurlResponse::mStatusMutex
mutableprivate

◆ mUploadProgressCallback

ProgressCallback audacity::network_manager::CurlResponse::mUploadProgressCallback
private

Definition at line 91 of file CurlResponse.h.

Referenced by perform(), and setUploadProgressCallback().

◆ mVerb

RequestVerb audacity::network_manager::CurlResponse::mVerb
private

Definition at line 80 of file CurlResponse.h.

Referenced by perform().


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