diff --git a/src/core/curl_socket.cc b/src/core/curl_socket.cc index 17a22393..c91668d9 100644 --- a/src/core/curl_socket.cc +++ b/src/core/curl_socket.cc @@ -99,29 +99,35 @@ CurlSocket::close() { if (m_fileDesc == -1) throw torrent::internal_error("CurlSocket::close() m_fileDesc == -1."); - // Extra cleanup to avoid leaving dangling polling events in case - // libcurl decides to leave the fd open for reuse. - control->poll()->remove_read(this); - control->poll()->remove_write(this); - control->poll()->remove_error(this); - control->poll()->closed(this); m_fileDesc = -1; } void CurlSocket::event_read() { +#if (LIBCURL_VERSION_NUM >= 0x071003) return m_stack->receive_action(this, CURL_CSELECT_IN); +#else + return m_stack->receive_action(this, 0); +#endif } void CurlSocket::event_write() { +#if (LIBCURL_VERSION_NUM >= 0x071003) return m_stack->receive_action(this, CURL_CSELECT_OUT); +#else + return m_stack->receive_action(this, 0); +#endif } void CurlSocket::event_error() { +#if (LIBCURL_VERSION_NUM >= 0x071003) return m_stack->receive_action(this, CURL_CSELECT_ERR); +#else + return m_stack->receive_action(this, 0); +#endif } } diff --git a/src/core/curl_stack.cc b/src/core/curl_stack.cc index 51ea8076..a4bc212a 100644 --- a/src/core/curl_stack.cc +++ b/src/core/curl_stack.cc @@ -132,6 +132,14 @@ CurlStack::receive_action(CurlSocket* socket, int events) { void CurlStack::receive_timeout() { receive_action(NULL, 0); + + // Sometimes libcurl forgets to reset the timeout. Try to poll the value in that case, or use 10 seconds. + if (!empty() && !m_taskTimeout.is_queued()) { + long timeout; + curl_multi_timeout((CURLM*)m_handle, &timeout); + priority_queue_insert(&taskScheduler, &m_taskTimeout, + cachedTime + rak::timer::from_milliseconds(std::max(timeout, 10000))); + } } void @@ -161,6 +169,10 @@ CurlStack::add_get(CurlGet* get) { if (curl_multi_add_handle((CURLM*)m_handle, get->handle()) > 0) throw torrent::internal_error("Error calling curl_multi_add_handle."); + +#if (LIBCURL_VERSION_NUM < 0x071000) + receive_timeout(); +#endif } void