Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/curl/docs/libcurl/opts/CURLOPT_OPENSOCKETFUNCTION.3 @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 .\" ************************************************************************** | |
| 2 .\" * _ _ ____ _ | |
| 3 .\" * Project ___| | | | _ \| | | |
| 4 .\" * / __| | | | |_) | | | |
| 5 .\" * | (__| |_| | _ <| |___ | |
| 6 .\" * \___|\___/|_| \_\_____| | |
| 7 .\" * | |
| 8 .\" * Copyright (C) 1998 - 2017, 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 https://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_OPENSOCKETFUNCTION 3 "16 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options" | |
| 24 .SH NAME | |
| 25 CURLOPT_OPENSOCKETFUNCTION \- set callback for opening sockets | |
| 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 struct curl_sockaddr { | |
| 37 int family; | |
| 38 int socktype; | |
| 39 int protocol; | |
| 40 unsigned int addrlen; | |
| 41 struct sockaddr addr; | |
| 42 }; | |
| 43 | |
| 44 curl_socket_t opensocket_callback(void *clientp, | |
| 45 curlsocktype purpose, | |
| 46 struct curl_sockaddr *address); | |
| 47 | |
| 48 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_OPENSOCKETFUNCTION, opensocket_callback); | |
| 49 .SH DESCRIPTION | |
| 50 Pass a pointer to your callback function, which should match the prototype | |
| 51 shown above. | |
| 52 | |
| 53 This callback function gets called by libcurl instead of the \fIsocket(2)\fP | |
| 54 call. The callback's \fIpurpose\fP argument identifies the exact purpose for | |
| 55 this particular socket: \fICURLSOCKTYPE_IPCXN\fP is for IP based connections | |
| 56 and \fICURLSOCKTYPE_ACCEPT\fP is for sockets created after accept() - such as | |
| 57 when doing active FTP. Future versions of libcurl may support more | |
| 58 purposes. | |
| 59 | |
| 60 The \fIclientp\fP pointer contains whatever user-defined value set using the | |
| 61 \fICURLOPT_OPENSOCKETDATA(3)\fP function. | |
| 62 | |
| 63 The callback gets the resolved peer address as the \fIaddress\fP argument and | |
| 64 is allowed to modify the address or refuse to connect completely. The callback | |
| 65 function should return the newly created socket or \fICURL_SOCKET_BAD\fP in | |
| 66 case no connection could be established or another error was detected. Any | |
| 67 additional \fIsetsockopt(2)\fP calls can of course be done on the socket at | |
| 68 the user's discretion. A \fICURL_SOCKET_BAD\fP return value from the callback | |
| 69 function will signal an unrecoverable error to libcurl and it will return | |
| 70 \fICURLE_COULDNT_CONNECT\fP from the function that triggered this callback. | |
| 71 This return code can be used for IP address blacklisting. | |
| 72 | |
| 73 If you want to pass in a socket with an already established connection, pass | |
| 74 the socket back with this callback and then use | |
| 75 \fICURLOPT_SOCKOPTFUNCTION(3)\fP to signal that it already is connected. | |
| 76 .SH DEFAULT | |
| 77 The default behavior is the equivalent of this: | |
| 78 .nf | |
| 79 return socket(addr->family, addr->socktype, addr->protocol); | |
| 80 .fi | |
| 81 .SH PROTOCOLS | |
| 82 All | |
| 83 .SH EXAMPLE | |
| 84 .nf | |
| 85 /* make libcurl use the already established socket 'sockfd' */ | |
| 86 | |
| 87 static curl_socket_t opensocket(void *clientp, | |
| 88 curlsocktype purpose, | |
| 89 struct curl_sockaddr *address) | |
| 90 { | |
| 91 curl_socket_t sockfd; | |
| 92 sockfd = *(curl_socket_t *)clientp; | |
| 93 /* the actual externally set socket is passed in via the OPENSOCKETDATA | |
| 94 option */ | |
| 95 return sockfd; | |
| 96 } | |
| 97 | |
| 98 static int sockopt_callback(void *clientp, curl_socket_t curlfd, | |
| 99 curlsocktype purpose) | |
| 100 { | |
| 101 /* This return code was added in libcurl 7.21.5 */ | |
| 102 return CURL_SOCKOPT_ALREADY_CONNECTED; | |
| 103 } | |
| 104 | |
| 105 curl = curl_easy_init(); | |
| 106 if(curl) { | |
| 107 /* libcurl will internally think that you connect to the host | |
| 108 * and port that you specify in the URL option. */ | |
| 109 curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999"); | |
| 110 /* call this function to get a socket */ | |
| 111 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket); | |
| 112 curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd); | |
| 113 | |
| 114 /* call this function to set options for the socket */ | |
| 115 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); | |
| 116 | |
| 117 res = curl_easy_perform(curl); | |
| 118 | |
| 119 curl_easy_cleanup(curl); | |
| 120 } | |
| 121 .fi | |
| 122 .SH AVAILABILITY | |
| 123 Added in 7.17.1. | |
| 124 .SH RETURN VALUE | |
| 125 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. | |
| 126 .SH "SEE ALSO" | |
| 127 .BR CURLOPT_OPENSOCKETDATA "(3), " CURLOPT_SOCKOPTFUNCTION "(3), " | |
| 128 .BR CURLOPT_CLOSESOCKETFUNCTION "(3), " |
