curl_multi_assign.3 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. .\" generated by cd2nroff 0.1 from curl_multi_assign.md
  2. .TH curl_multi_assign 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_multi_assign \- set data to associate with an internal socket
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd,
  9. void *sockptr);
  10. .fi
  11. .SH DESCRIPTION
  12. This function creates an association in the multi handle between the given
  13. socket and a private pointer of the application. This is designed for
  14. \fIcurl_multi_socket_action(3)\fP uses.
  15. When set, the \fIsockptr\fP pointer is passed to all future socket callbacks
  16. for the specific \fIsockfd\fP socket.
  17. If the given \fIsockfd\fP is not already in use by libcurl, this function
  18. returns an error.
  19. libcurl only keeps one single pointer associated with a socket, so calling
  20. this function several times for the same socket makes the last set pointer get
  21. used.
  22. The idea here being that this association (socket to private pointer) is
  23. something that just about every application that uses this API needs and then
  24. libcurl can just as well do it since it already has the necessary
  25. functionality.
  26. It is acceptable to call this function from your multi callback functions.
  27. .SH PROTOCOLS
  28. This functionality affects all supported protocols
  29. .SH EXAMPLE
  30. .nf
  31. int main(void)
  32. {
  33. CURLM *multi = curl_multi_init();
  34. void *ourstructp; /* pointer to our data */
  35. curl_socket_t fd; /* file descriptor to associate our data with */
  36. /* make our struct pointer associated with socket fd */
  37. CURLMcode mc = curl_multi_assign(multi, fd, ourstructp);
  38. if(mc)
  39. printf("error: %s\\n", curl_multi_strerror(mc));
  40. }
  41. .fi
  42. .SH TYPICAL USAGE
  43. In a typical application you allocate a struct or at least use some kind of
  44. semi\-dynamic data for each socket that we must wait for action on when using
  45. the \fIcurl_multi_socket_action(3)\fP approach.
  46. When our socket\-callback gets called by libcurl and we get to know about yet
  47. another socket to wait for, we can use \fIcurl_multi_assign(3)\fP to point out the
  48. particular data so that when we get updates about this same socket again, we
  49. do not have to find the struct associated with this socket by ourselves.
  50. .SH AVAILABILITY
  51. Added in curl 7.15.5
  52. .SH RETURN VALUE
  53. The standard CURLMcode for multi interface error codes.
  54. .SH SEE ALSO
  55. .BR curl_multi_setopt (3),
  56. .BR curl_multi_socket_action (3)