mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-14 22:22:31 +00:00
* Cleanup of the API, got rid of "get_" prefix for alot of the calls.
* Tweaked the http get timeout, now it has a 60 second connect timeout and a 360 second download timeout. * Moved libtorrent/src/parse/download_constructor to src/download. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@595 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -48,7 +48,7 @@ namespace core {
|
||||
|
||||
size_t
|
||||
curl_get_receive_write(void* data, size_t size, size_t nmemb, void* handle) {
|
||||
if (!((CurlGet*)handle)->get_stream()->write((char*)data, size * nmemb).fail())
|
||||
if (!((CurlGet*)handle)->stream()->write((char*)data, size * nmemb).fail())
|
||||
return size * nmemb;
|
||||
else
|
||||
return 0;
|
||||
@@ -84,7 +84,8 @@ CurlGet::start() {
|
||||
curl_easy_setopt(m_handle, CURLOPT_URL, m_url.c_str());
|
||||
curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, &curl_get_receive_write);
|
||||
curl_easy_setopt(m_handle, CURLOPT_WRITEDATA, this);
|
||||
curl_easy_setopt(m_handle, CURLOPT_TIMEOUT, 60);
|
||||
curl_easy_setopt(m_handle, CURLOPT_CONNECTTIMEOUT, 60);
|
||||
curl_easy_setopt(m_handle, CURLOPT_TIMEOUT, 360);
|
||||
|
||||
curl_easy_setopt(m_handle, CURLOPT_FORBID_REUSE, 1);
|
||||
curl_easy_setopt(m_handle, CURLOPT_NOSIGNAL, 1);
|
||||
@@ -108,7 +109,7 @@ CurlGet::close() {
|
||||
|
||||
|
||||
double
|
||||
CurlGet::get_size_done() {
|
||||
CurlGet::size_done() {
|
||||
double d = 0.0;
|
||||
curl_easy_getinfo(m_handle, CURLINFO_SIZE_DOWNLOAD, &d);
|
||||
|
||||
@@ -116,7 +117,7 @@ CurlGet::get_size_done() {
|
||||
}
|
||||
|
||||
double
|
||||
CurlGet::get_size_total() {
|
||||
CurlGet::size_total() {
|
||||
double d = 0.0;
|
||||
curl_easy_getinfo(m_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
|
||||
|
||||
|
||||
+2
-2
@@ -63,8 +63,8 @@ class CurlGet : public torrent::Http {
|
||||
|
||||
bool is_busy() { return m_handle; }
|
||||
|
||||
double get_size_done();
|
||||
double get_size_total();
|
||||
double size_done();
|
||||
double size_total();
|
||||
|
||||
void set_user_agent(const char* s);
|
||||
|
||||
|
||||
@@ -76,14 +76,17 @@ void
|
||||
Download::set_root_directory(const std::string& d) {
|
||||
m_download.set_root_dir(d +
|
||||
(!d.empty() && *d.rbegin() != '/' ? "/" : "") +
|
||||
(m_download.get_entry_size() > 1 ? m_download.get_name() : ""));
|
||||
(m_download.size_file_entries() > 1 ? m_download.name() : ""));
|
||||
}
|
||||
|
||||
void
|
||||
Download::enable_udp_trackers(bool state) {
|
||||
for (int i = 0, last = m_download.get_tracker_size(); i < last; ++i)
|
||||
if (m_download.get_tracker(i).get_type() == torrent::Tracker::TRACKER_UDP)
|
||||
m_download.get_tracker(i).enable(state);
|
||||
for (int i = 0, last = m_download.size_trackers(); i < last; ++i)
|
||||
if (m_download.tracker(i).tracker_type() == torrent::Tracker::TRACKER_UDP)
|
||||
if (state)
|
||||
m_download.tracker(i).enable();
|
||||
else
|
||||
m_download.tracker(i).disable();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+5
-5
@@ -60,14 +60,14 @@ public:
|
||||
|
||||
torrent::Download& get_download() { return m_download; }
|
||||
const torrent::Download& get_download() const { return m_download; }
|
||||
std::string get_hash() { return m_download.get_hash(); }
|
||||
torrent::Bencode& get_bencode() { return m_download.get_bencode(); }
|
||||
std::string get_hash() { return m_download.info_hash(); }
|
||||
torrent::Bencode& get_bencode() { return m_download.bencode(); }
|
||||
|
||||
const std::string& get_message() { return m_message; }
|
||||
|
||||
void set_root_directory(const std::string& d);
|
||||
|
||||
ConnType get_connection_current() const { return m_download.get_connection_type(); }
|
||||
ConnType get_connection_current() const { return m_download.connection_type(); }
|
||||
ConnType get_connection_leech() const { return m_connectionLeech; }
|
||||
ConnType get_connection_seed() const { return m_connectionSeed; }
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
template <typename Ret, typename Arg1, Ret (torrent::Download::*func)(Arg1)>
|
||||
void call(Arg1 a1) { (m_download.*func)(a1); }
|
||||
|
||||
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
|
||||
bool operator == (const std::string& str) { return str == m_download.info_hash(); }
|
||||
|
||||
void receive_finished();
|
||||
|
||||
@@ -109,7 +109,7 @@ private:
|
||||
|
||||
inline bool
|
||||
Download::is_done() {
|
||||
return m_download.get_chunks_done() == m_download.get_chunks_total();
|
||||
return m_download.chunks_done() == m_download.chunks_total();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ PollManager::PollManager(torrent::Poll* poll) :
|
||||
throw std::logic_error("PollManager::PollManager(...) received poll == NULL");
|
||||
|
||||
#if defined USE_VARIABLE_FDSET
|
||||
m_setSize = m_poll->get_open_max() / 8;
|
||||
m_setSize = m_poll->open_max() / 8;
|
||||
m_readSet = (fd_set*)new char[m_setSize];
|
||||
m_writeSet = (fd_set*)new char[m_setSize];
|
||||
m_errorSet = (fd_set*)new char[m_setSize];
|
||||
@@ -59,7 +59,7 @@ PollManager::PollManager(torrent::Poll* poll) :
|
||||
std::memset(m_writeSet, 0, m_setSize);
|
||||
std::memset(m_errorSet, 0, m_setSize);
|
||||
#else
|
||||
if (m_poll->get_open_max() > FD_SETSIZE)
|
||||
if (m_poll->open_max() > FD_SETSIZE)
|
||||
throw std::logic_error("PollManager::PollManager(...) received a max open sockets >= FD_SETSIZE, but USE_VARIABLE_FDSET was not defined");
|
||||
|
||||
m_setSize = FD_SETSIZE / 8;
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
PollManager(torrent::Poll* poll);
|
||||
virtual ~PollManager();
|
||||
|
||||
unsigned int get_open_max() const { return m_poll->get_open_max(); }
|
||||
unsigned int get_open_max() const { return m_poll->open_max(); }
|
||||
|
||||
CurlStack* get_http_stack() { return &m_httpStack; }
|
||||
torrent::Poll* get_torrent_poll() { return m_poll; }
|
||||
|
||||
@@ -65,7 +65,7 @@ PollManagerEPoll::poll(utils::Timer timeout) {
|
||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
||||
// resolution.
|
||||
torrent::perform();
|
||||
timeout = std::min(timeout, utils::Timer(torrent::get_next_timeout()));
|
||||
timeout = std::min(timeout, utils::Timer(torrent::next_timeout()));
|
||||
|
||||
if (m_httpStack.is_busy()) {
|
||||
// When we're using libcurl we need to use select, but as this is
|
||||
@@ -79,9 +79,9 @@ PollManagerEPoll::poll(utils::Timer timeout) {
|
||||
FD_ZERO(m_writeSet);
|
||||
FD_ZERO(m_errorSet);
|
||||
#endif
|
||||
FD_SET(static_cast<torrent::PollEPoll*>(m_poll)->get_fd(), m_readSet);
|
||||
FD_SET(static_cast<torrent::PollEPoll*>(m_poll)->file_descriptor(), m_readSet);
|
||||
|
||||
unsigned int maxFd = std::max((unsigned int)static_cast<torrent::PollEPoll*>(m_poll)->get_fd(),
|
||||
unsigned int maxFd = std::max((unsigned int)static_cast<torrent::PollEPoll*>(m_poll)->file_descriptor(),
|
||||
m_httpStack.fdset(m_readSet, m_writeSet, m_errorSet));
|
||||
|
||||
timeval t = timeout.tval();
|
||||
@@ -91,7 +91,7 @@ PollManagerEPoll::poll(utils::Timer timeout) {
|
||||
|
||||
m_httpStack.perform();
|
||||
|
||||
if (!FD_ISSET(static_cast<torrent::PollEPoll*>(m_poll)->get_fd(), m_readSet)) {
|
||||
if (!FD_ISSET(static_cast<torrent::PollEPoll*>(m_poll)->file_descriptor(), m_readSet)) {
|
||||
// Need to call perform here so that scheduled task get done
|
||||
// even if there's no socket events outside of the http stuff.
|
||||
torrent::perform();
|
||||
|
||||
@@ -63,7 +63,7 @@ PollManagerSelect::~PollManagerSelect() {
|
||||
void
|
||||
PollManagerSelect::poll(utils::Timer timeout) {
|
||||
torrent::perform();
|
||||
timeout = std::min(timeout, utils::Timer(torrent::get_next_timeout()));
|
||||
timeout = std::min(timeout, utils::Timer(torrent::next_timeout()));
|
||||
|
||||
#if defined USE_VARIABLE_FDSET
|
||||
std::memset(m_readSet, 0, m_setSize);
|
||||
|
||||
Reference in New Issue
Block a user