mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-13 04:36:16 +00:00
HttpQueue finishing touches.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@266 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <iostream>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <curl/easy.h>
|
#include <curl/easy.h>
|
||||||
#include <torrent/exceptions.h>
|
#include <torrent/exceptions.h>
|
||||||
@@ -32,7 +32,7 @@ CurlGet::start() {
|
|||||||
if (is_busy())
|
if (is_busy())
|
||||||
throw torrent::internal_error("Tried to call CurlGet::start on a busy object");
|
throw torrent::internal_error("Tried to call CurlGet::start on a busy object");
|
||||||
|
|
||||||
if (m_out == NULL)
|
if (m_stream == NULL)
|
||||||
throw torrent::internal_error("Tried to call CurlGet::start without a valid output stream");
|
throw torrent::internal_error("Tried to call CurlGet::start without a valid output stream");
|
||||||
|
|
||||||
m_handle = curl_easy_init();
|
m_handle = curl_easy_init();
|
||||||
@@ -64,14 +64,14 @@ CurlGet::perform(CURLMsg* msg) {
|
|||||||
throw torrent::client_error("CurlGet::process got CURLMSG that isn't done");
|
throw torrent::client_error("CurlGet::process got CURLMSG that isn't done");
|
||||||
|
|
||||||
if (msg->data.result == CURLE_OK)
|
if (msg->data.result == CURLE_OK)
|
||||||
m_slotDone();
|
m_signalDone.emit();
|
||||||
else
|
else
|
||||||
m_slotFailed(curl_easy_strerror(msg->data.result));
|
m_signalFailed.emit(curl_easy_strerror(msg->data.result));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
curl_get_receive_write(void* data, size_t size, size_t nmemb, void* handle) {
|
curl_get_receive_write(void* data, size_t size, size_t nmemb, void* handle) {
|
||||||
return ((CurlGet*)handle)->m_out->write((char*)data, size * nmemb).fail() ? 0 : size * nmemb;
|
return ((CurlGet*)handle)->m_stream->write((char*)data, size * nmemb).fail() ? 0 : size * nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
#include <sigc++/bind.h>
|
#include <sigc++/bind.h>
|
||||||
#include <torrent/exceptions.h>
|
#include <torrent/exceptions.h>
|
||||||
#include <torrent/torrent.h>
|
#include <torrent/torrent.h>
|
||||||
@@ -10,7 +11,7 @@
|
|||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
DownloadList::iterator
|
DownloadList::iterator
|
||||||
DownloadList::insert(std::istream& str) {
|
DownloadList::insert(std::istream* str) {
|
||||||
torrent::Download d = torrent::download_create(str);
|
torrent::Download d = torrent::download_create(str);
|
||||||
|
|
||||||
iterator itr = Base::insert(end(), Download());
|
iterator itr = Base::insert(end(), Download());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
using Base::empty;
|
using Base::empty;
|
||||||
using Base::size;
|
using Base::size;
|
||||||
|
|
||||||
iterator insert(std::istream& str);
|
iterator insert(std::istream* str);
|
||||||
void erase(iterator itr);
|
void erase(iterator itr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+9
-14
@@ -3,6 +3,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <sigc++/bind.h>
|
#include <sigc++/bind.h>
|
||||||
|
#include <sigc++/hide.h>
|
||||||
#include <torrent/http.h>
|
#include <torrent/http.h>
|
||||||
|
|
||||||
#include "functional.h"
|
#include "functional.h"
|
||||||
@@ -11,29 +12,31 @@
|
|||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
void
|
HttpQueue::iterator
|
||||||
HttpQueue::insert(const std::string& url) {
|
HttpQueue::insert(const std::string& url) {
|
||||||
std::auto_ptr<torrent::Http> h(m_slotFactory());
|
std::auto_ptr<torrent::Http> h(m_slotFactory());
|
||||||
std::auto_ptr<std::stringstream> s(new std::stringstream);
|
std::auto_ptr<std::stringstream> s(new std::stringstream);
|
||||||
|
|
||||||
h->set_out(s.get());
|
|
||||||
h->set_url(url);
|
h->set_url(url);
|
||||||
|
h->set_stream(s.get());
|
||||||
h->set_user_agent("rtorrent/" VERSION);
|
h->set_user_agent("rtorrent/" VERSION);
|
||||||
|
|
||||||
iterator itr = Base::insert(end(), h.get());
|
iterator itr = Base::insert(end(), h.get());
|
||||||
|
|
||||||
h->slot_done(sigc::bind(sigc::mem_fun(this, &HttpQueue::receive_done), itr));
|
h->signal_done().connect(sigc::bind(sigc::mem_fun(this, &HttpQueue::erase), itr));
|
||||||
h->slot_failed(sigc::bind<0>(sigc::mem_fun(this, &HttpQueue::receive_failed), itr));
|
h->signal_failed().connect(sigc::bind<0>(sigc::hide(sigc::mem_fun(this, &HttpQueue::erase)), itr));
|
||||||
|
|
||||||
(*itr)->start();
|
(*itr)->start();
|
||||||
|
|
||||||
h.release();
|
h.release();
|
||||||
s.release();
|
s.release();
|
||||||
|
|
||||||
|
return itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
HttpQueue::erase(iterator itr) {
|
HttpQueue::erase(iterator itr) {
|
||||||
delete (*itr)->get_out();
|
delete (*itr)->get_stream();
|
||||||
delete *itr;
|
delete *itr;
|
||||||
|
|
||||||
Base::erase(itr);
|
Base::erase(itr);
|
||||||
@@ -41,18 +44,10 @@ HttpQueue::erase(iterator itr) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
HttpQueue::clear() {
|
HttpQueue::clear() {
|
||||||
std::for_each(begin(), end(), func::on(func::call_delete(), std::mem_fun(&CurlGet::get_out)));
|
std::for_each(begin(), end(), func::on(func::call_delete(), std::mem_fun(&CurlGet::get_stream)));
|
||||||
std::for_each(begin(), end(), func::call_delete());
|
std::for_each(begin(), end(), func::call_delete());
|
||||||
|
|
||||||
Base::clear();
|
Base::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
HttpQueue::receive_done(iterator itr) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
HttpQueue::receive_failed(iterator itr, std::string msg) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ public:
|
|||||||
using Base::empty;
|
using Base::empty;
|
||||||
using Base::size;
|
using Base::size;
|
||||||
|
|
||||||
void insert(const std::string& url);
|
// Note that any slots connected to the torrent::Http signals must be
|
||||||
|
// pushed in front of the erase slot added by HttpQueue::insert.
|
||||||
|
iterator insert(const std::string& url);
|
||||||
void erase(iterator itr);
|
void erase(iterator itr);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
@@ -37,9 +39,6 @@ public:
|
|||||||
void slot_factory(SlotFactory s) { m_slotFactory = s; }
|
void slot_factory(SlotFactory s) { m_slotFactory = s; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void receive_done(iterator itr);
|
|
||||||
void receive_failed(iterator itr, std::string msg);
|
|
||||||
|
|
||||||
SlotFactory m_slotFactory;
|
SlotFactory m_slotFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -66,9 +66,9 @@ Poll::work_input() {
|
|||||||
m_slotReadStdin(key);
|
m_slotReadStdin(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
Poll::SlotFactory
|
||||||
Poll::register_http() {
|
Poll::get_http_factory() {
|
||||||
torrent::Http::set_factory(sigc::bind(sigc::ptr_fun(&core::CurlGet::new_object), &m_curlStack));
|
return sigc::bind(sigc::ptr_fun(&core::CurlGet::new_object), &m_curlStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-15
@@ -6,33 +6,38 @@
|
|||||||
|
|
||||||
#include "curl_stack.h"
|
#include "curl_stack.h"
|
||||||
|
|
||||||
|
namespace torrent {
|
||||||
|
class Http;
|
||||||
|
}
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
class Poll {
|
class Poll {
|
||||||
public:
|
public:
|
||||||
typedef sigc::slot0<void> Slot;
|
typedef sigc::slot0<void> Slot;
|
||||||
typedef sigc::slot1<void, int> SlotInt;
|
typedef sigc::slot1<void, int> SlotInt;
|
||||||
|
typedef sigc::slot0<torrent::Http*> SlotFactory;
|
||||||
|
|
||||||
void poll();
|
void poll();
|
||||||
|
|
||||||
void register_http();
|
SlotFactory get_http_factory();
|
||||||
|
|
||||||
void slot_read_stdin(SlotInt s) { m_slotReadStdin = s; }
|
void slot_read_stdin(SlotInt s) { m_slotReadStdin = s; }
|
||||||
void slot_select_interrupted(Slot s) { m_slotSelectInterrupted = s; }
|
void slot_select_interrupted(Slot s) { m_slotSelectInterrupted = s; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void work();
|
void work();
|
||||||
void work_input();
|
void work_input();
|
||||||
|
|
||||||
SlotInt m_slotReadStdin;
|
SlotInt m_slotReadStdin;
|
||||||
Slot m_slotSelectInterrupted;
|
Slot m_slotSelectInterrupted;
|
||||||
|
|
||||||
int m_maxFd;
|
int m_maxFd;
|
||||||
fd_set m_readSet;
|
fd_set m_readSet;
|
||||||
fd_set m_writeSet;
|
fd_set m_writeSet;
|
||||||
fd_set m_exceptSet;
|
fd_set m_exceptSet;
|
||||||
|
|
||||||
CurlStack m_curlStack;
|
CurlStack m_curlStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-6
@@ -4,8 +4,10 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <torrent/http.h>
|
||||||
#include <torrent/torrent.h>
|
#include <torrent/torrent.h>
|
||||||
#include <sigc++/bind.h>
|
#include <sigc++/bind.h>
|
||||||
|
#include <sigc++/retype_return.h>
|
||||||
|
|
||||||
#ifdef USE_EXECINFO
|
#ifdef USE_EXECINFO
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
@@ -15,6 +17,7 @@
|
|||||||
|
|
||||||
#include "core/poll.h"
|
#include "core/poll.h"
|
||||||
#include "core/curl_stack.h"
|
#include "core/curl_stack.h"
|
||||||
|
#include "core/http_queue.h"
|
||||||
#include "core/download_list.h"
|
#include "core/download_list.h"
|
||||||
|
|
||||||
#include "ui/control.h"
|
#include "ui/control.h"
|
||||||
@@ -32,6 +35,7 @@ bool is_shutting_down = false;
|
|||||||
|
|
||||||
core::Poll poll;
|
core::Poll poll;
|
||||||
core::DownloadList downloads;
|
core::DownloadList downloads;
|
||||||
|
core::HttpQueue httpQueue;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_resized() {
|
is_resized() {
|
||||||
@@ -113,20 +117,28 @@ main(int argc, char** argv) {
|
|||||||
inputMain[KEY_RESIZE] = sigc::mem_fun(uiControl.get_display(), &display::Manager::adjust_layout);
|
inputMain[KEY_RESIZE] = sigc::mem_fun(uiControl.get_display(), &display::Manager::adjust_layout);
|
||||||
|
|
||||||
poll.slot_read_stdin(sigc::mem_fun(uiControl.get_input(), &input::Manager::pressed));
|
poll.slot_read_stdin(sigc::mem_fun(uiControl.get_input(), &input::Manager::pressed));
|
||||||
poll.register_http();
|
|
||||||
|
|
||||||
poll.slot_select_interrupted(sigc::ptr_fun(display::Canvas::do_update));
|
poll.slot_select_interrupted(sigc::ptr_fun(display::Canvas::do_update));
|
||||||
|
|
||||||
|
torrent::Http::set_factory(poll.get_http_factory());
|
||||||
|
httpQueue.slot_factory(poll.get_http_factory());
|
||||||
|
|
||||||
torrent::initialize();
|
torrent::initialize();
|
||||||
torrent::listen_open(6880, 6999);
|
torrent::listen_open(6880, 6999);
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
std::fstream f(argv[i], std::ios::in);
|
if (std::strncmp(argv[i], "http://", 7)) {
|
||||||
|
std::fstream f(argv[i], std::ios::in);
|
||||||
|
|
||||||
|
core::DownloadList::iterator itr = downloads.insert(&f);
|
||||||
|
|
||||||
|
itr->open();
|
||||||
|
itr->hash_check();
|
||||||
|
|
||||||
core::DownloadList::iterator itr = downloads.insert(f);
|
} else {
|
||||||
|
core::HttpQueue::iterator itr = httpQueue.insert(argv[i]);
|
||||||
|
|
||||||
itr->open();
|
(*itr)->signal_done().slots().push_front(sigc::hide_return(sigc::bind(sigc::mem_fun(downloads, &core::DownloadList::insert), (*itr)->get_stream())));
|
||||||
itr->hash_check();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uiControl.get_display().adjust_layout();
|
uiControl.get_display().adjust_layout();
|
||||||
|
|||||||
Reference in New Issue
Block a user