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