diff --git a/src/easy/handler.rs b/src/easy/handler.rs index 2b20a487f..044ce67f7 100644 --- a/src/easy/handler.rs +++ b/src/easy/handler.rs @@ -9,8 +9,10 @@ use std::slice; use std::str; use std::time::Duration; -use libc::{c_char, c_double, c_int, c_long, c_ulong, c_void, size_t}; +use libc::{c_char, c_double, c_int, c_long, c_uint, c_ulong, c_void, size_t}; use socket2::Socket; +#[cfg(windows)] +use windows_sys::Win32::Networking::WinSock::SOCKADDR; use crate::easy::form; use crate::easy::list; @@ -271,12 +273,16 @@ pub trait Handler { /// triggered this callback. /// /// By default this function opens a standard socket and - /// corresponds to `CURLOPT_OPENSOCKETFUNCTION `. + /// corresponds to `CURLOPT_OPENSOCKETFUNCTION`. fn open_socket( &mut self, + _purpose: curl_sys::curlsocktype, family: c_int, socktype: c_int, protocol: c_int, + _address_length: c_uint, + #[cfg(unix)] _address_data: libc::sockaddr, + #[cfg(windows)] _address_data: SOCKADDR, ) -> Option { // Note that we override this to calling a function in `socket2` to // ensure that we open all sockets with CLOEXEC. Otherwise if we rely on @@ -3651,16 +3657,22 @@ extern "C" fn ssl_ctx_cb( res.unwrap_or(curl_sys::CURLE_SSL_CONNECT_ERROR) } -// TODO: expose `purpose` and `sockaddr` inside of `address` extern "C" fn opensocket_cb( data: *mut c_void, - _purpose: curl_sys::curlsocktype, + purpose: curl_sys::curlsocktype, address: *mut curl_sys::curl_sockaddr, ) -> curl_sys::curl_socket_t { let res = panic::catch(|| unsafe { (*(data as *mut Inner)) .handler - .open_socket((*address).family, (*address).socktype, (*address).protocol) + .open_socket( + purpose, + (*address).family, + (*address).socktype, + (*address).protocol, + (*address).addrlen, + (*address).addr, + ) .unwrap_or(curl_sys::CURL_SOCKET_BAD) }); res.unwrap_or(curl_sys::CURL_SOCKET_BAD)