diff options
author | B. Stack <bgstack15@gmail.com> | 2021-04-05 15:59:11 +0000 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2021-04-05 15:59:11 +0000 |
commit | 8d28254d708c88ae4aaebbc82cbb6c91726aa390 (patch) | |
tree | dafb5e266c513a5ed9863401e62d246742861e0c /libcurl | |
parent | Merge branch '11.7' into 'master' (diff) | |
parent | add upstream 11.9 (diff) | |
download | FreeFileSync-8d28254d708c88ae4aaebbc82cbb6c91726aa390.tar.gz FreeFileSync-8d28254d708c88ae4aaebbc82cbb6c91726aa390.tar.bz2 FreeFileSync-8d28254d708c88ae4aaebbc82cbb6c91726aa390.zip |
Merge branch '11.9' into 'master'11.9
add upstream 11.9
See merge request opensource-tracking/FreeFileSync!32
Diffstat (limited to 'libcurl')
-rw-r--r-- | libcurl/rest.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/libcurl/rest.cpp b/libcurl/rest.cpp index 0964f63a..e80a4961 100644 --- a/libcurl/rest.cpp +++ b/libcurl/rest.cpp @@ -7,6 +7,7 @@ #include "rest.h" #include <zen/sys_info.h> #include <zen/http.h> + #include <fcntl.h> using namespace zen; @@ -61,14 +62,36 @@ HttpSession::Result HttpSession::perform(const std::string& serverRelPath, options.emplace_back(CURLOPT_LOW_SPEED_LIMIT, 1L); //[bytes], can't use "0" which means "inactive", so use some low number + std::exception_ptr userCallbackException; + + //libcurl does *not* set FD_CLOEXEC for us! https://github.com/curl/curl/issues/2252 + auto onSocketCreate = [&](curl_socket_t curlfd, curlsocktype purpose) + { + assert(::fcntl(curlfd, F_GETFD) == 0); + if (::fcntl(curlfd, F_SETFD, FD_CLOEXEC) == -1) //=> RACE-condition if other thread calls fork/execv before this thread sets FD_CLOEXEC! + { + userCallbackException = std::make_exception_ptr(SysError(formatSystemError("fcntl(FD_CLOEXEC)", errno))); + return CURL_SOCKOPT_ERROR; + } + return CURL_SOCKOPT_OK; + }; + + using SocketCbType = decltype(onSocketCreate); + using SocketCbWrapperType = int (*)(SocketCbType* clientp, curl_socket_t curlfd, curlsocktype purpose); //needed for cdecl function pointer cast + SocketCbWrapperType onSocketCreateWrapper = [](SocketCbType* clientp, curl_socket_t curlfd, curlsocktype purpose) + { + return (*clientp)(curlfd, purpose); //free this poor little C-API from its shackles and redirect to a proper lambda + }; + + options.emplace_back(CURLOPT_SOCKOPTFUNCTION, onSocketCreateWrapper); + options.emplace_back(CURLOPT_SOCKOPTDATA, &onSocketCreate); + //libcurl forwards this char-string to OpenSSL as is, which - thank god - accepts UTF8 options.emplace_back(CURLOPT_CAINFO, caCertFilePath_.c_str()); //hopefully latest version from https://curl.haxx.se/docs/caextract.html //CURLOPT_SSL_VERIFYPEER => already active by default //CURLOPT_SSL_VERIFYHOST => //--------------------------------------------------- - std::exception_ptr userCallbackException; - auto onBytesReceived = [&](const void* buffer, size_t len) { try |