diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c1f446cb1..b62e16558 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,7 +47,7 @@ option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) set(USE_CURL FALSE) if(ENABLE_CURL) - find_package(CURL) + find_package(CURL 7.28.0) if (CURL_FOUND) message(STATUS "cURL support enabled.") set(USE_CURL TRUE) diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index a966d4855..a2ba03ba5 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include "network/socket.h" // for select() #include "threading/event.h" #include "config.h" #include "exceptions.h" @@ -436,6 +435,12 @@ HTTPFetchOngoing::~HTTPFetchOngoing() } +#if LIBCURL_VERSION_NUM >= 0x074200 +#define HAVE_CURL_MULTI_POLL +#else +#undef HAVE_CURL_MULTI_POLL +#endif + class CurlFetchThread : public Thread { protected: @@ -595,62 +600,40 @@ protected: // Wait until some IO happens, or timeout elapses void waitForIO(long timeout) { - fd_set read_fd_set; - fd_set write_fd_set; - fd_set exc_fd_set; - int max_fd; - long select_timeout = -1; - struct timeval select_tv; CURLMcode mres; - FD_ZERO(&read_fd_set); - FD_ZERO(&write_fd_set); - FD_ZERO(&exc_fd_set); +#ifdef HAVE_CURL_MULTI_POLL + mres = curl_multi_poll(m_multi, nullptr, 0, timeout, nullptr); - mres = curl_multi_fdset(m_multi, &read_fd_set, - &write_fd_set, &exc_fd_set, &max_fd); if (mres != CURLM_OK) { - errorstream<<"curl_multi_fdset" - <<" returned error code "< 0) + sleep_ms(timeout); + } else { + mres = curl_multi_wait(m_multi, nullptr, 0, timeout, nullptr); - // Limit timeout so new requests get through - if (select_timeout < 0 || select_timeout > timeout) - select_timeout = timeout; - - if (select_timeout > 0) { - // in Winsock it is forbidden to pass three empty - // fd_sets to select(), so in that case use sleep_ms - if (max_fd != -1) { - select_tv.tv_sec = select_timeout / 1000; - select_tv.tv_usec = (select_timeout % 1000) * 1000; - int retval = select(max_fd + 1, &read_fd_set, - &write_fd_set, &exc_fd_set, - &select_tv); - if (retval == -1) { - #ifdef _WIN32 - errorstream<<"select returned error code " - <