Git init
[external/curl.git] / docs / libcurl / curl_multi_socket.3
1 .\"
2 .TH curl_multi_socket 3 "9 Jul 2006" "libcurl 7.16.0" "libcurl Manual"
3 .SH NAME
4 curl_multi_socket \- reads/writes available data
5 .SH SYNOPSIS
6 .nf
7 #include <curl/curl.h>
8 CURLMcode curl_multi_socket(CURLM * multi_handle, curl_socket_t sockfd,
9                             int *running_handles);
10
11 CURLMcode curl_multi_socket_all(CURLM *multi_handle,
12                                 int *running_handles);
13 .fi
14 .SH DESCRIPTION
15 These functions are deprecated. Do not use! See
16 \fIcurl_multi_socket_action(3)\fP instead!
17
18 At return, the integer \fBrunning_handles\fP points to will contain the number
19 of still running easy handles within the multi handle. When this number
20 reaches zero, all transfers are complete/done. Note that when you call
21 \fIcurl_multi_socket_action(3)\fP on a specific socket and the counter
22 decreases by one, it DOES NOT necessarily mean that this exact socket/transfer
23 is the one that completed. Use \fIcurl_multi_info_read(3)\fP to figure out
24 which easy handle that completed.
25
26 The \fBcurl_multi_socket_action(3)\fP functions inform the application about
27 updates in the socket (file descriptor) status by doing none, one, or multiple
28 calls to the socket callback function set with the CURLMOPT_SOCKETFUNCTION
29 option to \fIcurl_multi_setopt(3)\fP. They update the status with changes
30 since the previous time the callback was called.
31
32 Get the timeout time by setting the \fICURLMOPT_TIMERFUNCTION\fP option with
33 \fIcurl_multi_setopt(3)\fP. Your application will then get called with
34 information on how long to wait for socket actions at most before doing the
35 timeout action: call the \fBcurl_multi_socket_action(3)\fP function with the
36 \fBsockfd\fP argument set to CURL_SOCKET_TIMEOUT. You can also use the
37 \fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
38 for an event-based system using the callback is far better than relying on
39 polling the timeout value.
40
41 Usage of \fIcurl_multi_socket(3)\fP is deprecated, whereas the function is
42 equivalent to \fIcurl_multi_socket_action(3)\fP with \fBev_bitmask\fP set to
43 0.
44
45 Force libcurl to (re-)check all its internal sockets and transfers instead of
46 just a single one by calling \fBcurl_multi_socket_all(3)\fP. Note that there
47 should not be any reason to use this function!
48 .SH "CALLBACK DETAILS"
49
50 The socket \fBcallback\fP function uses a prototype like this
51 .nf
52
53   int curl_socket_callback(CURL *easy,      /* easy handle */
54                            curl_socket_t s, /* socket */
55                            int action,      /* see values below */
56                            void *userp,    /* private callback pointer */
57                            void *socketp); /* private socket pointer */
58
59 .fi
60 The callback MUST return 0.
61
62 The \fIeasy\fP argument is a pointer to the easy handle that deals with this
63 particular socket. Note that a single handle may work with several sockets
64 simultaneously.
65
66 The \fIs\fP argument is the actual socket value as you use it within your
67 system.
68
69 The \fIaction\fP argument to the callback has one of five values:
70 .RS
71 .IP "CURL_POLL_NONE (0)"
72 register, not interested in readiness (yet)
73 .IP "CURL_POLL_IN (1)"
74 register, interested in read readiness
75 .IP "CURL_POLL_OUT (2)"
76 register, interested in write readiness
77 .IP "CURL_POLL_INOUT (3)"
78 register, interested in both read and write readiness
79 .IP "CURL_POLL_REMOVE (4)"
80 unregister
81 .RE
82
83 The \fIsocketp\fP argument is a private pointer you have previously set with
84 \fIcurl_multi_assign(3)\fP to be associated with the \fIs\fP socket. If no
85 pointer has been set, socketp will be NULL. This argument is of course a
86 service to applications that want to keep certain data or structs that are
87 strictly associated to the given socket.
88
89 The \fIuserp\fP argument is a private pointer you have previously set with
90 \fIcurl_multi_setopt(3)\fP and the CURLMOPT_SOCKETDATA option.
91 .SH "RETURN VALUE"
92 CURLMcode type, general libcurl multi interface error code.
93
94 Legacy: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this basically means
95 that you should call \fIcurl_multi_socket(3)\fP again, before you wait for
96 more actions on libcurl's sockets. You don't have to do it immediately, but
97 the return code means that libcurl may have more data available to return or
98 that there may be more data to send off before it is "satisfied".
99
100 In modern libcurls, \fICURLM_CALL_MULTI_PERFORM\fP or
101 \fICURLM_CALL_MULTI_SOKCET\fP should not be returned and no application needs
102 to care about them.
103
104 NOTE that the return code is for the whole multi stack. Problems still might have
105 occurred on individual transfers even when one of these functions
106 return OK.
107 .SH "TYPICAL USAGE"
108 1. Create a multi handle
109
110 2. Set the socket callback with CURLMOPT_SOCKETFUNCTION
111
112 3. Set the timeout callback with CURLMOPT_TIMERFUNCTION, to get to know what
113 timeout value to use when waiting for socket activities.
114
115 4. Add easy handles with curl_multi_add_handle()
116
117 5. Provide some means to manage the sockets libcurl is using, so you can check
118 them for activity. This can be done through your application code, or by way
119 of an external library such as libevent or glib.
120
121 6. Wait for activity on any of libcurl's sockets, use the timeout value your
122 callback has been told
123
124 7, When activity is detected, call curl_multi_socket_action() for the
125 socket(s) that got action. If no activity is detected and the timeout expires,
126 call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP
127
128 8. Go back to step 6.
129 .SH AVAILABILITY
130 This function was added in libcurl 7.15.4, and is deemed stable since
131 7.16.0.
132
133 \fIcurl_multi_socket(3)\fP is deprecated, use
134 \fIcurl_multi_socket_action(3)\fP instead!
135 .SH "SEE ALSO"
136 .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
137 .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
138 .BR "the hiperfifo.c example"