Allow getinfo() to be called on a const CurlEasyRequest.

This commit is contained in:
Aleric Inglewood
2012-10-14 02:45:58 +02:00
parent 3ac46f5fa7
commit 83312fbb74
2 changed files with 25 additions and 13 deletions

View File

@@ -678,7 +678,7 @@ char* CurlEasyHandle::getTLErrorBuffer(void)
return tldata.mCurlErrorBuffer; return tldata.mCurlErrorBuffer;
} }
void CurlEasyHandle::setErrorBuffer(void) void CurlEasyHandle::setErrorBuffer(void) const
{ {
char* error_buffer = getTLErrorBuffer(); char* error_buffer = getTLErrorBuffer();
if (mErrorBuffer != error_buffer) if (mErrorBuffer != error_buffer)
@@ -697,7 +697,7 @@ void CurlEasyHandle::setErrorBuffer(void)
} }
} }
CURLcode CurlEasyHandle::getinfo_priv(CURLINFO info, void* data) CURLcode CurlEasyHandle::getinfo_priv(CURLINFO info, void* data) const
{ {
setErrorBuffer(); setErrorBuffer();
return check_easy_code(curl_easy_getinfo(mEasyHandle, info, data)); return check_easy_code(curl_easy_getinfo(mEasyHandle, info, data));
@@ -874,6 +874,11 @@ ThreadSafeCurlEasyRequest* CurlEasyRequest::get_lockobj(void)
return static_cast<ThreadSafeCurlEasyRequest*>(AIThreadSafeSimpleDC<CurlEasyRequest>::wrapper_cast(this)); return static_cast<ThreadSafeCurlEasyRequest*>(AIThreadSafeSimpleDC<CurlEasyRequest>::wrapper_cast(this));
} }
ThreadSafeCurlEasyRequest const* CurlEasyRequest::get_lockobj(void) const
{
return static_cast<ThreadSafeCurlEasyRequest const*>(AIThreadSafeSimpleDC<CurlEasyRequest>::wrapper_cast(this));
}
//static //static
size_t CurlEasyRequest::headerCallback(char* ptr, size_t size, size_t nmemb, void* userdata) size_t CurlEasyRequest::headerCallback(char* ptr, size_t size, size_t nmemb, void* userdata)
{ {
@@ -1723,6 +1728,11 @@ ThreadSafeBufferedCurlEasyRequest* CurlResponderBuffer::get_lockobj(void)
return static_cast<ThreadSafeBufferedCurlEasyRequest*>(AIThreadSafeSimple<CurlResponderBuffer>::wrapper_cast(this)); return static_cast<ThreadSafeBufferedCurlEasyRequest*>(AIThreadSafeSimple<CurlResponderBuffer>::wrapper_cast(this));
} }
ThreadSafeBufferedCurlEasyRequest const* CurlResponderBuffer::get_lockobj(void) const
{
return static_cast<ThreadSafeBufferedCurlEasyRequest const*>(AIThreadSafeSimple<CurlResponderBuffer>::wrapper_cast(this));
}
void CurlResponderBuffer::prepRequest(AICurlEasyRequest_wat& curl_easy_request_w, AIHTTPHeaders const& headers, AICurlInterface::ResponderPtr responder) void CurlResponderBuffer::prepRequest(AICurlEasyRequest_wat& curl_easy_request_w, AIHTTPHeaders const& headers, AICurlInterface::ResponderPtr responder)
{ {
mInput.reset(new LLBufferArray); mInput.reset(new LLBufferArray);

View File

@@ -116,20 +116,20 @@ namespace AICurlPrivate {
// Extract information from a curl handle. // Extract information from a curl handle.
private: private:
CURLcode getinfo_priv(CURLINFO info, void* data); CURLcode getinfo_priv(CURLINFO info, void* data) const;
public: public:
// The rest are inlines to provide some type-safety. // The rest are inlines to provide some type-safety.
CURLcode getinfo(CURLINFO info, char** data) { return getinfo_priv(info, data); } CURLcode getinfo(CURLINFO info, char** data) const { return getinfo_priv(info, data); }
CURLcode getinfo(CURLINFO info, curl_slist** data) { return getinfo_priv(info, data); } CURLcode getinfo(CURLINFO info, curl_slist** data) const { return getinfo_priv(info, data); }
CURLcode getinfo(CURLINFO info, double* data) { return getinfo_priv(info, data); } CURLcode getinfo(CURLINFO info, double* data) const { return getinfo_priv(info, data); }
CURLcode getinfo(CURLINFO info, long* data) { return getinfo_priv(info, data); } CURLcode getinfo(CURLINFO info, long* data) const { return getinfo_priv(info, data); }
#ifdef __LP64__ // sizeof(long) > sizeof(int) ? #ifdef __LP64__ // sizeof(long) > sizeof(int) ?
// Overload for integer types that are too small (libcurl demands a long). // Overload for integer types that are too small (libcurl demands a long).
CURLcode getinfo(CURLINFO info, S32* data) { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast<S32>(ldata); return res; } CURLcode getinfo(CURLINFO info, S32* data) const { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast<S32>(ldata); return res; }
CURLcode getinfo(CURLINFO info, U32* data) { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast<U32>(ldata); return res; } CURLcode getinfo(CURLINFO info, U32* data) const { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast<U32>(ldata); return res; }
#else // sizeof(long) == sizeof(int) #else // sizeof(long) == sizeof(int)
CURLcode getinfo(CURLINFO info, S32* data) { return getinfo_priv(info, reinterpret_cast<long*>(data)); } CURLcode getinfo(CURLINFO info, S32* data) const { return getinfo_priv(info, reinterpret_cast<long*>(data)); }
CURLcode getinfo(CURLINFO info, U32* data) { return getinfo_priv(info, reinterpret_cast<long*>(data)); } CURLcode getinfo(CURLINFO info, U32* data) const { return getinfo_priv(info, reinterpret_cast<long*>(data)); }
#endif #endif
// Perform a file transfer (blocking). // Perform a file transfer (blocking).
@@ -146,7 +146,7 @@ namespace AICurlPrivate {
private: private:
CURL* mEasyHandle; CURL* mEasyHandle;
CURLM* mActiveMultiHandle; CURLM* mActiveMultiHandle;
char* mErrorBuffer; mutable char* mErrorBuffer;
AIPostFieldPtr mPostField; // This keeps the POSTFIELD data alive for as long as the easy handle exists. AIPostFieldPtr mPostField; // This keeps the POSTFIELD data alive for as long as the easy handle exists.
bool mQueuedForRemoval; // Set if the easy handle is (probably) added to the multi handle, but is queued for removal. bool mQueuedForRemoval; // Set if the easy handle is (probably) added to the multi handle, but is queued for removal.
#ifdef SHOW_ASSERT #ifdef SHOW_ASSERT
@@ -174,7 +174,7 @@ namespace AICurlPrivate {
private: private:
// Call this prior to every curl_easy function whose return value is passed to check_easy_code. // Call this prior to every curl_easy function whose return value is passed to check_easy_code.
void setErrorBuffer(void); void setErrorBuffer(void) const;
static void handle_easy_error(CURLcode code); static void handle_easy_error(CURLcode code);
@@ -363,6 +363,7 @@ namespace AICurlPrivate {
// Return pointer to the ThreadSafe (wrapped) version of this object. // Return pointer to the ThreadSafe (wrapped) version of this object.
ThreadSafeCurlEasyRequest* get_lockobj(void); ThreadSafeCurlEasyRequest* get_lockobj(void);
ThreadSafeCurlEasyRequest const* get_lockobj(void) const;
protected: protected:
// Pass events to parent. // Pass events to parent.
@@ -452,6 +453,7 @@ class CurlResponderBuffer : protected AICurlResponderBufferEvents, protected AIC
public: public:
// Return pointer to the ThreadSafe (wrapped) version of this object. // Return pointer to the ThreadSafe (wrapped) version of this object.
ThreadSafeBufferedCurlEasyRequest* get_lockobj(void); ThreadSafeBufferedCurlEasyRequest* get_lockobj(void);
ThreadSafeBufferedCurlEasyRequest const* get_lockobj(void) const;
// Return true when prepRequest was already called and the object has not been // Return true when prepRequest was already called and the object has not been
// invalidated as a result of calling timed_out(). // invalidated as a result of calling timed_out().