Imported Upstream version 7.50.2
[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, \fBrunning_handles\fP points to 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 \fIcurl_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
57 \fICURLMOPT_SOCKETFUNCTION(3)\fP option to \fIcurl_multi_setopt(3)\fP. They
58 update the status with changes since the previous time the callback was
59 called.
60
61 Get the timeout time by setting the \fICURLMOPT_TIMERFUNCTION(3)\fP option
62 with \fIcurl_multi_setopt(3)\fP. Your application will then get called with
63 information on how long to wait for socket actions at most before doing the
64 timeout action: call the \fIcurl_multi_socket_action(3)\fP function with the
65 \fBsockfd\fP argument set to CURL_SOCKET_TIMEOUT. You can also use the
66 \fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
67 for an event-based system using the callback is far better than relying on
68 polling the timeout value.
69 .SH "CALLBACK DETAILS"
70
71 The socket \fBcallback\fP function uses a prototype like this
72 .nf
73
74   int curl_socket_callback(CURL *easy,      /* easy handle */
75                            curl_socket_t s, /* socket */
76                            int action,      /* see values below */
77                            void *userp,    /* private callback pointer */
78                            void *socketp); /* private socket pointer,
79                                               \fBNULL\fP if not
80                                               previously assigned with
81                                               \fIcurl_multi_assign(3)\fP */
82
83 .fi
84 The callback MUST return 0.
85
86 The \fIeasy\fP argument is a pointer to the easy handle that deals with this
87 particular socket. Note that a single handle may work with several sockets
88 simultaneously.
89
90 The \fIs\fP argument is the actual socket value as you use it within your
91 system.
92
93 The \fIaction\fP argument to the callback has one of five values:
94 .RS
95 .IP "CURL_POLL_NONE (0)"
96 register, not interested in readiness (yet)
97 .IP "CURL_POLL_IN (1)"
98 register, interested in read readiness
99 .IP "CURL_POLL_OUT (2)"
100 register, interested in write readiness
101 .IP "CURL_POLL_INOUT (3)"
102 register, interested in both read and write readiness
103 .IP "CURL_POLL_REMOVE (4)"
104 unregister
105 .RE
106
107 The \fIsocketp\fP argument is a private pointer you have previously set with
108 \fIcurl_multi_assign(3)\fP to be associated with the \fIs\fP socket. If no
109 pointer has been set, socketp will be NULL. This argument is of course a
110 service to applications that want to keep certain data or structs that are
111 strictly associated to the given socket.
112
113 The \fIuserp\fP argument is a private pointer you have previously set with
114 \fIcurl_multi_setopt(3)\fP and the CURLMOPT_SOCKETDATA option.
115 .SH "RETURN VALUE"
116 CURLMcode type, general libcurl multi interface error code.
117
118 Before version 7.20.0: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this
119 basically means that you should call \fIcurl_multi_socket_action(3)\fP again
120 before you wait for more actions on libcurl's sockets. You don't have to do it
121 immediately, but the return code means that libcurl may have more data
122 available to return or that there may be more data to send off before it is
123 "satisfied".
124
125 The return code from this function is for the whole multi stack.  Problems
126 still might have occurred on individual transfers even when one of these
127 functions return OK.
128 .SH "TYPICAL USAGE"
129 1. Create a multi handle
130
131 2. Set the socket callback with CURLMOPT_SOCKETFUNCTION
132
133 3. Set the timeout callback with CURLMOPT_TIMERFUNCTION, to get to know what
134 timeout value to use when waiting for socket activities.
135
136 4. Add easy handles with curl_multi_add_handle()
137
138 5. Provide some means to manage the sockets libcurl is using, so you can check
139 them for activity. This can be done through your application code, or by way
140 of an external library such as libevent or glib.
141
142 6. Call curl_multi_socket_action(..., CURL_SOCKET_TIMEOUT, 0, ...)
143 to kickstart everything. To get one or more callbacks called.
144
145 7. Wait for activity on any of libcurl's sockets, use the timeout value your
146 callback has been told.
147
148 8, When activity is detected, call curl_multi_socket_action() for the
149 socket(s) that got action. If no activity is detected and the timeout expires,
150 call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP.
151 .SH AVAILABILITY
152 This function was added in libcurl 7.15.4, and is deemed stable since 7.16.0.
153 .SH "SEE ALSO"
154 .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
155 .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
156 .BR "the hiperfifo.c example"