From 424a20b3f5d2eb77d5344cfb9b051eeca7816770 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Mon, 25 Jul 2005 15:28:03 +0000 Subject: [PATCH] * Changed the API to support different Poll objects and made PollSelect available. Started work on PollEPoll. * Fixed a bug that caused blank characters to be inserted into the tracker request url. * Added display of the options field in the peer info view. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@508 e378c898-3ddf-0310-93e7-cc216c733640 --- configure.ac | 1 + scripts/checks.m4 | 114 +++++++++++++++++++++++++++++--- scripts/common.m4 | 27 +++++--- src/core/Makefile.am | 5 +- src/core/manager.cc | 10 +++ src/core/manager.h | 3 +- src/core/poll.cc | 22 +++++- src/core/poll.h | 36 +++++----- src/core/poll_epoll.cc | 96 +++++++++++++++++++++++++++ src/core/poll_epoll.h | 77 +++++++++++++++++++++ src/display/window_peer_info.cc | 1 + src/main.cc | 4 +- 12 files changed, 357 insertions(+), 39 deletions(-) create mode 100644 src/core/poll_epoll.cc create mode 100644 src/core/poll_epoll.h diff --git a/configure.ac b/configure.ac index 8a39e264..ed685d3a 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,7 @@ AC_SEARCH_LIBS(wbkgdset, ncurses curses,,echo "*** The ncurses library is requir TORRENT_CHECK_EXECINFO() TORRENT_CHECK_CURL() +TORRENT_WITHOUT_EPOLL() TORRENT_OTFD() PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.7.1, diff --git a/scripts/checks.m4 b/scripts/checks.m4 index 982858bf..c750bf78 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -18,8 +18,8 @@ AC_DEFUN([TORRENT_CHECK_CURL], [ my_cv_curl_vers="$ver" AC_MSG_RESULT([$my_cv_curl_vers]) - CURL_CFLAGS="`curl-config --cflags`" - CURL_LIBS="`curl-config --libs`" + CURL_CFLAGS=`curl-config --cflags` + CURL_LIBS=`curl-config --libs` else AC_MSG_RESULT(FAILED) AC_MSG_ERROR([$ver is too old. Need version $check or higher.]) @@ -36,13 +36,13 @@ AC_DEFUN([TORRENT_CHECK_OPENSSL], [ # first, deal with the user option : set places to be 'search' or the prefix AC_ARG_WITH(openssl, [ --with-openssl=PATH Find the OpenSSL header and library in - `PATH/include' and `PATH/lib'. If PATH is of the - form `HEADER:LIB', then search for header files in - HEADER, and the library in LIB. If you omit the - option completely, the configure script will - search for OpenSSL in a number of standard - places. - ], [ + `PATH/include' and `PATH/lib'. If PATH is of the + form `HEADER:LIB', then search for header files in + HEADER, and the library in LIB. If you omit the + option completely, the configure script will + search for OpenSSL in a number of standard + places.], + [ if test "$withval" = "yes"; then PKG_CHECK_MODULES(OPENSSL, openssl, CXXFLAGS="$CXXFLAGS `pkg-config --cflags openssl`"; @@ -60,3 +60,99 @@ AC_DEFUN([TORRENT_CHECK_OPENSSL], [ AC_MSG_ERROR(Could not find openssl's crypto library, try --with-openssl=PATH)) ]) ]) + + +AC_DEFUN([TORRENT_CHECK_XFS], [ + AC_MSG_CHECKING(for XFS support) + + AC_COMPILE_IFELSE( + [[#include + #include + int main() { + struct xfs_flock64 l; + ioctl(0, XFS_IOC_RESVSP64, &l); + return 0; + } + ]], + [ + AC_DEFINE(HAS_XFS, 1, XFS filesystem supported.) + AC_MSG_RESULT(yes) + ], [ + AC_MSG_RESULT(no) + ]) +]) + + +AC_DEFUN([TORRENT_WITHOUT_XFS], [ + AC_ARG_WITH(xfs, + [ --without-xfs Do not check for XFS filesystem support], + [ + if test "$withval" = "yes"; then + TORRENT_CHECK_XFS + fi + ], [ + TORRENT_CHECK_XFS + ]) +]) + + +AC_DEFUN([TORRENT_CHECK_EPOLL], [ + AC_MSG_CHECKING(for epoll support) + + AC_COMPILE_IFELSE( + [[#include + int main() { + int fd = epoll_create(100); + return 0; + } + ]], + [ + AC_DEFINE(HAS_EPOLL, 1, epoll supported.) + AC_MSG_RESULT(yes) + ], [ + AC_MSG_RESULT(no) + ]) +]) + + +AC_DEFUN([TORRENT_WITHOUT_EPOLL], [ + AC_ARG_WITH(epoll, + [ --without-epoll Do not check for epoll support], + [ + if test "$withval" = "yes"; then + TORRENT_CHECK_EPOLL + fi + ], [ + TORRENT_CHECK_EPOLL + ]) +]) + + +AC_DEFUN([TORRENT_CHECK_POSIX_FALLOCATE], [ + AC_MSG_CHECKING(for posix_fallocate) + + AC_COMPILE_IFELSE( + [[#include + int main() { + posix_fallocate(0, 0, 0); + return 0; + } + ]], + [ + AC_DEFINE(HAS_POSIX_FALLOCATE, 1, posix_fallocate supported.) + AC_MSG_RESULT(yes) + ], [ + AC_MSG_RESULT(no) + ]) +]) + + +AC_DEFUN([TORRENT_WITH_POSIX_FALLOCATE], [ + AC_ARG_WITH(posix-fallocate, + [ --with-fallocate Check for posix_fallocate], + [ + if test "$withval" = "no"; then + TORRENT_CHECK_POSIX_FALLOCATE + fi + ]) +]) diff --git a/scripts/common.m4 b/scripts/common.m4 index 2495b2e7..9e96c723 100644 --- a/scripts/common.m4 +++ b/scripts/common.m4 @@ -2,17 +2,16 @@ AC_DEFUN([TORRENT_CHECK_CXXFLAGS], [ AC_MSG_CHECKING([for user-defined CXXFLAGS]) - if test !$CXXFLAGS; then + if test $CXXFLAGS; then + AC_MSG_RESULT([user-defined "$CXXFLAGS"]) + else CXXFLAGS="-O3 -Wall" AC_MSG_RESULT([default "$CXXFLAGS"]) - else - AC_MSG_RESULT([user-defined "$CXXFLAGS"]) fi ]) AC_DEFUN([TORRENT_ENABLE_DEBUG], [ - AC_ARG_ENABLE(debug, [ --enable-debug enable debug information [default=yes]], [ @@ -28,7 +27,6 @@ AC_DEFUN([TORRENT_ENABLE_DEBUG], [ AC_DEFUN([TORRENT_ENABLE_WERROR], [ - AC_ARG_ENABLE(werror, [ --enable-werror enable the -Werror flag [default=no]], [ @@ -39,8 +37,23 @@ AC_DEFUN([TORRENT_ENABLE_WERROR], [ ]) -AC_DEFUN([TORRENT_OTFD], [ +AC_DEFUN([TORRENT_ENABLE_UNSAFE_OPTIMIZATION], [ + AC_ARG_ENABLE(unsafe-optimization, + [ --enable-unsafe-optimization + enable unsafe optimization [default=yes]], + [ + if test "$enableval" = "yes"; then + AC_DEFINE(USE_UNSAFE_OPTIMIZATION, 1, Enable possibly unsafe optimization techniques.) + else + AC_DEFINE(USE_UNSAFE_OPTIMIZATION, 0, Disable possibly unsafe optimization techniques.) + fi + ],[ + AC_DEFINE(USE_UNSAFE_OPTIMIZATION, 0, Disable possibly unsafe optimization techniques.) + ]) +]) + +AC_DEFUN([TORRENT_OTFD], [ AC_LANG_PUSH(C++) AC_MSG_CHECKING(for proper overloaded template function disambiguation) @@ -61,7 +74,6 @@ AC_DEFUN([TORRENT_OTFD], [ AC_DEFUN([TORRENT_MINCORE_SIGNEDNESS], [ - AC_LANG_PUSH(C++) AC_MSG_CHECKING(signedness of mincore parameter) @@ -93,7 +105,6 @@ AC_DEFUN([TORRENT_MINCORE_SIGNEDNESS], [ ]) AC_DEFUN([TORRENT_CHECK_EXECINFO], [ - AC_MSG_CHECKING(for execinfo.h) AC_COMPILE_IFELSE( diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 25510773..69db491d 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -23,7 +23,8 @@ libsub_core_a_SOURCES = \ manager.cc \ manager.h \ poll.cc \ - poll.h - + poll.h \ + poll_epoll.cc \ + poll_epoll.h INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir) diff --git a/src/core/manager.cc b/src/core/manager.cc index a6037244..cabaca27 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -64,6 +64,16 @@ connect_signal_tracker_log(Download* d, torrent::Download::SlotString s) { d->get_download().signal_tracker_failed(s); } +Manager::Manager() : + m_portRandom(false), + m_portFirst(6890), + m_portLast(6999), + m_checkHash(true) { +} + +Manager::~Manager() { +} + void Manager::initialize() { torrent::Http::set_factory(m_poll.get_http_factory()); diff --git a/src/core/manager.h b/src/core/manager.h index 15964aa0..4538101f 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -58,7 +58,8 @@ public: typedef sigc::slot1 SlotReady; typedef sigc::slot0 SlotFailed; - Manager() : m_portRandom(false), m_portFirst(6890), m_portLast(6999), m_checkHash(true) {} + Manager(); + ~Manager(); DownloadList& get_download_list() { return m_downloadList; } DownloadStore& get_download_store() { return m_downloadStore; } diff --git a/src/core/poll.cc b/src/core/poll.cc index f221aac3..bb5cac21 100644 --- a/src/core/poll.cc +++ b/src/core/poll.cc @@ -43,12 +43,28 @@ #include #include #include +#include #include "poll.h" #include "curl_get.h" namespace core { +Poll::Poll() : + m_readSet(new fd_set), + m_writeSet(new fd_set), + m_exceptSet(new fd_set), + m_torrentPoll(new torrent::PollSelect) +{ +} + +Poll::~Poll() { + delete m_readSet; + delete m_writeSet; + delete m_exceptSet; + delete m_torrentPoll; +} + void Poll::poll(utils::Timer timeout) { // Do we want to clear m_maxFd in torrent::mark? @@ -60,7 +76,7 @@ Poll::poll(utils::Timer timeout) { FD_SET(0, m_readSet); - torrent::mark(m_readSet, m_writeSet, m_exceptSet, &m_maxFd); + m_maxFd = m_torrentPoll->mark(m_readSet, m_writeSet, m_exceptSet); if (m_curlStack.is_busy()) { int n = 0; @@ -96,7 +112,9 @@ Poll::work() { if (m_curlStack.is_busy()) m_curlStack.perform(); - torrent::work(m_readSet, m_writeSet, m_exceptSet, m_maxFd); + torrent::perform(); + m_torrentPoll->work(m_readSet, m_writeSet, m_exceptSet); + torrent::perform(); } void diff --git a/src/core/poll.h b/src/core/poll.h index 02f63922..48444070 100644 --- a/src/core/poll.h +++ b/src/core/poll.h @@ -43,6 +43,10 @@ #include "utils/timer.h" #include "curl_stack.h" +namespace torrent { + class PollSelect; +} + namespace core { class CurlGet; @@ -53,32 +57,34 @@ public: typedef sigc::slot1 SlotInt; typedef sigc::slot0 SlotFactory; - Poll() : m_readSet(new fd_set), m_writeSet(new fd_set), m_exceptSet(new fd_set) {} - ~Poll() { delete m_readSet; delete m_writeSet; delete m_exceptSet; } + Poll(); + ~Poll(); - void poll(utils::Timer t); + void poll(utils::Timer t); - SlotFactory get_http_factory(); + SlotFactory get_http_factory(); + torrent::Poll* get_torrent_poll() { return reinterpret_cast(m_torrentPoll); } - 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: Poll(const Poll&); void operator = (const Poll&); - 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; + torrent::PollSelect* m_torrentPoll; }; } diff --git a/src/core/poll_epoll.cc b/src/core/poll_epoll.cc new file mode 100644 index 00000000..d2ff5168 --- /dev/null +++ b/src/core/poll_epoll.cc @@ -0,0 +1,96 @@ +// rTorrent - BitTorrent client +// Copyright (C) 2005, 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 +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#include "config.h" + +#include "poll_epoll.h" + +namespace core { + +PollEPoll::PollEPoll() { +} + +PollEPoll::~PollEPoll() { +} + +void +PollEPoll::open(torrent::Event* event) { +} + +void +PollEPoll::close(torrent::Event* event) { +} + +bool +PollEPoll::in_read(torrent::Event* event) { + return false; +} + +bool +PollEPoll::in_write(torrent::Event* event) { + return false; +} + +bool +PollEPoll::in_error(torrent::Event* event) { + return false; +} + +void +PollEPoll::insert_read(torrent::Event* event) { +} + +void +PollEPoll::insert_write(torrent::Event* event) { +} + +void +PollEPoll::insert_error(torrent::Event* event) { +} + +void +PollEPoll::remove_read(torrent::Event* event) { +} + +void +PollEPoll::remove_write(torrent::Event* event) { +} + +void +PollEPoll::remove_error(torrent::Event* event) { +} + +} diff --git a/src/core/poll_epoll.h b/src/core/poll_epoll.h new file mode 100644 index 00000000..7ef062eb --- /dev/null +++ b/src/core/poll_epoll.h @@ -0,0 +1,77 @@ +// rTorrent - BitTorrent client +// Copyright (C) 2005, 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 +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#ifndef RTORRENT_CORE_POLL_EPOLL_H +#define RTORRENT_CORE_POLL_EPOLL_H + +#include + +namespace core { + +class PollEPoll : public torrent::Poll { + PollEPoll(); + virtual ~PollEPoll(); + + // Add configuration options for doing stuff like setting max open + // sockets etc? + + // torrent::Event::get_fd() is guaranteed to be valid and remain constant + // from open(...) is called to close(...) returns. + virtual void open(torrent::Event* event); + virtual void close(torrent::Event* event); + + // Functions for checking whetever the torrent::Event is listening to r/w/e? + virtual bool in_read(torrent::Event* event); + virtual bool in_write(torrent::Event* event); + virtual bool in_error(torrent::Event* event); + + // These functions may be called on 'event's that might, or might + // not, already be in the set. + virtual void insert_read(torrent::Event* event); + virtual void insert_write(torrent::Event* event); + virtual void insert_error(torrent::Event* event); + + virtual void remove_read(torrent::Event* event); + virtual void remove_write(torrent::Event* event); + virtual void remove_error(torrent::Event* event); + +private: + int m_fd; +}; + +} + +#endif diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index 97925452..e1b30346 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -84,6 +84,7 @@ WindowPeerInfo::redraw() { m_canvas->print(0, y++, "DNS: %s:%hu", (*m_focus)->get_dns().c_str(), (*m_focus)->get_port()); m_canvas->print(0, y++, "Id: %s" , utils::escape_string((*m_focus)->get_id()).c_str()); + m_canvas->print(0, y++, "Options: %s" , utils::string_to_hex(std::string((*m_focus)->get_options(), 8)).c_str()); m_canvas->print(0, y++, "Snubbed: %s", (*m_focus)->get_snubbed() ? "Yes" : "No"); m_canvas->print(0, y++, "Done: %i%", done_percentage(**m_focus)); diff --git a/src/main.cc b/src/main.cc index 39739e44..571a4d4c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -223,7 +223,7 @@ main(int argc, char** argv) { SignalHandler::set_handler(SIGFPE, sigc::bind(sigc::ptr_fun(&do_panic), SIGFPE)); // Need to initialize this before parseing options. - torrent::initialize(); + torrent::initialize(uiControl.get_core().get_poll().get_torrent_poll()); if (getenv("HOME")) load_option_file(getenv("HOME") + std::string("/.rtorrent.rc"), &optionHandler); @@ -323,7 +323,7 @@ receive_tracker_dump(std::istream* s) { void print_help() { - std::cout << "Rakshasa's BitTorrent client " VERSION "." << std::endl; + std::cout << "Rakshasa's BitTorrent client version " VERSION "." << std::endl; std::cout << std::endl; std::cout << "All value pairs (f.ex rate and queue size) will be in the UP/DOWN" << std::endl; std::cout << "order. Use the up/down/left/right arrow keys to move between screens." << std::endl;