Added error checking for samples.
authorGuenter Knauf <lists@gknw.net>
Wed, 4 Jul 2012 15:03:52 +0000 (17:03 +0200)
committerGuenter Knauf <lists@gknw.net>
Wed, 4 Jul 2012 15:03:52 +0000 (17:03 +0200)
19 files changed:
docs/examples/anyauthput.c
docs/examples/debug.c
docs/examples/fileupload.c
docs/examples/ftpgetresp.c
docs/examples/ftpupload.c
docs/examples/http-post.c
docs/examples/httpcustomheader.c
docs/examples/httpput.c
docs/examples/https.c
docs/examples/persistant.c
docs/examples/pop3s.c
docs/examples/pop3slist.c
docs/examples/post-callback.c
docs/examples/postit2.c
docs/examples/simple.c
docs/examples/simplepost.c
docs/examples/simplesmtp.c
docs/examples/simplessl.c
docs/examples/smtp-tls.c

index a28ecb7690218dd3a13dccae2472879609d0c7cc..5dac0e77921086e5dd1d46b889a453e8447c5387 100644 (file)
@@ -162,6 +162,10 @@ int main(int argc, char **argv)
 
     /* Now run off and do what you've been told! */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 270b497afb0cadaef09db62bdd388ecf805e6cf2..3852bf2ccf315df79741617751267b8f90a674ed 100644 (file)
@@ -132,6 +132,10 @@ int main(void)
 
     curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 756367b6b8a8c1fc818966640a0cda4f2f14c061..665eca0af9ddc8ea1c544df662e4aa1e994a7042 100644 (file)
@@ -64,14 +64,21 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK) {
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
-    /* now extract transfer info */
-    curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
-    curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
+    }
+    else {
+      /* now extract transfer info */
+      curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
+      curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
 
-    fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
-            speed_upload, total_time);
+      fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
+              speed_upload, total_time);
 
+    }
     /* always cleanup */
     curl_easy_cleanup(curl);
   }
index 29290a31d057184fa261468aea2db92ec9a05764..db96a3a13b2540b6b7333f7c4757f0dc255f0c8b 100644 (file)
@@ -60,6 +60,10 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
     curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile);
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 9928b9e81d8ebc17506ead9639af1b9b46fcd1d6..e79f8d842ae460ea7b1977f2332228f29f7188c7 100644 (file)
@@ -122,6 +122,10 @@ int main(void)
 
     /* Now run off and do what you've been told! */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* clean up the FTP commands list */
     curl_slist_free_all (headerlist);
index 22de628ca007b6a7f66d2af735d1e02827c33193..80f2b343b644ef59d5600ca7c40bede572169e9a 100644 (file)
@@ -38,6 +38,10 @@ int main(void)
 
     /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 077df2164b630e85457f7992f7d14f7ed5248367..5c013750f078b79713eefea29cad759c3cdc01a7 100644 (file)
@@ -38,10 +38,18 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_URL, "localhost");
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* redo request with our own custom Accept: */
     res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index f04618f96fde0a490a34fb70de2838e743c76fb6..fbbca9448b539d94ee90263521e09abdb3773556 100644 (file)
@@ -110,6 +110,10 @@ int main(int argc, char **argv)
 
     /* Now run off and do what you've been told! */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 984357e37f4628aa41b45defccac4b990f79a500..8bfd90cac95237f25f150fad637fa5768e7f84cf 100644 (file)
@@ -55,7 +55,12 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
 #endif
 
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 2d57e4907fc58d54c35828efefcc31f2f2a29054..0917dfdb81750a72b2ce202dd31e215e3da716a1 100644 (file)
@@ -37,12 +37,24 @@ int main(void)
 
     /* get the first document */
     curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
+
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* get another document from the same server using the same
        connection */
     curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/docs/");
+
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 4a2e8fdebcf48bd25791e703992dff6f3e066331..44d7c80d0f56716fb658b94af01a648b39acba9c 100644 (file)
@@ -59,7 +59,12 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
 #endif
 
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 54cb287843143b084a31c8b3673f1e74c3e9044c..9d9668fa0a7ad12dbfa32a67e3ecea81b850c727 100644 (file)
@@ -59,7 +59,12 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
 #endif
 
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index adadaf80328636f1717a846b6d16ddeacb481f0a..9736d8854bc13f4d7afce97cd82be8e3f4c508e1 100644 (file)
@@ -120,6 +120,10 @@ int main(void)
 
     /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 63c2484673d398780b160ac9115e9035b8db97ec..67dcc1330be4598346ae52898d3023fcbbdbaa14 100644 (file)
@@ -83,7 +83,13 @@ int main(int argc, char *argv[])
       /* only disable 100-continue header if explicitly requested */
       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
     curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 55877f8b27a00298e18ec4e279f08a02573b5cfe..cb23b7ae3d7d5af065d3038d3d46c07aedc7132a 100644 (file)
@@ -30,7 +30,13 @@ int main(void)
   curl = curl_easy_init();
   if(curl) {
     curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 3c8571919ccd61bb66866535909c001b3e20a2bb..8657771f46ad45ea9d26d2ba57e981e854f64456 100644 (file)
@@ -39,7 +39,12 @@ int main(void)
        itself */
     curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
 
+    /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* always cleanup */
     curl_easy_cleanup(curl);
index 84429f5bf4a3894d492230c1741b5584ace3c2a6..df85162424347e692d10cd0436b650ea6e0ad63a 100644 (file)
@@ -65,6 +65,10 @@ int main(void)
 
     /* send the message (including headers) */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* free the list of recipients */
     curl_slist_free_all(recipients);
index 46a3783291a2c8b6ae168ea0ceb06c19b83e2bf1..b77c276e459a3d93554a1a127a190e9710c89e60 100644 (file)
@@ -118,7 +118,13 @@ int main(void)
       /* disconnect if we can't validate server's cert */
       curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);
 
+      /* Perform the request, res will get the return code */
       res = curl_easy_perform(curl);
+      /* Check for errors */
+      if(res != CURLE_OK)
+        fprintf(stderr, "curl_easy_perform() failed: %s\n",
+                curl_easy_strerror(res));
+
       break;                   /* we are done... */
     }
     /* always cleanup */
index 8e2603fa45a96ece87b6a2366ca5bd688d0bb940..3635c103f2608a457f7271d3b93e98806732bb7a 100644 (file)
@@ -139,6 +139,10 @@ int main(void)
 
     /* send the message (including headers) */
     res = curl_easy_perform(curl);
+    /* Check for errors */
+    if(res != CURLE_OK)
+      fprintf(stderr, "curl_easy_perform() failed: %s\n",
+              curl_easy_strerror(res));
 
     /* free the list of recipients and clean up */
     curl_slist_free_all(recipients);