From f675a8b6d3b1b9e0ac0367d73547675199b1252c Mon Sep 17 00:00:00 2001 From: cantor Date: Fri, 14 Mar 2008 19:25:31 +0000 Subject: [PATCH] Add some logging. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@476 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/util/CurlURLInputStream.cpp | 26 ++++++++++++++------------ xmltooling/util/CurlURLInputStream.hpp | 4 +++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/xmltooling/util/CurlURLInputStream.cpp b/xmltooling/util/CurlURLInputStream.cpp index 1923a50..fc0b359 100644 --- a/xmltooling/util/CurlURLInputStream.cpp +++ b/xmltooling/util/CurlURLInputStream.cpp @@ -41,7 +41,6 @@ #include #include -#include #include using namespace xmltooling; @@ -60,6 +59,7 @@ CurlURLInputStream::CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTP , fDataAvailable(false) , fBufferHeadPtr(fBuffer) , fBufferTailPtr(fBuffer) + , m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".libcurl.NetAccessor")) { // Allocate the curl multi handle fMulti = curl_multi_init(); @@ -70,14 +70,14 @@ CurlURLInputStream::CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTP // Get the text of the URL we're going to use fURL.reset(XMLString::transcode(fURLSource.getURLText(), fMemoryManager), fMemoryManager); - //printf("Curl trying to fetch %s\n", fURL.get()); + m_log.debug("libcurl trying to fetch %s", fURL.get()); // Set URL option curl_easy_setopt(fEasy, CURLOPT_URL, fURL.get()); curl_easy_setopt(fEasy, CURLOPT_WRITEDATA, this); // Pass this pointer to write function curl_easy_setopt(fEasy, CURLOPT_WRITEFUNCTION, staticWriteCallback); // Our static write function - curl_easy_setopt(fEasy, CURLOPT_CONNECTTIMEOUT, 15); - curl_easy_setopt(fEasy, CURLOPT_TIMEOUT, 30); + curl_easy_setopt(fEasy, CURLOPT_CONNECTTIMEOUT, 30); + curl_easy_setopt(fEasy, CURLOPT_TIMEOUT, 60); curl_easy_setopt(fEasy, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3); curl_easy_setopt(fEasy, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(fEasy, CURLOPT_SSL_VERIFYPEER, 0); @@ -130,7 +130,7 @@ CurlURLInputStream::writeCallback(char *buffer, fTotalBytesRead += consume; fBytesToRead -= consume; - //printf("write callback consuming %d bytes\n", consume); + //m_log.debug("write callback consuming %d bytes", consume); // If bytes remain, rebuffer as many as possible into our holding buffer buffer += consume; @@ -144,7 +144,7 @@ CurlURLInputStream::writeCallback(char *buffer, fBufferHeadPtr += consume; buffer += consume; totalConsumed += consume; - //printf("write callback rebuffering %d bytes\n", consume); + //m_log.debug("write callback rebuffering %d bytes", consume); } // Return the total amount we've consumed. If we don't consume all the bytes @@ -180,7 +180,7 @@ CurlURLInputStream::readBytes(XMLByte* const toFill if (fBufferTailPtr == fBufferHeadPtr) fBufferHeadPtr = fBufferTailPtr = fBuffer; - //printf("consuming %d buffered bytes\n", bufCnt); + //m_log.debug("consuming %d buffered bytes", bufCnt); tryAgain = true; continue; @@ -189,13 +189,14 @@ CurlURLInputStream::readBytes(XMLByte* const toFill // Ask the curl to do some work int runningHandles = 0; CURLMcode curlResult = curl_multi_perform(fMulti, &runningHandles); + //m_log.debug("curl_multi_perform returned %d", curlResult); tryAgain = (curlResult == CURLM_CALL_MULTI_PERFORM); // Process messages from curl int msgsInQueue = 0; for (CURLMsg* msg = NULL; (msg = curl_multi_info_read(fMulti, &msgsInQueue)) != NULL; ) { - //printf("msg %d, %d from curl\n", msg->msg, msg->data.result); + m_log.debug("msg %d, %d from curl", msg->msg, msg->data.result); if (msg->msg != CURLMSG_DONE) continue; @@ -223,17 +224,17 @@ CurlURLInputStream::readBytes(XMLByte* const toFill break; default: - logging::Category::getInstance(XMLTOOLING_LOGCAT"libcurl.NetAccessor").error( - "curl NetAccessor encountered error from libcurl (%d)", msg->data.result - ); + m_log.error("curl NetAccessor encountered error from libcurl (%d)", msg->data.result); ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_InternalError, fURLSource.getURLText(), fMemoryManager); break; } } // If nothing is running any longer, bail out - if (runningHandles == 0) + if (runningHandles == 0) { + //m_log.debug("libcurl indicated no running handles"); break; + } // If there is no further data to read, and we haven't // read any yet on this invocation, call select to wait for data @@ -258,6 +259,7 @@ CurlURLInputStream::readBytes(XMLByte* const toFill } } + //m_log.debug("returning with %d bytes to parser", fBytesRead); return fBytesRead; } diff --git a/xmltooling/util/CurlURLInputStream.hpp b/xmltooling/util/CurlURLInputStream.hpp index a8bb925..991f775 100644 --- a/xmltooling/util/CurlURLInputStream.hpp +++ b/xmltooling/util/CurlURLInputStream.hpp @@ -22,7 +22,7 @@ #if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP) && !defined(XMLTOOLING_LITE) #define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP -#include +#include #include #include @@ -107,6 +107,8 @@ private : XMLByte fBuffer[CURL_MAX_WRITE_SIZE]; XMLByte* fBufferHeadPtr; XMLByte* fBufferTailPtr; + + logging::Category& m_log; }; // CurlURLInputStream -- 2.1.4