HttpQueue finishing touches.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@266 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-10 20:00:00 +00:00
parent deb1244d8c
commit 8ec38be77e
8 changed files with 61 additions and 49 deletions
+5 -5
View File
@@ -1,6 +1,6 @@
#include "config.h"
#include <ostream>
#include <iostream>
#include <curl/curl.h>
#include <curl/easy.h>
#include <torrent/exceptions.h>
@@ -32,7 +32,7 @@ CurlGet::start() {
if (is_busy())
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");
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");
if (msg->data.result == CURLE_OK)
m_slotDone();
m_signalDone.emit();
else
m_slotFailed(curl_easy_strerror(msg->data.result));
m_signalFailed.emit(curl_easy_strerror(msg->data.result));
}
size_t
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;
}
}
+2 -1
View File
@@ -1,6 +1,7 @@
#include "config.h"
#include <algorithm>
#include <stdexcept>
#include <sigc++/bind.h>
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
@@ -10,7 +11,7 @@
namespace core {
DownloadList::iterator
DownloadList::insert(std::istream& str) {
DownloadList::insert(std::istream* str) {
torrent::Download d = torrent::download_create(str);
iterator itr = Base::insert(end(), Download());
+1 -1
View File
@@ -24,7 +24,7 @@ public:
using Base::empty;
using Base::size;
iterator insert(std::istream& str);
iterator insert(std::istream* str);
void erase(iterator itr);
private:
+9 -14
View File
@@ -3,6 +3,7 @@
#include <memory>
#include <sstream>
#include <sigc++/bind.h>
#include <sigc++/hide.h>
#include <torrent/http.h>
#include "functional.h"
@@ -11,29 +12,31 @@
namespace core {
void
HttpQueue::iterator
HttpQueue::insert(const std::string& url) {
std::auto_ptr<torrent::Http> h(m_slotFactory());
std::auto_ptr<std::stringstream> s(new std::stringstream);
h->set_out(s.get());
h->set_url(url);
h->set_stream(s.get());
h->set_user_agent("rtorrent/" VERSION);
iterator itr = Base::insert(end(), h.get());
h->slot_done(sigc::bind(sigc::mem_fun(this, &HttpQueue::receive_done), itr));
h->slot_failed(sigc::bind<0>(sigc::mem_fun(this, &HttpQueue::receive_failed), itr));
h->signal_done().connect(sigc::bind(sigc::mem_fun(this, &HttpQueue::erase), itr));
h->signal_failed().connect(sigc::bind<0>(sigc::hide(sigc::mem_fun(this, &HttpQueue::erase)), itr));
(*itr)->start();
h.release();
s.release();
return itr;
}
void
HttpQueue::erase(iterator itr) {
delete (*itr)->get_out();
delete (*itr)->get_stream();
delete *itr;
Base::erase(itr);
@@ -41,18 +44,10 @@ HttpQueue::erase(iterator itr) {
void
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());
Base::clear();
}
void
HttpQueue::receive_done(iterator itr) {
}
void
HttpQueue::receive_failed(iterator itr, std::string msg) {
}
}
+3 -4
View File
@@ -29,7 +29,9 @@ public:
using Base::empty;
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 clear();
@@ -37,9 +39,6 @@ public:
void slot_factory(SlotFactory s) { m_slotFactory = s; }
private:
void receive_done(iterator itr);
void receive_failed(iterator itr, std::string msg);
SlotFactory m_slotFactory;
};
+3 -3
View File
@@ -66,9 +66,9 @@ Poll::work_input() {
m_slotReadStdin(key);
}
void
Poll::register_http() {
torrent::Http::set_factory(sigc::bind(sigc::ptr_fun(&core::CurlGet::new_object), &m_curlStack));
Poll::SlotFactory
Poll::get_http_factory() {
return sigc::bind(sigc::ptr_fun(&core::CurlGet::new_object), &m_curlStack);
}
}
+20 -15
View File
@@ -6,33 +6,38 @@
#include "curl_stack.h"
namespace torrent {
class Http;
}
namespace core {
class Poll {
public:
typedef sigc::slot0<void> Slot;
typedef sigc::slot1<void, int> SlotInt;
typedef sigc::slot0<void> Slot;
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_select_interrupted(Slot s) { m_slotSelectInterrupted = s; }
void slot_read_stdin(SlotInt s) { m_slotReadStdin = s; }
void slot_select_interrupted(Slot s) { m_slotSelectInterrupted = s; }
private:
void work();
void work_input();
void work();
void work_input();
SlotInt m_slotReadStdin;
Slot m_slotSelectInterrupted;
SlotInt m_slotReadStdin;
Slot m_slotSelectInterrupted;
int m_maxFd;
fd_set m_readSet;
fd_set m_writeSet;
fd_set m_exceptSet;
int m_maxFd;
fd_set m_readSet;
fd_set m_writeSet;
fd_set m_exceptSet;
CurlStack m_curlStack;
CurlStack m_curlStack;
};
}
+18 -6
View File
@@ -4,8 +4,10 @@
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <torrent/http.h>
#include <torrent/torrent.h>
#include <sigc++/bind.h>
#include <sigc++/retype_return.h>
#ifdef USE_EXECINFO
#include <execinfo.h>
@@ -15,6 +17,7 @@
#include "core/poll.h"
#include "core/curl_stack.h"
#include "core/http_queue.h"
#include "core/download_list.h"
#include "ui/control.h"
@@ -32,6 +35,7 @@ bool is_shutting_down = false;
core::Poll poll;
core::DownloadList downloads;
core::HttpQueue httpQueue;
bool
is_resized() {
@@ -113,20 +117,28 @@ main(int argc, char** argv) {
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.register_http();
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::listen_open(6880, 6999);
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->hash_check();
(*itr)->signal_done().slots().push_front(sigc::hide_return(sigc::bind(sigc::mem_fun(downloads, &core::DownloadList::insert), (*itr)->get_stream())));
}
}
uiControl.get_display().adjust_layout();