Imported Upstream version 7.59.0
[platform/upstream/curl.git] / docs / libcurl / opts / CURLMOPT_SOCKETFUNCTION.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2017, 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.haxx.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 .\"
23 .TH CURLMOPT_SOCKETFUNCTION 3 "May 31, 2017" "libcurl 7.59.0" "curl_multi_setopt options"
24
25 .SH NAME
26 CURLMOPT_SOCKETFUNCTION \- callback informed about what to wait for
27 .SH SYNOPSIS
28 .nf
29 #include <curl/curl.h>
30
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
37 CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION, socket_callback);
38 .SH DESCRIPTION
39 Pass a pointer to your callback function, which should match the prototype
40 shown above.
41
42 When the \fIcurl_multi_socket_action(3)\fP function runs, it informs the
43 application about updates in the socket (file descriptor) status by doing
44 none, one, or multiple calls to the \fBsocket_callback\fP. The callback gets
45 status updates with changes since the previous time the callback was called.
46 If the given callback pointer is NULL, no callback will be called. Set the
47 callback's \fBuserp\fP argument with \fICURLMOPT_SOCKETDATA(3)\fP.  See
48 \fIcurl_multi_socket_action(3)\fP for more details on how the callback is used
49 and should work.
50
51 The \fBwhat\fP parameter informs the callback on the status of the given
52 socket. It can hold one of these values:
53 .IP CURL_POLL_IN
54 Wait for incoming data. For the socket to become readable.
55 .IP CURL_POLL_OUT
56 Wait for outgoing data. For the socket to become writable.
57 .IP CURL_POLL_INOUT
58 Wait for incoming and outgoing data. For the socket to become readable or
59 writable.
60 .IP CURL_POLL_REMOVE
61 The specified socket/file descriptor is no longer used by libcurl.
62 .SH DEFAULT
63 NULL (no callback)
64 .SH PROTOCOLS
65 All
66 .SH EXAMPLE
67 .nf
68 static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
69 {
70   GlobalInfo *g = (GlobalInfo*) cbp;
71   SockInfo *fdp = (SockInfo*) sockp;
72
73   if(what == CURL_POLL_REMOVE) {
74     remsock(fdp);
75   }
76   else {
77     if(!fdp) {
78       addsock(s, e, what, g);
79     }
80     else {
81       setsock(fdp, s, e, what, g);
82     }
83   }
84   return 0;
85 }
86
87 main()
88 {
89   GlobalInfo setup;
90   /* ... use socket callback and custom pointer */
91   curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
92   curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
93 }
94 .fi
95 .SH AVAILABILITY
96 Added in 7.15.4
97 .SH RETURN VALUE
98 Returns CURLM_OK.
99 .SH "SEE ALSO"
100 .BR CURLMOPT_SOCKETDATA "(3), " curl_multi_socket_action "(3), "
101 .BR CURLMOPT_TIMERFUNCTION "(3) "
102