mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-15 13:46:17 +00:00
* Various fixes to the new polling code to handle bad libcurl/cares
behavior. Patch by Josef Drexler. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1067 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+12
-6
@@ -99,29 +99,35 @@ CurlSocket::close() {
|
|||||||
if (m_fileDesc == -1)
|
if (m_fileDesc == -1)
|
||||||
throw torrent::internal_error("CurlSocket::close() 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);
|
control->poll()->closed(this);
|
||||||
m_fileDesc = -1;
|
m_fileDesc = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CurlSocket::event_read() {
|
CurlSocket::event_read() {
|
||||||
|
#if (LIBCURL_VERSION_NUM >= 0x071003)
|
||||||
return m_stack->receive_action(this, CURL_CSELECT_IN);
|
return m_stack->receive_action(this, CURL_CSELECT_IN);
|
||||||
|
#else
|
||||||
|
return m_stack->receive_action(this, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CurlSocket::event_write() {
|
CurlSocket::event_write() {
|
||||||
|
#if (LIBCURL_VERSION_NUM >= 0x071003)
|
||||||
return m_stack->receive_action(this, CURL_CSELECT_OUT);
|
return m_stack->receive_action(this, CURL_CSELECT_OUT);
|
||||||
|
#else
|
||||||
|
return m_stack->receive_action(this, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CurlSocket::event_error() {
|
CurlSocket::event_error() {
|
||||||
|
#if (LIBCURL_VERSION_NUM >= 0x071003)
|
||||||
return m_stack->receive_action(this, CURL_CSELECT_ERR);
|
return m_stack->receive_action(this, CURL_CSELECT_ERR);
|
||||||
|
#else
|
||||||
|
return m_stack->receive_action(this, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,6 +132,14 @@ CurlStack::receive_action(CurlSocket* socket, int events) {
|
|||||||
void
|
void
|
||||||
CurlStack::receive_timeout() {
|
CurlStack::receive_timeout() {
|
||||||
receive_action(NULL, 0);
|
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<unsigned long>(timeout, 10000)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -161,6 +169,10 @@ CurlStack::add_get(CurlGet* get) {
|
|||||||
|
|
||||||
if (curl_multi_add_handle((CURLM*)m_handle, get->handle()) > 0)
|
if (curl_multi_add_handle((CURLM*)m_handle, get->handle()) > 0)
|
||||||
throw torrent::internal_error("Error calling curl_multi_add_handle.");
|
throw torrent::internal_error("Error calling curl_multi_add_handle.");
|
||||||
|
|
||||||
|
#if (LIBCURL_VERSION_NUM < 0x071000)
|
||||||
|
receive_timeout();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user