CURLMOPT_SOCKETFUNCTION.3 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2017, 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.haxx.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. .\" **************************************************************************
  22. .\"
  23. .TH CURLMOPT_SOCKETFUNCTION 3 "May 31, 2017" "libcurl 7.61.1" "curl_multi_setopt options"
  24. .SH NAME
  25. CURLMOPT_SOCKETFUNCTION \- callback informed about what to wait for
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. int socket_callback(CURL *easy, /* easy handle */
  30. curl_socket_t s, /* socket */
  31. int what, /* describes the socket */
  32. void *userp, /* private callback pointer */
  33. void *socketp); /* private socket pointer */
  34. CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION, socket_callback);
  35. .SH DESCRIPTION
  36. Pass a pointer to your callback function, which should match the prototype
  37. shown above.
  38. When the \fIcurl_multi_socket_action(3)\fP function runs, it informs the
  39. application about updates in the socket (file descriptor) status by doing
  40. none, one, or multiple calls to the \fBsocket_callback\fP. The callback gets
  41. status updates with changes since the previous time the callback was called.
  42. If the given callback pointer is NULL, no callback will be called. Set the
  43. callback's \fBuserp\fP argument with \fICURLMOPT_SOCKETDATA(3)\fP. See
  44. \fIcurl_multi_socket_action(3)\fP for more details on how the callback is used
  45. and should work.
  46. The \fBwhat\fP parameter informs the callback on the status of the given
  47. socket. It can hold one of these values:
  48. .IP CURL_POLL_IN
  49. Wait for incoming data. For the socket to become readable.
  50. .IP CURL_POLL_OUT
  51. Wait for outgoing data. For the socket to become writable.
  52. .IP CURL_POLL_INOUT
  53. Wait for incoming and outgoing data. For the socket to become readable or
  54. writable.
  55. .IP CURL_POLL_REMOVE
  56. The specified socket/file descriptor is no longer used by libcurl.
  57. .SH DEFAULT
  58. NULL (no callback)
  59. .SH PROTOCOLS
  60. All
  61. .SH EXAMPLE
  62. .nf
  63. static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
  64. {
  65. GlobalInfo *g = (GlobalInfo*) cbp;
  66. SockInfo *fdp = (SockInfo*) sockp;
  67. if(what == CURL_POLL_REMOVE) {
  68. remsock(fdp);
  69. }
  70. else {
  71. if(!fdp) {
  72. addsock(s, e, what, g);
  73. }
  74. else {
  75. setsock(fdp, s, e, what, g);
  76. }
  77. }
  78. return 0;
  79. }
  80. main()
  81. {
  82. GlobalInfo setup;
  83. /* ... use socket callback and custom pointer */
  84. curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
  85. curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
  86. }
  87. .fi
  88. .SH AVAILABILITY
  89. Added in 7.15.4
  90. .SH RETURN VALUE
  91. Returns CURLM_OK.
  92. .SH "SEE ALSO"
  93. .BR CURLMOPT_SOCKETDATA "(3), " curl_multi_socket_action "(3), "
  94. .BR CURLMOPT_TIMERFUNCTION "(3) "