title: C++ libcurl http response code issues
body: <p>This issue/quirk/side-effect is driving me crazy. Near the bottom the code, the response code of the HTTP interaction is passed by reference into responseCode_. However it often comes out as 0 even though the site can otherwise be accessed, and returns too quickly to be a timeout...</p>
  
  <p>All variables are defined, the code below is just a snippet of a C++ method in a class. Any var_ variables are instance based. It runs on several threads, but that should not be a problem. Each class that uses libcurl has its own instance on the respective threads.</p>
  
  <p>Thanks in advance for any ideas or advice...</p>
  
  <pre><code> CURL *curl;
   curl = curl_easy_init();
   //The URL
   curl_easy_setopt(curl, CURLOPT_URL, url.getURLString().c_str());
   //Timeout
   curl_easy_setopt(curl, CURLOPT_TIMEOUT, &amp;timeout_);
   //disable signals to use with threads
   curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
   //Redirecting
   curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5);
   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
   //Writing callback
   curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, &amp;writerh);
   curl_easy_setopt(curl, CURLOPT_HEADERDATA, &amp;head_);
   //Writing callback
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &amp;writerb);
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;body_);
   //Headers
   struct curl_slist *headers = NULL;
   for (std::map&lt;std::string, std::string&gt;::iterator itr = requestHeaders_.begin(); itr != requestHeaders_.end(); itr++) {
    std::stringstream header;
    header &lt;&lt; itr-&gt;first &lt;&lt; ": " &lt;&lt; itr-&gt;second;
    headers = curl_slist_append(headers, header.str().c_str());
   }
   curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
   //UA
   curl_easy_setopt(curl, CURLOPT_USERAGENT, "RDFaS-Bot/1.0 (+http://www.rdfas.com/bot)");
   curl_easy_perform(curl); /* ignores error */
   //Response code
   curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &amp;responseCode_);
   //clean headers
   curl_slist_free_all(headers);
   curl_easy_cleanup(curl);
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p><code>curl_easy_perform</code> was not returning CURLE_OK when the response code was 0, as the marked answer explains. However debug hooks are very useful too and an excellent suggestion</p>