.. 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
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) {
curl_easy_cleanup(curl);
+ close(sockfd);
+
if(res) {
printf("libcurl error: %d\n", res);
return 4;
}
}
+
+#ifdef WIN32
+ WSACleanup();
+#endif
return 0;
}