blob: e99fb79f2d16d7af586493f009b2848d15909c72 [file] [log] [blame]
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -07001.\" **************************************************************************
2.\" * _ _ ____ _
3.\" * Project ___| | | | _ \| |
4.\" * / __| | | | |_) | |
5.\" * | (__| |_| | _ <| |___
6.\" * \___|\___/|_| \_\_____|
7.\" *
8.\" * Copyright (C) 1998 - 2014, 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.\"
23.TH CURLOPT_SOCKOPTFUNCTION 3 "16 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
24.SH NAME
25CURLOPT_SOCKOPTFUNCTION \- set callback for setting socket options
26.SH SYNOPSIS
27.nf
28#include <curl/curl.h>
29
30typedef enum {
31 CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */
32 CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */
33 CURLSOCKTYPE_LAST /* never use */
34} curlsocktype;
35
36#define CURL_SOCKOPT_OK 0
37#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return
38 CURLE_ABORTED_BY_CALLBACK */
39#define CURL_SOCKOPT_ALREADY_CONNECTED 2
40
41int sockopt_callback(void *clientp,
42 curl_socket_t curlfd,
43 curlsocktype purpose);
44
45CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
46.SH DESCRIPTION
47Pass a pointer to your callback function, which should match the prototype
48shown above.
49
50When set, this callback function gets called by libcurl when the socket has
51been created, but before the connect call to allow applications to change
52specific socket options. The callback's \fIpurpose\fP argument identifies the
53exact purpose for this particular socket:
54
55\fICURLSOCKTYPE_IPCXN\fP for actively created connections or since 7.28.0
56\fICURLSOCKTYPE_ACCEPT\fP for FTP when the connection was setup with PORT/EPSV
57(in earlier versions these sockets weren't passed to this callback).
58
59Future versions of libcurl may support more purposes. libcurl passes the newly
60created socket descriptor to the callback in the \fIcurlfd\fP parameter so
61additional setsockopt() calls can be done at the user's discretion.
62
63The \fIclientp\fP pointer contains whatever user-defined value set using the
64\fICURLOPT_SOCKOPTDATA(3)\fP function.
65
66Return \fICURL_SOCKOPT_OK\fP from the callback on success. Return
67\fICURL_SOCKOPT_ERROR\fP from the callback function to signal an unrecoverable
68error to the library and it will close the socket and return
69\fICURLE_COULDNT_CONNECT\fP.
70Alternatively, the callback function can return
71\fICURL_SOCKOPT_ALREADY_CONNECTED\fP, to tell libcurl that the socket is
72already connected and then libcurl will not attempt to connect it. This allows
73an application to pass in an already connected socket with
74\fICURLOPT_OPENSOCKETFUNCTION(3)\fP and then have this function make libcurl
75not attempt to connect (again).
76.SH DEFAULT
77By default, this callback is NULL and unused.
78.SH PROTOCOLS
79All
80.SH EXAMPLE
81TODO
82.SH AVAILABILITY
83Added in 7.16.0. The \fICURL_SOCKOPT_ALREADY_CONNECTED\fP return code was
84added in 7.21.5.
85.SH RETURN VALUE
86Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
87.SH "SEE ALSO"
88.BR CURLOPT_SOCKOPTDATA "(3), " CURLOPT_OPENSOCKETFUNCTION "(3), "