Imported Upstream version 7.48.0
[platform/upstream/curl.git] / docs / libcurl / curl_multi_socket_action.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2016, 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 .TH curl_multi_socket_action 3 "9 Jul 2006" "libcurl 7.16.0" "libcurl Manual"
23 .SH NAME
24 curl_multi_socket_action \- reads/writes available data given an action
25 .SH SYNOPSIS
26 .nf
27 #include <curl/curl.h>
28
29 CURLMcode curl_multi_socket_action(CURLM * multi_handle,
30                                    curl_socket_t sockfd,
31                                    int ev_bitmask,
32                                    int *running_handles);
33 .fi
34 .SH DESCRIPTION
35 When the application has detected action on a socket handled by libcurl, it
36 should call \fIcurl_multi_socket_action(3)\fP with the \fBsockfd\fP argument
37 set to the socket with the action. When the events on a socket are known, they
38 can be passed as an events bitmask \fBev_bitmask\fP by first setting
39 \fBev_bitmask\fP to 0, and then adding using bitwise OR (|) any combination of
40 events to be chosen from CURL_CSELECT_IN, CURL_CSELECT_OUT or
41 CURL_CSELECT_ERR. When the events on a socket are unknown, pass 0 instead, and
42 libcurl will test the descriptor internally. It is also permissible to pass
43 CURL_SOCKET_TIMEOUT to the \fBsockfd\fP parameter in order to initiate the
44 whole process or when a timeout occurs.
45
46 At return, the integer \fBrunning_handles\fP points to will contain the number
47 of running easy handles within the multi handle. When this number reaches
48 zero, all transfers are complete/done. When you call
49 \fIcurl_multi_socket_action(3)\fP on a specific socket and the counter
50 decreases by one, it DOES NOT necessarily mean that this exact socket/transfer
51 is the one that completed. Use \fIcurl_multi_info_read(3)\fP to figure out
52 which easy handle that completed.
53
54 The \fBcurl_multi_socket_action(3)\fP functions inform the application about
55 updates in the socket (file descriptor) status by doing none, one, or multiple
56 calls to the socket callback function set with the CURLMOPT_SOCKETFUNCTION
57 option to \fIcurl_multi_setopt(3)\fP. They update the status with changes
58 since the previous time the callback was called.
59
60 Get the timeout time by setting the \fICURLMOPT_TIMERFUNCTION\fP option with
61 \fIcurl_multi_setopt(3)\fP. Your application will then get called with
62 information on how long to wait for socket actions at most before doing the
63 timeout action: call the \fBcurl_multi_socket_action(3)\fP function with the
64 \fBsockfd\fP argument set to CURL_SOCKET_TIMEOUT. You can also use the
65 \fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
66 for an event-based system using the callback is far better than relying on
67 polling the timeout value.
68 .SH "CALLBACK DETAILS"
69
70 The socket \fBcallback\fP function uses a prototype like this
71 .nf
72
73   int curl_socket_callback(CURL *easy,      /* easy handle */
74                            curl_socket_t s, /* socket */
75                            int action,      /* see values below */
76                            void *userp,    /* private callback pointer */
77                            void *socketp); /* private socket pointer,
78                                               \fBNULL\fP if not
79                                               previously assigned with
80                                               \fBcurl_multi_assign(3)\fP */
81
82 .fi
83 The callback MUST return 0.
84
85 The \fIeasy\fP argument is a pointer to the easy handle that deals with this
86 particular socket. Note that a single handle may work with several sockets
87 simultaneously.
88
89 The \fIs\fP argument is the actual socket value as you use it within your
90 system.
91
92 The \fIaction\fP argument to the callback has one of five values:
93 .RS
94 .IP "CURL_POLL_NONE (0)"
95 register, not interested in readiness (yet)
96 .IP "CURL_POLL_IN (1)"
97 register, interested in read readiness
98 .IP "CURL_POLL_OUT (2)"
99 register, interested in write readiness
100 .IP "CURL_POLL_INOUT (3)"
101 register, interested in both read and write readiness
102 .IP "CURL_POLL_REMOVE (4)"
103 unregister
104 .RE
105
106 The \fIsocketp\fP argument is a private pointer you have previously set with
107 \fIcurl_multi_assign(3)\fP to be associated with the \fIs\fP socket. If no
108 pointer has been set, socketp will be NULL. This argument is of course a
109 service to applications that want to keep certain data or structs that are
110 strictly associated to the given socket.
111
112 The \fIuserp\fP argument is a private pointer you have previously set with
113 \fIcurl_multi_setopt(3)\fP and the CURLMOPT_SOCKETDATA option.
114 .SH "RETURN VALUE"
115 CURLMcode type, general libcurl multi interface error code.
116
117 Before version 7.20.0: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this
118 basically means that you should call \fIcurl_multi_socket_action(3)\fP again
119 before you wait for more actions on libcurl's sockets. You don't have to do it
120 immediately, but the return code means that libcurl may have more data
121 available to return or that there may be more data to send off before it is
122 "satisfied".
123
124 The return code from this function is for the whole multi stack.  Problems
125 still might have occurred on individual transfers even when one of these
126 functions return OK.
127 .SH "TYPICAL USAGE"
128 1. Create a multi handle
129
130 2. Set the socket callback with CURLMOPT_SOCKETFUNCTION
131
132 3. Set the timeout callback with CURLMOPT_TIMERFUNCTION, to get to know what
133 timeout value to use when waiting for socket activities.
134
135 4. Add easy handles with curl_multi_add_handle()
136
137 5. Provide some means to manage the sockets libcurl is using, so you can check
138 them for activity. This can be done through your application code, or by way
139 of an external library such as libevent or glib.
140
141 6. Call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...)
142 to kickstart everything. To get one or more callbacks called.
143
144 7. Wait for activity on any of libcurl's sockets, use the timeout value your
145 callback has been told.
146
147 8, When activity is detected, call curl_multi_socket_action() for the
148 socket(s) that got action. If no activity is detected and the timeout expires,
149 call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP.
150 .SH AVAILABILITY
151 This function was added in libcurl 7.15.4, and is deemed stable since 7.16.0.
152 .SH "SEE ALSO"
153 .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
154 .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
155 .BR "the hiperfifo.c example"