2

while I'm calling curl_easy_perform() it's crashing and I'm getting "SSL read: error:00000000:lib(0):func(0):reason(0), errno 110". Need help to resolve this.

NOTE: After curl_easy_perform sends http1.1 command and before it receives http 200 OK, if internet is disconnected then this error comes.

if (curl) {
   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
   curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
   curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

   curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, read_data);
   //url_easy_setopt(curl, CURLOPT_WRITEDATA, client);
   curl_easy_setopt(curl, CURLOPT_URL, "https://***.com:1027/page");  
   curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
   curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 0);
   printf("sending perform request\n");
   try{
   res = curl_easy_perform(curl); // Perform the request, res will get the return code 
   printf("%s",curl_easy_strerror(res));
   }catch(int e){
       printf("catch the error\n");
       fflush(stdout);
   }
   printf("perform done");

   if (res != CURLE_OK) { /* Check for errors */
       fprintf(stderr, "curl_easy_perform() failed: %s\n",
               curl_easy_strerror(res));
       printf(" Uploading failed \n");
       fflush(stdout);
       result = 0;
   }
  • 1
    Make sure you're using `CURLOPT_SSL_VERIFYHOST=true` and `CURLOPT_SSL_VERIFYPEER=2` (the default values anyway, so you don't need to set them), [otherwise your connection is vulnerable to MITM attacks](http://stackoverflow.com/a/13742121/372643). You will indeed to set up `CURLOPT_CAINFO` (or `CAPATH`) correctly for this too. – Bruno Nov 21 '14 at 11:09
  • @bruno i'm still getting the same error – Chitresh Sinha Dec 09 '14 at 09:55
  • After curl_easy_perform sends http1.1 command and before it receives http 200 OK, if internet is disconnected then this error comes. – Chitresh Sinha Dec 09 '14 at 13:01
  • Not sure what you mean after your edit. If you mean this only occurs when your internet is disconnected (after sending the request, but before receiving the response), getting a read error when you are disconnected shouldn't be a big surprise... – Bruno Dec 09 '14 at 13:12
  • @bruno I want to know how to handle this error. I've tried try-catch and other signal handlers but i'm not able to catch this error. – Chitresh Sinha Dec 10 '14 at 07:02
  • Your `curl_easy_perform function` call is a **C** function inside a try/catch block. Exceptions are a C++ thing so `curl_easy_perform` will never throw an exception. That's why it's using return codes to signal errors. – Frak Aug 21 '17 at 13:54

0 Answers0