CURLOPT_CLOSESOCKETFUNCTION.3 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_CLOSESOCKETFUNCTION 3 "16 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_CLOSESOCKETFUNCTION \- callback to socket close replacement
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. int closesocket_callback(void *clientp, curl_socket_t item);
  32. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CLOSESOCKETFUNCTION,
  33. closesocket_callback);
  34. .fi
  35. .SH DESCRIPTION
  36. Pass a pointer to your callback function, which should match the prototype
  37. shown above.
  38. This callback function gets called by libcurl instead of the \fIclose(3)\fP or
  39. \fIclosesocket(3)\fP call when sockets are closed (not for any other file
  40. descriptors). This is pretty much the reverse to the
  41. \fICURLOPT_OPENSOCKETFUNCTION(3)\fP option. Return 0 to signal success and 1
  42. if there was an error.
  43. The \fIclientp\fP pointer is set with
  44. \fICURLOPT_CLOSESOCKETDATA(3)\fP. \fIitem\fP is the socket libcurl wants to be
  45. closed.
  46. .SH DEFAULT
  47. By default libcurl uses the standard socket close function.
  48. .SH PROTOCOLS
  49. All
  50. .SH EXAMPLE
  51. .nf
  52. static int closesocket(void *clientp, curl_socket_t item)
  53. {
  54. printf("libcurl wants to close %d now\\n", (int)item);
  55. return 0;
  56. }
  57. /* call this function to close sockets */
  58. curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
  59. curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
  60. .fi
  61. .SH AVAILABILITY
  62. Added in 7.21.7
  63. .SH RETURN VALUE
  64. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  65. .SH "SEE ALSO"
  66. .BR CURLOPT_CLOSESOCKETDATA "(3), " CURLOPT_OPENSOCKETFUNCTION "(3), "