Annotation of embedaddon/curl/docs/libcurl/opts/CURLOPT_OPENSOCKETDATA.3, revision 1.1
1.1 ! misho 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_OPENSOCKETDATA 3 "May 15, 2017" "libcurl 7.70.0" "curl_easy_setopt options"
! 24:
! 25: .SH NAME
! 26: CURLOPT_OPENSOCKETDATA \- custom pointer passed to open socket callback
! 27: .SH SYNOPSIS
! 28: #include <curl/curl.h>
! 29:
! 30: CURLcode curl_easy_setopt(CURL *handle, CURLOPT_OPENSOCKETDATA, void *pointer);
! 31: .SH DESCRIPTION
! 32: Pass a \fIpointer\fP that will be untouched by libcurl and passed as the first
! 33: argument in the opensocket callback set with \fICURLOPT_OPENSOCKETFUNCTION(3)\fP.
! 34: .SH DEFAULT
! 35: The default value of this parameter is NULL.
! 36: .SH PROTOCOLS
! 37: All
! 38: .SH EXAMPLE
! 39: .nf
! 40: /* make libcurl use the already established socket 'sockfd' */
! 41:
! 42: static curl_socket_t opensocket(void *clientp,
! 43: curlsocktype purpose,
! 44: struct curl_sockaddr *address)
! 45: {
! 46: curl_socket_t sockfd;
! 47: sockfd = *(curl_socket_t *)clientp;
! 48: /* the actual externally set socket is passed in via the OPENSOCKETDATA
! 49: option */
! 50: return sockfd;
! 51: }
! 52:
! 53: static int sockopt_callback(void *clientp, curl_socket_t curlfd,
! 54: curlsocktype purpose)
! 55: {
! 56: /* This return code was added in libcurl 7.21.5 */
! 57: return CURL_SOCKOPT_ALREADY_CONNECTED;
! 58: }
! 59:
! 60: curl = curl_easy_init();
! 61: if(curl) {
! 62: /* libcurl will internally think that you connect to the host
! 63: * and port that you specify in the URL option. */
! 64: curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
! 65: /* call this function to get a socket */
! 66: curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
! 67: curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
! 68:
! 69: /* call this function to set options for the socket */
! 70: curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
! 71:
! 72: res = curl_easy_perform(curl);
! 73:
! 74: curl_easy_cleanup(curl);
! 75: }
! 76: .fi
! 77: .SH AVAILABILITY
! 78: Added in 7.17.1
! 79: .SH RETURN VALUE
! 80: Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
! 81: .SH "SEE ALSO"
! 82: .BR CURLOPT_OPENSOCKETFUNCTION "(3), " CURLOPT_SOCKOPTFUNCTION "(3), "
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>