Skip to content

Commit f0b7b10

Browse files
committed
CURLMOPT_SOCKETFUNCTION.3: clarified
Moved away the callback explanation from curl_multi_socket_action.3 and expanded it somewhat. Closes curl#4006
1 parent 4da5794 commit f0b7b10

File tree

2 files changed

+26
-76
lines changed

2 files changed

+26
-76
lines changed

docs/libcurl/curl_multi_socket_action.3

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.\" * | (__| |_| | _ <| |___
66
.\" * \___|\___/|_| \_\_____|
77
.\" *
8-
.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
8+
.\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
99
.\" *
1010
.\" * This software is licensed as described in the file COPYING, which
1111
.\" * you should have received as part of this distribution. The terms
@@ -43,15 +43,14 @@ libcurl will test the descriptor internally. It is also permissible to pass
4343
CURL_SOCKET_TIMEOUT to the \fBsockfd\fP parameter in order to initiate the
4444
whole process or when a timeout occurs.
4545

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.
46+
At return, \fBrunning_handles\fP points to the number of running easy handles
47+
within the multi handle. When this number reaches zero, all transfers are
48+
complete/done. When you call \fIcurl_multi_socket_action(3)\fP on a specific
49+
socket and the counter decreases by one, it DOES NOT necessarily mean that
50+
this exact socket/transfer is the one that completed. Use
51+
\fIcurl_multi_info_read(3)\fP to figure out which easy handle that completed.
5352

54-
The \fIcurl_multi_socket_action(3)\fP functions inform the application about
53+
The \fIcurl_multi_socket_action(3)\fP function informs the application about
5554
updates in the socket (file descriptor) status by doing none, one, or multiple
5655
calls to the socket callback function set with the
5756
\fICURLMOPT_SOCKETFUNCTION(3)\fP option to \fIcurl_multi_setopt(3)\fP. They
@@ -66,65 +65,6 @@ timeout action: call the \fIcurl_multi_socket_action(3)\fP function with the
6665
\fIcurl_multi_timeout(3)\fP function to poll the value at any given time, but
6766
for an event-based system using the callback is far better than relying on
6867
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 \fICURLMOPT_SOCKETDATA(3)\fP 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.
12868
.SH "TYPICAL USAGE"
12969
1. Create a multi handle
13070

docs/libcurl/opts/CURLMOPT_SOCKETFUNCTION.3

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.\" * | (__| |_| | _ <| |___
66
.\" * \___|\___/|_| \_\_____|
77
.\" *
8-
.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
8+
.\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
99
.\" *
1010
.\" * This software is licensed as described in the file COPYING, which
1111
.\" * you should have received as part of this distribution. The terms
@@ -38,14 +38,24 @@ CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION, socket_callb
3838
Pass a pointer to your callback function, which should match the prototype
3939
shown above.
4040

41-
When the \fIcurl_multi_socket_action(3)\fP function runs, it informs the
41+
When the \fIcurl_multi_socket_action(3)\fP function is called, it informs the
4242
application about updates in the socket (file descriptor) status by doing
43-
none, one, or multiple calls to the \fBsocket_callback\fP. The callback gets
44-
status updates with changes since the previous time the callback was called.
45-
If the given callback pointer is NULL, no callback will be called. Set the
46-
callback's \fBuserp\fP argument with \fICURLMOPT_SOCKETDATA(3)\fP. See
47-
\fIcurl_multi_socket_action(3)\fP for more details on how the callback is used
48-
and should work.
43+
none, one, or multiple calls to the \fBsocket_callback\fP. The callback
44+
function gets status updates with changes since the previous time the callback
45+
was called. If the given callback pointer is set to NULL, no callback will be
46+
called.
47+
.SH "CALLBACK ARGUMENTS"
48+
\fIeasy\fP identifies the specific transfer for which this update is related.
49+
50+
\fIs\fP is the specific socket this function invocation concerns. If the
51+
\fBwhat\fP argument is not CURL_POLL_REMOVE then it holds information about
52+
what activity on this socket the application is supposed to
53+
monitor. Subsequent calls to this callback might update the \fBwhat\fP bits
54+
for a socket that is alredy monitored.
55+
56+
\fBuserp\fP is set with \fICURLMOPT_SOCKETDATA(3)\fP.
57+
58+
\fBsocketp\fP is set with \fIcurl_multi_assign(3)\fP or will be NULL.
4959

5060
The \fBwhat\fP parameter informs the callback on the status of the given
5161
socket. It can hold one of these values:

0 commit comments

Comments
 (0)