From 83312fbb74f440d126113d8d93ea8b7e2e1edf18 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sun, 14 Oct 2012 02:45:58 +0200 Subject: [PATCH] Allow getinfo() to be called on a const CurlEasyRequest. --- indra/aistatemachine/aicurl.cpp | 14 ++++++++++++-- indra/aistatemachine/aicurlprivate.h | 24 +++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/indra/aistatemachine/aicurl.cpp b/indra/aistatemachine/aicurl.cpp index fae7c3633..c26b93f2e 100644 --- a/indra/aistatemachine/aicurl.cpp +++ b/indra/aistatemachine/aicurl.cpp @@ -678,7 +678,7 @@ char* CurlEasyHandle::getTLErrorBuffer(void) return tldata.mCurlErrorBuffer; } -void CurlEasyHandle::setErrorBuffer(void) +void CurlEasyHandle::setErrorBuffer(void) const { char* error_buffer = getTLErrorBuffer(); 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(); return check_easy_code(curl_easy_getinfo(mEasyHandle, info, data)); @@ -874,6 +874,11 @@ ThreadSafeCurlEasyRequest* CurlEasyRequest::get_lockobj(void) return static_cast(AIThreadSafeSimpleDC::wrapper_cast(this)); } +ThreadSafeCurlEasyRequest const* CurlEasyRequest::get_lockobj(void) const +{ + return static_cast(AIThreadSafeSimpleDC::wrapper_cast(this)); +} + //static 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(AIThreadSafeSimple::wrapper_cast(this)); } +ThreadSafeBufferedCurlEasyRequest const* CurlResponderBuffer::get_lockobj(void) const +{ + return static_cast(AIThreadSafeSimple::wrapper_cast(this)); +} + void CurlResponderBuffer::prepRequest(AICurlEasyRequest_wat& curl_easy_request_w, AIHTTPHeaders const& headers, AICurlInterface::ResponderPtr responder) { mInput.reset(new LLBufferArray); diff --git a/indra/aistatemachine/aicurlprivate.h b/indra/aistatemachine/aicurlprivate.h index 5b9d6457f..a95b9a314 100644 --- a/indra/aistatemachine/aicurlprivate.h +++ b/indra/aistatemachine/aicurlprivate.h @@ -116,20 +116,20 @@ namespace AICurlPrivate { // Extract information from a curl handle. private: - CURLcode getinfo_priv(CURLINFO info, void* data); + CURLcode getinfo_priv(CURLINFO info, void* data) const; public: // The rest are inlines to provide some type-safety. - CURLcode getinfo(CURLINFO info, char** data) { return getinfo_priv(info, data); } - CURLcode getinfo(CURLINFO info, curl_slist** data) { return getinfo_priv(info, data); } - CURLcode getinfo(CURLINFO info, double* data) { return getinfo_priv(info, data); } - CURLcode getinfo(CURLINFO info, long* 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) const { return getinfo_priv(info, data); } + CURLcode getinfo(CURLINFO info, double* data) const { return getinfo_priv(info, data); } + CURLcode getinfo(CURLINFO info, long* data) const { return getinfo_priv(info, data); } #ifdef __LP64__ // sizeof(long) > sizeof(int) ? // 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(ldata); return res; } - CURLcode getinfo(CURLINFO info, U32* data) { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast(ldata); return res; } + CURLcode getinfo(CURLINFO info, S32* data) const { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast(ldata); return res; } + CURLcode getinfo(CURLINFO info, U32* data) const { long ldata; CURLcode res = getinfo_priv(info, &ldata); *data = static_cast(ldata); return res; } #else // sizeof(long) == sizeof(int) - CURLcode getinfo(CURLINFO info, S32* data) { return getinfo_priv(info, reinterpret_cast(data)); } - CURLcode getinfo(CURLINFO info, U32* data) { return getinfo_priv(info, reinterpret_cast(data)); } + CURLcode getinfo(CURLINFO info, S32* data) const { return getinfo_priv(info, reinterpret_cast(data)); } + CURLcode getinfo(CURLINFO info, U32* data) const { return getinfo_priv(info, reinterpret_cast(data)); } #endif // Perform a file transfer (blocking). @@ -146,7 +146,7 @@ namespace AICurlPrivate { private: CURL* mEasyHandle; CURLM* mActiveMultiHandle; - char* mErrorBuffer; + mutable char* mErrorBuffer; 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. #ifdef SHOW_ASSERT @@ -174,7 +174,7 @@ namespace AICurlPrivate { private: // 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); @@ -363,6 +363,7 @@ namespace AICurlPrivate { // Return pointer to the ThreadSafe (wrapped) version of this object. ThreadSafeCurlEasyRequest* get_lockobj(void); + ThreadSafeCurlEasyRequest const* get_lockobj(void) const; protected: // Pass events to parent. @@ -452,6 +453,7 @@ class CurlResponderBuffer : protected AICurlResponderBufferEvents, protected AIC public: // Return pointer to the ThreadSafe (wrapped) version of this object. ThreadSafeBufferedCurlEasyRequest* get_lockobj(void); + ThreadSafeBufferedCurlEasyRequest const* get_lockobj(void) const; // Return true when prepRequest was already called and the object has not been // invalidated as a result of calling timed_out().