tizen 2.3.1 release
[external/curl.git] / docs / examples / sendrecv.c
index ad5ddd1..88fddf5 100644 (file)
@@ -1,20 +1,32 @@
-/*****************************************************************************
+/***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
  *                             / __| | | | |_) | |
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * An example of curl_easy_send() and curl_easy_recv() usage.
+ * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
- */
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+/* An example of curl_easy_send() and curl_easy_recv() usage. */
 
 #include <stdio.h>
 #include <string.h>
 #include <curl/curl.h>
 
 /* Auxiliary function that waits on the socket. */
-static int wait_on_socket(int sockfd, int for_recv, long timeout_ms)
+static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
 {
   struct timeval tv;
   fd_set infd, outfd, errfd;
@@ -49,8 +61,10 @@ int main(void)
   CURLcode res;
   /* Minimalistic http request */
   const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n";
-  int sockfd; /* socket */
+  curl_socket_t sockfd; /* socket */
+  long sockextr;
   size_t iolen;
+  curl_off_t nread;
 
   curl = curl_easy_init();
   if(curl) {
@@ -65,9 +79,11 @@ int main(void)
       return 1;
     }
 
-    /* Extract the socket from the curl handle - we'll need it
-     * for waiting */
-    res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
+    /* Extract the socket from the curl handle - we'll need it for waiting.
+     * Note that this API takes a pointer to a 'long' while we use
+     * curl_socket_t for sockets otherwise.
+     */
+    res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
 
     if(CURLE_OK != res)
     {
@@ -75,6 +91,8 @@ int main(void)
       return 1;
     }
 
+    sockfd = sockextr;
+
     /* wait for the socket to become ready for sending */
     if(!wait_on_socket(sockfd, 0, 60000L))
     {
@@ -105,7 +123,9 @@ int main(void)
       if(CURLE_OK != res)
         break;
 
-      printf("Received %u bytes.\n", iolen);
+      nread = (curl_off_t)iolen;
+
+      printf("Received %" CURL_FORMAT_CURL_OFF_T " bytes.\n", nread);
     }
 
     /* always cleanup */