1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLMOPT_SOCKETDATA
5Section: 3
6Source: libcurl
7See-also:
8  - CURLMOPT_SOCKETFUNCTION (3)
9  - CURLMOPT_TIMERFUNCTION (3)
10  - curl_multi_socket_action (3)
11Protocol:
12  - All
13---
14
15# NAME
16
17CURLMOPT_SOCKETDATA - custom pointer passed to the socket callback
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETDATA, void *pointer);
25~~~
26
27# DESCRIPTION
28
29A data *pointer* to pass to the socket callback set with the
30CURLMOPT_SOCKETFUNCTION(3) option.
31
32This pointer is not touched by libcurl but is only passed in as the socket
33callback's **clientp** argument.
34
35# DEFAULT
36
37NULL
38
39# EXAMPLE
40
41~~~c
42struct priv {
43  void *ours;
44};
45
46static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
47{
48  struct priv *p = sockp;
49  printf("my ptr: %p\n", p->ours);
50
51  if(what == CURL_POLL_REMOVE) {
52    /* remove the socket from our collection */
53  }
54  if(what & CURL_POLL_IN) {
55    /* wait for read on this socket */
56  }
57  if(what & CURL_POLL_OUT) {
58    /* wait for write on this socket */
59  }
60
61  return 0;
62}
63
64int main(void)
65{
66  struct priv setup;
67  CURLM *multi = curl_multi_init();
68  /* ... use socket callback and custom pointer */
69  curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
70  curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
71}
72~~~
73
74# AVAILABILITY
75
76Added in 7.15.4
77
78# RETURN VALUE
79
80Returns CURLM_OK.
81