Skip to content
Permalink
Browse files

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 #3663
  • Loading branch information...
Andre Guibert de Bruet authored and jay committed Mar 11, 2019
1 parent 0bb5639 commit 57c70767930c0f0cbf93c56c28442cf34eb6af07
Showing with 9 additions and 1 deletion.
  1. +9 −1 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;
}

0 comments on commit 57c7076

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.