Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame^] | 1 | .\" ************************************************************************** |
| 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 |
| 25 | CURLOPT_SOCKOPTFUNCTION \- set callback for setting socket options |
| 26 | .SH SYNOPSIS |
| 27 | .nf |
| 28 | #include <curl/curl.h> |
| 29 | |
| 30 | typedef 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 | |
| 41 | int sockopt_callback(void *clientp, |
| 42 | curl_socket_t curlfd, |
| 43 | curlsocktype purpose); |
| 44 | |
| 45 | CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); |
| 46 | .SH DESCRIPTION |
| 47 | Pass a pointer to your callback function, which should match the prototype |
| 48 | shown above. |
| 49 | |
| 50 | When set, this callback function gets called by libcurl when the socket has |
| 51 | been created, but before the connect call to allow applications to change |
| 52 | specific socket options. The callback's \fIpurpose\fP argument identifies the |
| 53 | exact 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 | |
| 59 | Future versions of libcurl may support more purposes. libcurl passes the newly |
| 60 | created socket descriptor to the callback in the \fIcurlfd\fP parameter so |
| 61 | additional setsockopt() calls can be done at the user's discretion. |
| 62 | |
| 63 | The \fIclientp\fP pointer contains whatever user-defined value set using the |
| 64 | \fICURLOPT_SOCKOPTDATA(3)\fP function. |
| 65 | |
| 66 | Return \fICURL_SOCKOPT_OK\fP from the callback on success. Return |
| 67 | \fICURL_SOCKOPT_ERROR\fP from the callback function to signal an unrecoverable |
| 68 | error to the library and it will close the socket and return |
| 69 | \fICURLE_COULDNT_CONNECT\fP. |
| 70 | Alternatively, the callback function can return |
| 71 | \fICURL_SOCKOPT_ALREADY_CONNECTED\fP, to tell libcurl that the socket is |
| 72 | already connected and then libcurl will not attempt to connect it. This allows |
| 73 | an application to pass in an already connected socket with |
| 74 | \fICURLOPT_OPENSOCKETFUNCTION(3)\fP and then have this function make libcurl |
| 75 | not attempt to connect (again). |
| 76 | .SH DEFAULT |
| 77 | By default, this callback is NULL and unused. |
| 78 | .SH PROTOCOLS |
| 79 | All |
| 80 | .SH EXAMPLE |
| 81 | TODO |
| 82 | .SH AVAILABILITY |
| 83 | Added in 7.16.0. The \fICURL_SOCKOPT_ALREADY_CONNECTED\fP return code was |
| 84 | added in 7.21.5. |
| 85 | .SH RETURN VALUE |
| 86 | Returns 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), " |