mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 21:52:30 +00:00
Merge branch 'master' into c++11
Conflicts: src/core/manager.cc src/thread_base.cc
This commit is contained in:
@@ -26,12 +26,6 @@ libsub_core_a_SOURCES = \
|
||||
manager.h \
|
||||
poll_manager.cc \
|
||||
poll_manager.h \
|
||||
poll_manager_epoll.cc \
|
||||
poll_manager_epoll.h \
|
||||
poll_manager_kqueue.cc \
|
||||
poll_manager_kqueue.h \
|
||||
poll_manager_select.cc \
|
||||
poll_manager_select.h \
|
||||
range_map.h \
|
||||
view.cc \
|
||||
view.h \
|
||||
|
||||
@@ -642,6 +642,9 @@ DownloadList::confirm_finished(Download* download) {
|
||||
|
||||
DL_TRIGGER_EVENT(download, "event.download.finished");
|
||||
|
||||
if (find(infohash) != end())
|
||||
return;
|
||||
|
||||
// if (download->resume_flags() != ~uint32_t())
|
||||
// throw torrent::internal_error("DownloadList::confirm_finished(...) download->resume_flags() != ~uint32_t().");
|
||||
|
||||
@@ -655,8 +658,7 @@ DownloadList::confirm_finished(Download* download) {
|
||||
// being hashed.
|
||||
download->set_resume_flags(~uint32_t());
|
||||
|
||||
if (find(infohash) != end() &&
|
||||
!download->is_active() && rpc::call_command_value("d.state", rpc::make_target(download)) == 1)
|
||||
if (!download->is_active() && rpc::call_command_value("d.state", rpc::make_target(download)) == 1)
|
||||
resume(download,
|
||||
torrent::Download::start_no_create |
|
||||
torrent::Download::start_skip_tracker |
|
||||
|
||||
+2
-4
@@ -71,9 +71,7 @@
|
||||
#include "download_store.h"
|
||||
#include "http_queue.h"
|
||||
#include "manager.h"
|
||||
#include "poll_manager_epoll.h"
|
||||
#include "poll_manager_kqueue.h"
|
||||
#include "poll_manager_select.h"
|
||||
#include "poll_manager.h"
|
||||
#include "view.h"
|
||||
|
||||
namespace core {
|
||||
@@ -204,7 +202,7 @@ Manager::get_address_throttle(const sockaddr* addr) {
|
||||
// Most of this should be possible to move out.
|
||||
void
|
||||
Manager::initialize_second() {
|
||||
torrent::Http::set_factory(tr1::bind(&CurlStack::new_object, m_httpStack));
|
||||
torrent::Http::slot_factory() = std::tr1::bind(&CurlStack::new_object, m_httpStack);
|
||||
m_httpQueue->slot_factory(sigc::mem_fun(m_httpStack, &CurlStack::new_object));
|
||||
|
||||
CurlStack::global_init();
|
||||
|
||||
+24
-40
@@ -39,71 +39,55 @@
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <rak/error_number.h>
|
||||
#include <torrent/poll_epoll.h>
|
||||
#include <torrent/poll_kqueue.h>
|
||||
#include <torrent/poll_select.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "control.h"
|
||||
#include "manager.h"
|
||||
#include "poll_manager.h"
|
||||
#include "poll_manager_epoll.h"
|
||||
#include "poll_manager_kqueue.h"
|
||||
#include "poll_manager_select.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
PollManager::PollManager(torrent::Poll* poll) :
|
||||
m_poll(poll) {
|
||||
|
||||
if (m_poll == NULL)
|
||||
throw std::logic_error("PollManager::PollManager(...) received poll == NULL");
|
||||
}
|
||||
|
||||
PollManager::~PollManager() {
|
||||
delete m_poll;
|
||||
}
|
||||
|
||||
PollManager*
|
||||
PollManager::create_poll_manager() {
|
||||
PollManager* pollManager = NULL;
|
||||
torrent::Poll*
|
||||
create_poll() {
|
||||
Log* log = &control->core()->get_log_important();
|
||||
|
||||
const char* poll = getenv("RTORRENT_POLL");
|
||||
const char* poll_name = getenv("RTORRENT_POLL");
|
||||
|
||||
int maxOpen = sysconf(_SC_OPEN_MAX);
|
||||
|
||||
if (poll != NULL) {
|
||||
if (!strcmp(poll, "epoll"))
|
||||
pollManager = PollManagerEPoll::create(maxOpen);
|
||||
else if (!strcmp(poll, "kqueue"))
|
||||
pollManager = PollManagerKQueue::create(maxOpen);
|
||||
else if (!strcmp(poll, "select"))
|
||||
pollManager = PollManagerSelect::create(maxOpen);
|
||||
torrent::Poll* poll = NULL;
|
||||
|
||||
if (pollManager == NULL)
|
||||
log->push_front(std::string("Cannot enable '") + poll + "' based polling.");
|
||||
if (poll_name != NULL) {
|
||||
if (!strcmp(poll_name, "epoll"))
|
||||
poll = torrent::PollEPoll::create(maxOpen);
|
||||
else if (!strcmp(poll_name, "kqueue"))
|
||||
poll = torrent::PollKQueue::create(maxOpen);
|
||||
else if (!strcmp(poll_name, "select"))
|
||||
poll = torrent::PollSelect::create(maxOpen);
|
||||
|
||||
if (poll == NULL)
|
||||
log->push_front(std::string("Cannot enable '") + poll_name + "' based polling.");
|
||||
}
|
||||
|
||||
if (pollManager != NULL)
|
||||
log->push_front(std::string("Using '") + poll + "' based polling.");
|
||||
if (poll != NULL)
|
||||
log->push_front(std::string("Using '") + poll_name + "' based polling.");
|
||||
|
||||
else if ((pollManager = PollManagerEPoll::create(maxOpen)) != NULL)
|
||||
else if ((poll = torrent::PollEPoll::create(maxOpen)) != NULL)
|
||||
log->push_front("Using 'epoll' based polling.");
|
||||
|
||||
else if ((pollManager = PollManagerKQueue::create(maxOpen)) != NULL)
|
||||
else if ((poll = torrent::PollKQueue::create(maxOpen)) != NULL)
|
||||
log->push_front("Using 'kqueue' based polling.");
|
||||
|
||||
else if ((pollManager = PollManagerSelect::create(maxOpen)) != NULL)
|
||||
else if ((poll = torrent::PollSelect::create(maxOpen)) != NULL)
|
||||
log->push_front("Using 'select' based polling.");
|
||||
|
||||
else
|
||||
throw std::runtime_error("Could not create any PollManager.");
|
||||
throw std::runtime_error("Could not create any Poll object.");
|
||||
|
||||
return pollManager;
|
||||
}
|
||||
|
||||
void
|
||||
PollManager::check_error() {
|
||||
if (rak::error_number::current().value() != rak::error_number::e_intr)
|
||||
throw std::runtime_error("Poll::work(): " + std::string(rak::error_number::current().c_str()));
|
||||
return poll;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-27
@@ -45,33 +45,7 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
// CurlStack really should be somewhere else, but that won't happen
|
||||
// until they add an epoll friendly API.
|
||||
|
||||
class PollManager {
|
||||
public:
|
||||
typedef sigc::signal0<void> Signal;
|
||||
|
||||
PollManager(torrent::Poll* poll);
|
||||
virtual ~PollManager();
|
||||
|
||||
unsigned int get_open_max() const { return m_poll->open_max(); }
|
||||
|
||||
torrent::Poll* get_torrent_poll() { return m_poll; }
|
||||
|
||||
virtual void poll(rak::timer timeout) = 0;
|
||||
virtual void poll_simple(rak::timer timeout) = 0;
|
||||
|
||||
static PollManager* create_poll_manager();
|
||||
|
||||
protected:
|
||||
PollManager(const PollManager&);
|
||||
void operator = (const PollManager&);
|
||||
|
||||
void check_error();
|
||||
|
||||
torrent::Poll* m_poll;
|
||||
};
|
||||
torrent::Poll* create_poll();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <torrent/poll_epoll.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "poll_manager_epoll.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
PollManagerEPoll*
|
||||
PollManagerEPoll::create(int maxOpenSockets) {
|
||||
torrent::PollEPoll* p = torrent::PollEPoll::create(maxOpenSockets);
|
||||
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return new PollManagerEPoll(p);
|
||||
}
|
||||
|
||||
PollManagerEPoll::~PollManagerEPoll() {
|
||||
}
|
||||
|
||||
void
|
||||
PollManagerEPoll::poll(rak::timer timeout) {
|
||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
||||
// resolution.
|
||||
torrent::perform();
|
||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
||||
|
||||
ThreadBase::release_global_lock();
|
||||
ThreadBase::entering_main_polling();
|
||||
|
||||
int status = static_cast<torrent::PollEPoll*>(m_poll)->poll((timeout.usec() + 999) / 1000);
|
||||
|
||||
ThreadBase::leaving_main_polling();
|
||||
ThreadBase::acquire_global_lock();
|
||||
|
||||
if (status == -1)
|
||||
return check_error();
|
||||
|
||||
torrent::perform();
|
||||
static_cast<torrent::PollEPoll*>(m_poll)->perform();
|
||||
}
|
||||
|
||||
void
|
||||
PollManagerEPoll::poll_simple(rak::timer timeout) {
|
||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
||||
// resolution.
|
||||
timeout = timeout + 1000;
|
||||
|
||||
if (static_cast<torrent::PollEPoll*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1)
|
||||
return check_error();
|
||||
|
||||
static_cast<torrent::PollEPoll*>(m_poll)->perform();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_CORE_POLL_MANAGER_EPOLL_H
|
||||
#define RTORRENT_CORE_POLL_MANAGER_EPOLL_H
|
||||
|
||||
#include "poll_manager.h"
|
||||
|
||||
namespace torrent {
|
||||
class PollEPoll;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
|
||||
class PollManagerEPoll : public PollManager {
|
||||
public:
|
||||
static PollManagerEPoll* create(int maxOpenSockets);
|
||||
~PollManagerEPoll();
|
||||
|
||||
torrent::Poll* get_torrent_poll();
|
||||
|
||||
void poll(rak::timer timeout);
|
||||
void poll_simple(rak::timer timeout);
|
||||
|
||||
private:
|
||||
PollManagerEPoll(torrent::Poll* p) : PollManager(p) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/poll_kqueue.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "poll_manager_kqueue.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
PollManagerKQueue*
|
||||
PollManagerKQueue::create(int maxOpenSockets) {
|
||||
torrent::PollKQueue* p = torrent::PollKQueue::create(maxOpenSockets);
|
||||
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return new PollManagerKQueue(p);
|
||||
}
|
||||
|
||||
PollManagerKQueue::~PollManagerKQueue() {
|
||||
}
|
||||
|
||||
void
|
||||
PollManagerKQueue::poll(rak::timer timeout) {
|
||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
||||
// resolution.
|
||||
torrent::perform();
|
||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
||||
|
||||
ThreadBase::release_global_lock();
|
||||
ThreadBase::entering_main_polling();
|
||||
|
||||
int status = static_cast<torrent::PollKQueue*>(m_poll)->poll((timeout.usec() + 999) / 1000);
|
||||
|
||||
ThreadBase::leaving_main_polling();
|
||||
ThreadBase::acquire_global_lock();
|
||||
|
||||
if (status == -1)
|
||||
return check_error();
|
||||
|
||||
torrent::perform();
|
||||
static_cast<torrent::PollKQueue*>(m_poll)->perform();
|
||||
}
|
||||
|
||||
void
|
||||
PollManagerKQueue::poll_simple(rak::timer timeout) {
|
||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
||||
// resolution.
|
||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
||||
|
||||
if (static_cast<torrent::PollKQueue*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1)
|
||||
return check_error();
|
||||
|
||||
static_cast<torrent::PollKQueue*>(m_poll)->perform();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_CORE_POLL_MANAGER_KQUEUE_H
|
||||
#define RTORRENT_CORE_POLL_MANAGER_KQUEUE_H
|
||||
|
||||
#include "poll_manager.h"
|
||||
|
||||
namespace torrent {
|
||||
class PollKQueue;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
|
||||
class PollManagerKQueue : public PollManager {
|
||||
public:
|
||||
static PollManagerKQueue* create(int maxOpenSockets);
|
||||
~PollManagerKQueue();
|
||||
|
||||
torrent::Poll* get_torrent_poll();
|
||||
|
||||
void poll(rak::timer timeout);
|
||||
void poll_simple(rak::timer timeout);
|
||||
|
||||
private:
|
||||
PollManagerKQueue(torrent::Poll* p) : PollManager(p) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <rak/allocators.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/poll_select.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "poll_manager_select.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
PollManagerSelect::PollManagerSelect(torrent::Poll* p) : PollManager(p) {
|
||||
#if defined USE_VARIABLE_FDSET
|
||||
m_setSize = (m_poll->open_max() + 7) / 8;
|
||||
|
||||
char* buffer = rak::cacheline_allocator<char>::alloc_size(3 * m_setSize);
|
||||
std::memset(buffer, 0, 3 * m_setSize);
|
||||
|
||||
m_readSet = (fd_set*)buffer;
|
||||
m_writeSet = (fd_set*)(buffer += m_setSize);
|
||||
m_errorSet = (fd_set*)(buffer += m_setSize);
|
||||
#else
|
||||
#error Only variable fdset supported atm.
|
||||
#endif
|
||||
}
|
||||
|
||||
PollManagerSelect*
|
||||
PollManagerSelect::create(int maxOpenSockets) {
|
||||
torrent::PollSelect* p = torrent::PollSelect::create(maxOpenSockets);
|
||||
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
return new PollManagerSelect(p);
|
||||
}
|
||||
|
||||
PollManagerSelect::~PollManagerSelect() {
|
||||
free(m_readSet);
|
||||
}
|
||||
|
||||
void
|
||||
PollManagerSelect::poll(rak::timer timeout) {
|
||||
torrent::perform();
|
||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
||||
|
||||
std::memset(m_readSet, 0, m_setSize);
|
||||
std::memset(m_writeSet, 0, m_setSize);
|
||||
std::memset(m_errorSet, 0, m_setSize);
|
||||
|
||||
unsigned int maxFd = static_cast<torrent::PollSelect*>(m_poll)->fdset(m_readSet, m_writeSet, m_errorSet);
|
||||
|
||||
timeval t = timeout.tval();
|
||||
|
||||
ThreadBase::entering_main_polling();
|
||||
ThreadBase::release_global_lock();
|
||||
|
||||
int status = select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t);
|
||||
|
||||
ThreadBase::leaving_main_polling();
|
||||
ThreadBase::acquire_global_lock();
|
||||
|
||||
if (status == -1)
|
||||
return check_error();
|
||||
|
||||
torrent::perform();
|
||||
static_cast<torrent::PollSelect*>(m_poll)->perform(m_readSet, m_writeSet, m_errorSet);
|
||||
}
|
||||
|
||||
void
|
||||
PollManagerSelect::poll_simple(rak::timer timeout) {
|
||||
torrent::PollSelect* currentPoll = static_cast<torrent::PollSelect*>(m_poll);
|
||||
|
||||
timeout = timeout + 1000;
|
||||
std::memset(m_readSet, 0, 3 * m_setSize);
|
||||
|
||||
unsigned int maxFd = currentPoll->fdset(m_readSet, m_writeSet, m_errorSet);
|
||||
|
||||
timeval t = timeout.tval();
|
||||
|
||||
if (select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t) == -1)
|
||||
return check_error();
|
||||
|
||||
currentPoll->perform(m_readSet, m_writeSet, m_errorSet);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_CORE_POLL_MANAGER_SELECT_H
|
||||
#define RTORRENT_CORE_POLL_MANAGER_SELECT_H
|
||||
|
||||
#include "poll_manager.h"
|
||||
|
||||
namespace torrent {
|
||||
class PollSelect;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
|
||||
class lt_cacheline_aligned PollManagerSelect : public PollManager {
|
||||
public:
|
||||
static PollManagerSelect* create(int maxOpenSockets);
|
||||
~PollManagerSelect();
|
||||
|
||||
void poll(rak::timer timeout);
|
||||
void poll_simple(rak::timer timeout);
|
||||
|
||||
private:
|
||||
PollManagerSelect(torrent::Poll* p);
|
||||
|
||||
unsigned int m_setSize;
|
||||
fd_set* m_readSet;
|
||||
fd_set* m_writeSet;
|
||||
fd_set* m_errorSet;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user