CURLMOPT_SOCKETFUNCTION.3 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, Daniel Stenberg, <[email protected]>, 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 CURLMOPT_SOCKETFUNCTION 3 "May 17, 2022" "libcurl 7.85.0" "curl_multi_setopt options"
  26. .SH NAME
  27. CURLMOPT_SOCKETFUNCTION \- callback informed about what to wait for
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. int socket_callback(CURL *easy, /* easy handle */
  32. curl_socket_t s, /* socket */
  33. int what, /* describes the socket */
  34. void *userp, /* private callback pointer */
  35. void *socketp); /* private socket pointer */
  36. CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION, socket_callback);
  37. .SH DESCRIPTION
  38. Pass a pointer to your callback function, which should match the prototype
  39. shown above.
  40. When the \fIcurl_multi_socket_action(3)\fP function is called, it informs the
  41. application about updates in the socket (file descriptor) status by doing
  42. none, one, or multiple calls to the \fBsocket_callback\fP. The callback
  43. function gets status updates with changes since the previous time the callback
  44. was called. If the given callback pointer is set to NULL, no callback will be
  45. called.
  46. .SH "CALLBACK ARGUMENTS"
  47. \fIeasy\fP identifies the specific transfer for which this update is related.
  48. \fIs\fP is the specific socket this function invocation concerns. If the
  49. \fBwhat\fP argument is not CURL_POLL_REMOVE then it holds information about
  50. what activity on this socket the application is supposed to
  51. monitor. Subsequent calls to this callback might update the \fBwhat\fP bits
  52. for a socket that is already monitored.
  53. The socket callback should return 0 on success, and -1 on error. If this
  54. callback returns error, \fBall\fP transfers currently in progress in this
  55. multi handle will be aborted and fail.
  56. \fBuserp\fP is set with \fICURLMOPT_SOCKETDATA(3)\fP.
  57. \fBsocketp\fP is set with \fIcurl_multi_assign(3)\fP or will be NULL.
  58. The \fBwhat\fP parameter informs the callback on the status of the given
  59. socket. It can hold one of these values:
  60. .IP CURL_POLL_IN
  61. Wait for incoming data. For the socket to become readable.
  62. .IP CURL_POLL_OUT
  63. Wait for outgoing data. For the socket to become writable.
  64. .IP CURL_POLL_INOUT
  65. Wait for incoming and outgoing data. For the socket to become readable or
  66. writable.
  67. .IP CURL_POLL_REMOVE
  68. The specified socket/file descriptor is no longer used by libcurl.
  69. .SH DEFAULT
  70. NULL (no callback)
  71. .SH PROTOCOLS
  72. All
  73. .SH EXAMPLE
  74. .nf
  75. static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
  76. {
  77. GlobalInfo *g = (GlobalInfo*) cbp;
  78. SockInfo *fdp = (SockInfo*) sockp;
  79. if(what == CURL_POLL_REMOVE) {
  80. remsock(fdp);
  81. }
  82. else {
  83. if(!fdp) {
  84. addsock(s, e, what, g);
  85. }
  86. else {
  87. setsock(fdp, s, e, what, g);
  88. }
  89. }
  90. return 0;
  91. }
  92. main()
  93. {
  94. GlobalInfo setup;
  95. /* ... use socket callback and custom pointer */
  96. curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
  97. curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
  98. }
  99. .fi
  100. .SH AVAILABILITY
  101. Added in 7.15.4
  102. .SH RETURN VALUE
  103. Returns CURLM_OK.
  104. .SH "SEE ALSO"
  105. .BR CURLMOPT_SOCKETDATA "(3), " curl_multi_socket_action "(3), "
  106. .BR CURLMOPT_TIMERFUNCTION "(3) "