cURL / Mailing Lists / curl-library / Single Mail

curl-library

Timeout & crash Issue

From: <Gunn_Fergal_at_emc.com>
Date: Fri, 19 Mar 2004 09:58:19 -0000

I've seen some issues when using libcurl. We are using Curl 7.10.5
 
1) Our program is crashing out on us at the same place every time (see red
line below).
        "string out = outbuf.str();"
    The thing that makes this all the more hard to debug is that we have no
debug or trace
    information when it does crash. The program just stops and not core
file or error log.
    Is there some setting we must set in order to get debug info???
 
2) The http request we are making sometimes fails to return and I tried to
use the CURLOPT_TIMEOUT
    setting below to interrupt a request. This has not worked for me
though. Is there another
    setting that needs to be set in conjunction with CURLOPT_TIMEOUT??
 
I'd appreciate any help with these problems as I have only very minimal Curl
experience.
 
Here's the problematic code
 
void XHMP::GetXmlData(std::string & xml_data, const bool secure)
{
    try
    {
        CURL *curl;
        ostrstream outbuf;
        string url;
 
        curl = curl_easy_init();
        if (curl != NULL)
        {
            struct curl_slist *headers=NULL;
 
            url = secure ? "https://" : "http://";
 
            url += m_host;
 
            url += secure ? "" : ":8000";
    
            url += "/servlets/CelerraManager" ;
 
            curl_easy_setopt(curl, CURLOPT_URL,url.c_str());
 
            headers = curl_slist_append(headers, "Content-Type: text/xml");
 
            string user = "EMCXMPUser: " + m_uname;
            headers = curl_slist_append(headers, user.c_str());
 
            headers = curl_slist_append(headers, "EMCXMPAction: mtr");
 
            if (secure)
            {
              curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
              curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);
            }
 

            curl_easy_setopt(curl, CURLOPT_POSTFIELDS,m_XmlString.c_str() );
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
 

            curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,&curl_write_hook);
 
            curl_easy_setopt(curl,CURLOPT_FILE,&outbuf);
            curl_easy_setopt(curl,CURLOPT_TIMEOUT,30);
 
            char errorBuf[CURL_ERROR_SIZE];
            curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,&errorBuf);

            int status = curl_easy_perform(curl);
            if (status == 0)
            {
                string out = outbuf.str();
                int index = out.find_last_of("</Packet>");
                xml_data = out.substr(0,index+1);
            }
            curl_slist_free_all(headers);
            curl_easy_cleanup(curl);
        }
}
 

size_t XHMP::curl_write_hook(void *ptr, size_t size, size_t nmemb, void
*stream)
{
        // *stream is actually an ostream object
        ostrstream& buf=*(reinterpret_cast<ostrstream*>(stream));
        buf.write(reinterpret_cast<const char*>(ptr),size*nmemb);
        return size*nmemb;
}
 

_________________________________________________________<?xml:namespace
prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Fergal Gunn

Software Engineer

EMC Cork, Software Development ( Phone: + 353 (0)21 493 8277

Ovens, Co. Cork, Ireland. Ê Fax: + 353 (0)21 428 1833

 <http://www.emc.com/> http://www.emc.com * e-mail:
Gunn_Fergal_at_emc.com

_________________________________________________________

 
Received on 2004-03-19