summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Guibert de Bruet <andygui@gmail.com>2019-03-10 23:15:15 -0400
committerJay Satiro <raysatiro@yahoo.com>2019-03-11 23:02:54 -0400
commit57c70767930c0f0cbf93c56c28442cf34eb6af07 (patch)
tree6f79d8fbc785174ba1211e27c0514ccd7efe2498
parent0bb56392d4d077c5d62c63831536354a29d59f26 (diff)
downloadcurl-57c70767930c0f0cbf93c56c28442cf34eb6af07.tar.gz
examples/externalsocket: add missing close socket calls
.. and for Windows also call WSACleanup since we call WSAStartup. The example is to demonstrate handling the socket independently of libcurl. In this case libcurl is not responsible for creating, opening or closing the socket, it is handled by the application (our example). Fixes https://github.com/curl/curl/pull/3663
-rw-r--r--docs/examples/externalsocket.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c
index 0ac113db3..d89b041b4 100644
--- a/docs/examples/externalsocket.c
+++ b/docs/examples/externalsocket.c
@@ -124,8 +124,10 @@ int main(void)
servaddr.sin_port = htons(PORTNUM);
servaddr.sin_addr.s_addr = inet_addr(IPADDR);
- if(INADDR_NONE == servaddr.sin_addr.s_addr)
+ if(INADDR_NONE == servaddr.sin_addr.s_addr) {
+ close(sockfd);
return 2;
+ }
if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) ==
-1) {
@@ -157,10 +159,16 @@ int main(void)
curl_easy_cleanup(curl);
+ close(sockfd);
+
if(res) {
printf("libcurl error: %d\n", res);
return 4;
}
}
+
+#ifdef WIN32
+ WSACleanup();
+#endif
return 0;
}