CURLMOPT_SOCKETFUNCTION.3 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2019, 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 "3 Nov 2016" "libcurl 7.39.0" "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 is called, 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
  41. function gets status updates with changes since the previous time the callback
  42. was called. If the given callback pointer is set to NULL, no callback will be
  43. called.
  44. .SH "CALLBACK ARGUMENTS"
  45. \fIeasy\fP identifies the specific transfer for which this update is related.
  46. \fIs\fP is the specific socket this function invocation concerns. If the
  47. \fBwhat\fP argument is not CURL_POLL_REMOVE then it holds information about
  48. what activity on this socket the application is supposed to
  49. monitor. Subsequent calls to this callback might update the \fBwhat\fP bits
  50. for a socket that is already monitored.
  51. \fBuserp\fP is set with \fICURLMOPT_SOCKETDATA(3)\fP.
  52. \fBsocketp\fP is set with \fIcurl_multi_assign(3)\fP or will be NULL.
  53. The \fBwhat\fP parameter informs the callback on the status of the given
  54. socket. It can hold one of these values:
  55. .IP CURL_POLL_IN
  56. Wait for incoming data. For the socket to become readable.
  57. .IP CURL_POLL_OUT
  58. Wait for outgoing data. For the socket to become writable.
  59. .IP CURL_POLL_INOUT
  60. Wait for incoming and outgoing data. For the socket to become readable or
  61. writable.
  62. .IP CURL_POLL_REMOVE
  63. The specified socket/file descriptor is no longer used by libcurl.
  64. .SH DEFAULT
  65. NULL (no callback)
  66. .SH PROTOCOLS
  67. All
  68. .SH EXAMPLE
  69. .nf
  70. static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
  71. {
  72. GlobalInfo *g = (GlobalInfo*) cbp;
  73. SockInfo *fdp = (SockInfo*) sockp;
  74. if(what == CURL_POLL_REMOVE) {
  75. remsock(fdp);
  76. }
  77. else {
  78. if(!fdp) {
  79. addsock(s, e, what, g);
  80. }
  81. else {
  82. setsock(fdp, s, e, what, g);
  83. }
  84. }
  85. return 0;
  86. }
  87. main()
  88. {
  89. GlobalInfo setup;
  90. /* ... use socket callback and custom pointer */
  91. curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
  92. curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
  93. }
  94. .fi
  95. .SH AVAILABILITY
  96. Added in 7.15.4
  97. .SH RETURN VALUE
  98. Returns CURLM_OK.
  99. .SH "SEE ALSO"
  100. .BR CURLMOPT_SOCKETDATA "(3), " curl_multi_socket_action "(3), "
  101. .BR CURLMOPT_TIMERFUNCTION "(3) "