curl_multi_assign.3 3.1 KB

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