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