curl_multi_assign.3 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, 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. .\" **************************************************************************
  22. .TH curl_multi_assign 3 "9 Jul 2006" "libcurl 7.16.0" "libcurl Manual"
  23. .SH NAME
  24. curl_multi_assign \- set data to associate with an internal socket
  25. .SH SYNOPSIS
  26. .nf
  27. #include <curl/curl.h>
  28. CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd,
  29. void *sockptr);
  30. .fi
  31. .SH DESCRIPTION
  32. This function creates an association in the multi handle between the given
  33. socket and a private pointer of the application. This is designed for
  34. \fIcurl_multi_socket_action(3)\fP uses.
  35. When set, the \fIsockptr\fP pointer will be passed to all future socket
  36. callbacks for the specific \fIsockfd\fP socket.
  37. If the given \fIsockfd\fP is not already in use by libcurl, this function will
  38. return an error.
  39. libcurl only keeps one single pointer associated with a socket, so calling
  40. this function several times for the same socket will make the last set pointer
  41. get used.
  42. The idea here being that this association (socket to private pointer) is
  43. something that just about every application that uses this API will need and
  44. then libcurl can just as well do it since it already has an internal hash
  45. table lookup for this.
  46. It is acceptable to call this function from your multi callback functions.
  47. .SH EXAMPLE
  48. .nf
  49. /* make our struct pointer associated with socket fd */
  50. mc = curl_multi_assign(multi_handle, fd, ourstructp);
  51. .fi
  52. .SH AVAILABILITY
  53. Added in 7.15.5
  54. .SH RETURN VALUE
  55. The standard CURLMcode for multi interface error codes.
  56. .SH TYPICAL USAGE
  57. In a typical application you allocate a struct or at least use some kind of
  58. semi-dynamic data for each socket that we must wait for action on when using
  59. the \fIcurl_multi_socket_action(3)\fP approach.
  60. When our socket-callback gets called by libcurl and we get to know about yet
  61. another socket to wait for, we can use \fIcurl_multi_assign(3)\fP to point out
  62. the particular data so that when we get updates about this same socket again,
  63. we do not have to find the struct associated with this socket by ourselves.
  64. .SH "SEE ALSO"
  65. .BR curl_multi_setopt "(3), " curl_multi_socket_action "(3) "