cURL / Mailing Lists / curl-library / Single Mail

curl-library

[Patch] docs/examples/asiohiper.cpp

From: Gisle Vanem <gvanem_at_yahoo.no>
Date: Sat, 6 Feb 2016 10:20:48 +0100

This example is not quite up-to-date with the latest Boost
or C++ standard. With latest MSVC, I get these errors and
1 warning:

  asiohiper.cpp(365): error C2039: 'cout': is not a member of 'std'

  asiohiper.cpp(431): error C2664: 'CURLcode curl_easy_setopt(CURL *,CURLoption,...)':
  cannot convert argument 3 from 'overloaded-function' to '...'
  asiohiper.cpp(431): note: Context does not allow for disambiguation of overloaded function

  asiohiper.cpp(445): warning C4101: 'rc': unreferenced local variable

With this patch, it builds and works fine:

--- a/asiohiper.cpp 2016-02-05 07:58:11
+++ b/asiohiper.cpp 2016-02-06 09:54:13
@@ -48,6 +48,7 @@
 #include <curl/curl.h>
 #include <boost/asio.hpp>
 #include <boost/bind.hpp>
+#include <iostream>

 #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */

@@ -378,9 +379,9 @@
 }

 /* CURLOPT_CLOSESOCKETFUNCTION */
-static int closesocket(void *clientp, curl_socket_t item)
+static int close_socket(void *clientp, curl_socket_t item)
 {
- fprintf(MSG_OUT, "\nclosesocket : %d", item);
+ fprintf(MSG_OUT, "\nclose_socket : %d", item);

   std::map<curl_socket_t, boost::asio::ip::tcp::socket *>::iterator it = socket_map.find(item);

@@ -427,7 +428,7 @@
   curl_easy_setopt(conn->easy, CURLOPT_OPENSOCKETFUNCTION, opensocket);

   /* call this function to close a socket */
- curl_easy_setopt(conn->easy, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
+ curl_easy_setopt(conn->easy, CURLOPT_CLOSESOCKETFUNCTION, close_socket);

   fprintf(MSG_OUT,
           "\nAdding easy %p to multi %p (%s)", conn->easy, g->multi, url);
@@ -441,7 +442,6 @@
 int main(int argc, char **argv)
 {
   GlobalInfo g;
- CURLMcode rc;

   (void)argc;
   (void)argv;

----------

The renaming of 'closesocket()' is because <winsock2.h> has the same function.

-- 
--gv
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html
Received on 2016-02-06