aboutsummaryrefslogtreecommitdiff
path: root/docs/examples
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-05-31 09:26:51 +0200
committerDaniel Stenberg <daniel@haxx.se>2017-05-31 11:56:53 +0200
commit55fcb8485914700132fd1854c9509b66c955efbe (patch)
treea6c46cbe6dc2a799477d5733e0824c6d1ba1d2f2 /docs/examples
parent314a7fa3ceb74f90cc7cce28bef7517ef874f64c (diff)
example/externalsocket.c: make it use CLOSESOCKETFUNCTION too
Diffstat (limited to 'docs/examples')
-rw-r--r--docs/examples/externalsocket.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c
index 80e6598fa..9adb0dc4f 100644
--- a/docs/examples/externalsocket.c
+++ b/docs/examples/externalsocket.c
@@ -58,6 +58,13 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
return written;
}
+static int closesocket(void *clientp, curl_socket_t item)
+{
+ (void)clientp;
+ printf("libcurl wants to close %d now\n", (int)item);
+ return 0;
+}
+
static curl_socket_t opensocket(void *clientp,
curlsocktype purpose,
struct curl_sockaddr *address)
@@ -137,6 +144,10 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
+ /* call this function to close sockets */
+ curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
+ curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
+
/* call this function to set options for the socket */
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);