2008-05-24 Albert Lee <[email protected]>
authortrisk
Sat, 24 May 2008 09:11:53 +0000
changeset 1152 24f4e428f2d0
parent 1151 57ba40acfb7f
child 1153 c0a013e9d965
2008-05-24 Albert Lee <[email protected]> * SFErtorrent.spec: Add SFExmlrpc-c-gpp dependencies * SFExmlrpc-c-gpp.spec: *NEW* A lightweight RPC library based on XML and HTTP (g++ version) * base-specs/libtorrent.spec: Enable ports, add patch2 * base-specs/rtorrent.spec: Enable XML-RPC * base-specs/xmlrpc-c.spec: *NEW* Base spec for xmlrpc-c * patches/libtorrent-02-event-ports.diff: Patch for event completion by River Tarnell * patches/rtorrent-01-solaris.diff: Minor addition to patch * patches/rtorrent-02-event-ports.diff: Patch for event completion by River Tarnell
ChangeLog
SFErtorrent.spec
SFExmlrpc-c-gpp.spec
base-specs/libtorrent.spec
base-specs/rtorrent.spec
base-specs/xmlrpc-c.spec
patches/libtorrent-02-event-ports.diff
patches/rtorrent-01-solaris.diff
patches/rtorrent-02-event-ports.diff
--- a/ChangeLog	Sat May 24 06:34:23 2008 +0000
+++ b/ChangeLog	Sat May 24 09:11:53 2008 +0000
@@ -1,3 +1,17 @@
+2008-05-24  Albert Lee  <[email protected]>
+
+	* SFErtorrent.spec: Add SFExmlrpc-c-gpp dependencies
+	* SFExmlrpc-c-gpp.spec: *NEW* A lightweight RPC library based on XML and
+	  HTTP (g++ version)
+	* base-specs/libtorrent.spec: Enable ports, add patch2
+	* base-specs/rtorrent.spec: Enable XML-RPC
+	* base-specs/xmlrpc-c.spec: *NEW* Base spec for xmlrpc-c
+	* patches/libtorrent-02-event-ports.diff: Patch for event completion
+	  by River Tarnell
+	* patches/rtorrent-01-solaris.diff: Minor addition to patch
+	* patches/rtorrent-02-event-ports.diff: Patch for event completion by
+	  River Tarnell
+
 2008-05-24  Albert Lee  <[email protected]>
 
 	* SFEiodine.spec: Bump to 0.4.1
--- a/SFErtorrent.spec	Sat May 24 06:34:23 2008 +0000
+++ b/SFErtorrent.spec	Sat May 24 09:11:53 2008 +0000
@@ -21,6 +21,8 @@
 Requires: SFElibtorrent-gpp
 BuildRequires: SFEsigcpp-gpp-devel
 BuildRequires: SFElibtorrent-gpp-devel
+Requires: SFExmlrpc-c-gpp
+BuildRequires: SFExmlrpc-c-gpp-devel
 Requires: SUNWcurl
 Requires: SFEncurses
 BuildRequires: SFEncurses-devel
@@ -55,5 +57,7 @@
 %{_mandir}/man1/rtorrent.1
 
 %changelog
+* Sat May 24 2008 - [email protected].
+- Add SFExmlrpc-c-gpp dependencies
 * Fri May  9 2008 - [email protected]
 - Initial version
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SFExmlrpc-c-gpp.spec	Sat May 24 09:11:53 2008 +0000
@@ -0,0 +1,61 @@
+#
+# spec file for package SFExmlrpc-c-gpp
+#
+# includes module(s): xmlrpc-c-gpp
+#
+%include Solaris.inc
+
+%define cc_is_gcc 1
+%include base.inc
+
+%use xmlrpc_c = xmlrpc-c.spec
+
+Name:                   SFExmlrpc-c-gpp
+Summary:                A lightweight RPC library based on XML and HTTP (g++ version)
+Version:                %{xmlrpc_c.version}
+SUNW_BaseDir:           %{_basedir}
+BuildRoot:              %{_tmppath}/%{name}-%{version}-build
+%include default-depend.inc
+Requires: SUNWlibC
+Requires: SUNWgccruntime
+
+%package devel
+Summary:                 %{summary} - development files
+SUNW_BaseDir:            %{_prefix}
+%include default-depend.inc
+
+%prep
+rm -rf %name-%version
+mkdir %name-%version
+%xmlrpc_c.prep -d %name-%version
+cd %{_builddir}/%name-%version
+
+%build
+export CC=gcc
+export CXX=g++
+export CXXFLAGS="%{gcc_cxx_optflags}"
+export CFLAGS="%{gcc_optflags}"
+export LDFLAGS="%_ldflags"
+%xmlrpc_c.build -d %name-%version
+
+%install
+rm -rf $RPM_BUILD_ROOT
+%xmlrpc_c.install -d %name-%version
+rm $RPM_BUILD_ROOT%{_libdir}/lib*.*a
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr (-, root, bin)
+%{_bindir}
+%dir %attr (0755,root,bin) %{_libdir}
+%{_libdir}/lib*.so*
+
+%files devel
+%defattr (-, root, bin)
+%{_includedir}
+
+%changelog
+* Sat May 24 2008 - [email protected]
+- Initial spec
--- a/base-specs/libtorrent.spec	Sat May 24 06:34:23 2008 +0000
+++ b/base-specs/libtorrent.spec	Sat May 24 09:11:53 2008 +0000
@@ -9,11 +9,13 @@
 Version:	0.12.2
 Source:		http://libtorrent.rakshasa.no/downloads/libtorrent-%{version}.tar.gz
 Patch1:         libtorrent-01-madvise.diff
+Patch2:         libtorrent-02-event-ports.diff
 BuildRoot:	%{_tmppath}/%{name}-%{version}-build
 
 %prep
 %setup -q -n %{name}-%{version}
 %patch1 -p1
+%patch2 -p1
 
 %build
 CPUS=`/usr/sbin/psrinfo | grep on-line | wc -l | tr -d ' '`
@@ -33,7 +35,8 @@
             --libexecdir=%{_libexecdir}	\
             --sysconfdir=%{_sysconfdir}	\
             --enable-shared		\
-	    --disable-static
+	    --disable-static		\
+	    --with-ports
 
 make -j$CPUS
 
@@ -45,5 +48,7 @@
 rm -rf $RPM_BUILD_ROOT
 
 %changelog
+* Sat May 24 2008 - [email protected].
+- Enable ports, add patch2
 * Fri May  9 2008 - [email protected]
 - Initial base spec file
--- a/base-specs/rtorrent.spec	Sat May 24 06:34:23 2008 +0000
+++ b/base-specs/rtorrent.spec	Sat May 24 09:11:53 2008 +0000
@@ -9,11 +9,13 @@
 Version:	0.8.2
 Source:		http://libtorrent.rakshasa.no/downloads/rtorrent-%{version}.tar.gz
 Patch1:         rtorrent-01-solaris.diff
+Patch2:         rtorrent-02-event-ports.diff
 BuildRoot:	%{_tmppath}/%{name}-%{version}-build
 
 %prep
 %setup -q -n %{name}-%{version}
 %patch1 -p1 -b .orig
+%patch2 -p1
 
 %build
 CPUS=`/usr/sbin/psrinfo | grep on-line | wc -l | tr -d ' '`
@@ -33,7 +35,8 @@
             --libexecdir=%{_libexecdir}	\
             --sysconfdir=%{_sysconfdir}	\
             --enable-shared		\
-	    --disable-static
+	    --disable-static		\
+	    --with-xmlrpc-c
 
 make -j$CPUS
 
@@ -44,5 +47,7 @@
 rm -rf $RPM_BUILD_ROOT
 
 %changelog
+* Sat May 24 2008 - [email protected]
+- Enable XML-RPC, add patch2
 * Fri May  9 2008 - [email protected]
 - Initial base spec file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base-specs/xmlrpc-c.spec	Sat May 24 09:11:53 2008 +0000
@@ -0,0 +1,48 @@
+#
+# spec file for package xmlrpc-c
+#
+# includes module(s): xmlrpc-c
+#
+%include Solaris.inc
+
+%define src_name	xmlrpc
+%define src_url		%{sf_download}/xmlrpc-c
+
+Name:                   xmlrpc-c
+Summary:                A lightweight RPC library based on XML and HTTP
+Version:                1.06.27
+Source:                 %{src_url}/%{src_name}-%{version}.tgz
+BuildRoot:              %{_tmppath}/%{name}-%{version}-build
+
+%prep
+%setup -q -n xmlrpc-c-%{version}
+
+%build
+CPUS=`/usr/sbin/psrinfo | grep on-line | wc -l | tr -d ' '`
+if test "x$CPUS" = "x" -o $CPUS = 0; then
+    CPUS=1
+fi
+
+./configure --prefix=%{_prefix}		\
+	    --bindir=%{_bindir}		\
+	    --mandir=%{_mandir}		\
+            --libdir=%{_libdir}		\
+            --datadir=%{_datadir}	\
+            --libexecdir=%{_libexecdir} \
+            --sysconfdir=%{_sysconfdir} \
+            --enable-shared		\
+	    --disable-werror		\
+	    --disable-warnings
+
+make -j$CPUS
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make install DESTDIR=$RPM_BUILD_ROOT
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%changelog
+* Sat May 24 2008 - [email protected]
+- Initial base spec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/libtorrent-02-event-ports.diff	Sat May 24 09:11:53 2008 +0000
@@ -0,0 +1,501 @@
+diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/config.h.in libtorrent-0.11.9-new/config.h.in
+--- libtorrent-0.11.9/config.h.in	2007-10-25 09:51:00.000000000 +0000
++++ libtorrent-0.11.9-new/config.h.in	2008-01-13 17:17:20.030864435 +0000
+@@ -141,6 +141,9 @@
+ /* Using OpenSSL's SHA1 implementation. */
+ #undef USE_OPENSSL_SHA
+ 
++/* Enable ports. */
++#undef USE_PORTS
++
+ /* posix_fallocate supported. */
+ #undef USE_POSIX_FALLOCATE
+ 
+diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/configure.ac libtorrent-0.11.9-new/configure.ac
+--- libtorrent-0.11.9/configure.ac	2007-10-25 09:48:32.000000000 +0000
++++ libtorrent-0.11.9-new/configure.ac	2008-01-13 17:13:30.892756466 +0000
+@@ -43,6 +43,7 @@
+ 
+ dnl TORRENT_WITH_XFS
+ TORRENT_WITH_KQUEUE
++TORRENT_WITH_PORTS
+ TORRENT_WITHOUT_EPOLL
+ TORRENT_WITH_POSIX_FALLOCATE
+ TORRENT_WITH_ADDRESS_SPACE
+diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/scripts/checks.m4 libtorrent-0.11.9-new/scripts/checks.m4
+--- libtorrent-0.11.9/scripts/checks.m4	2007-10-09 01:41:07.000000000 +0000
++++ libtorrent-0.11.9-new/scripts/checks.m4	2008-01-13 17:04:39.692325909 +0000
+@@ -85,6 +85,15 @@
+     ])
+ ])
+ 
++AC_DEFUN([TORRENT_WITH_PORTS], [
++  AC_ARG_WITH(ports,
++    [  --with-ports            enable Solaris ports. [[default=no]]],
++    [
++        if test "$withval" = "yes"; then
++            AC_DEFINE(USE_PORTS, 1, Enable ports.)
++        fi
++    ])
++])
+ 
+ AC_DEFUN([TORRENT_WITHOUT_VARIABLE_FDSET], [
+   AC_ARG_WITH(variable-fdset,
+diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/src/data/memory_chunk.cc libtorrent-0.11.9-new/src/data/memory_chunk.cc
+--- libtorrent-0.11.9/src/data/memory_chunk.cc	2007-07-19 21:23:06.000000000 +0000
++++ libtorrent-0.11.9-new/src/data/memory_chunk.cc	2008-01-13 15:25:19.923524858 +0000
+@@ -121,7 +121,7 @@
+ #if USE_MADVISE
+   align_pair(&offset, &length);
+ 
+-  if (madvise(m_ptr + offset, length, advice) == 0)
++  if (::madvise(m_ptr + offset, length, advice) == 0)
+     return true;
+ 
+   else if (errno == EINVAL || (errno == ENOMEM && advice != advice_willneed) || errno == EBADF)
+diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/src/torrent/Makefile.am libtorrent-0.11.9-new/src/torrent/Makefile.am
+--- libtorrent-0.11.9/src/torrent/Makefile.am	2007-02-02 11:09:56.000000000 +0000
++++ libtorrent-0.11.9-new/src/torrent/Makefile.am	2008-01-13 17:51:02.471766611 +0000
+@@ -33,6 +33,8 @@
+ 	poll_epoll.h \
+ 	poll_kqueue.h \
+ 	poll_kqueue.cc \
++	poll_ports.cc \
++	poll_ports.h \
+ 	poll_select.h \
+ 	poll_select.cc \
+ 	rate.cc \
+@@ -65,6 +67,7 @@
+ 	path.h \
+ 	poll.h \
+ 	poll_epoll.h \
++	poll_ports.h \
+ 	poll_kqueue.h \
+ 	poll_select.h \
+ 	rate.h \
+diff -urN libtorrent.orig/src/torrent/poll_ports.cc libtorrent/src/torrent/poll_ports.cc
+--- libtorrent.orig/src/torrent/poll_ports.cc	1969-12-31 19:00:00.000000000 -0500
++++ libtorrent/src/torrent/poll_ports.cc	2008-05-12 00:42:15.000000000 -0400
+@@ -0,0 +1,318 @@
++// libTorrent - BitTorrent library
++// Copyright (C) 2005-2007, 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 <[email protected]>
++//
++//           Skomakerveien 33
++//           3185 Skoppum, NORWAY
++
++#include "config.h"
++
++#include <cerrno>
++#include <iostream>
++
++#include <unistd.h>
++#include <torrent/exceptions.h>
++#include <torrent/event.h>
++
++#include "poll_ports.h"
++
++#ifdef USE_PORTS
++/*
++ * We should use <poll.h> here, but it seems to conflict with the
++ * <torrent/poll.h> header, so use <sys/poll.h> instead.  Since all
++ * poll.h does is include sys/poll.h, this shouldn't cause any
++ * problems.
++ */
++# include <sys/poll.h>
++# include <port.h>
++#endif
++
++namespace torrent {
++
++#ifdef USE_PORTS
++
++inline uint32_t
++PollPorts::event_mask(Event* e) {
++  return m_table[e->file_descriptor()];
++}
++
++inline void
++PollPorts::set_event_mask(Event* e, uint32_t m) {
++  m_table[e->file_descriptor()] = m;
++}
++
++inline void
++PollPorts::modify(Event* event, uint32_t mask) {
++  if (event_mask(event) == mask)
++    return;
++
++  port_dissociate(m_fd, PORT_SOURCE_FD, event->file_descriptor());
++
++  set_event_mask(event, mask);
++
++  if (mask == 0)
++    return;
++
++  if (port_associate(m_fd, PORT_SOURCE_FD, event->file_descriptor(),
++		  mask, event) == -1)
++	  throw internal_error("PollPorts::modify(...) port_associate failed");
++}
++
++PollPorts*
++PollPorts::create(int maxOpenSockets) {
++  int fd = port_create();
++
++  if (fd == -1)
++    return NULL;
++
++  return new PollPorts(fd, 1024, maxOpenSockets);
++}
++
++PollPorts::PollPorts(int fd, int maxEvents, int maxOpenSockets) :
++  m_fd(fd),
++  m_maxEvents(maxEvents),
++  m_waitingEvents(0),
++  m_events(new port_event_t[maxEvents]) {
++
++  m_table.resize(maxEvents); 
++}
++
++PollPorts::~PollPorts() {
++  m_table.clear();
++
++  ::close(m_fd);
++}
++
++int
++PollPorts::poll(int msec) {
++  timespec_t timeout;
++  timeout.tv_sec = msec / 1000;
++  timeout.tv_nsec = (msec * 1000000L) % 1000000000L;
++
++  uint_t nfds = 1;
++
++  int ret = port_getn(m_fd, m_events, m_maxEvents, &nfds, &timeout);
++
++  if (ret == -1 && errno != ETIME) {
++	  std::cerr << "error from ports, maxevents="<<m_maxEvents<<", nfds="<<nfds<<" msec="<<msec<<"\n";
++    return -1;
++  }
++
++  return m_waitingEvents = nfds;
++}
++
++// We check m_table to make sure the Event is still listening to the
++// event, so it is safe to remove Event's while in working.
++//
++// TODO: Do we want to guarantee if the Event has been removed from
++// some event but not closed, it won't call that event? Think so...
++void
++PollPorts::perform() {
++  for (port_event_t *itr = m_events, *last = m_events + m_waitingEvents; itr != last; ++itr) {
++    // Since port events are one-shot, re-add the fd before we process
++    // its events.
++
++    port_associate(m_fd, PORT_SOURCE_FD, itr->portev_object,
++        event_mask((Event *)itr->portev_user), itr->portev_user);
++
++    // Each branch must check for data.ptr != NULL to allow the socket
++    // to remove itself between the calls.
++    //
++    // TODO: Make it so that it checks that read/write is wanted, that
++    // it wasn't removed from one of them but not closed.
++
++    if (itr->portev_events & POLLERR && itr->portev_user != NULL 
++        && event_mask((Event*)itr->portev_user) & POLLERR)
++      ((Event*)itr->portev_user)->event_error();
++
++    if (itr->portev_events & POLLIN && itr->portev_user != NULL 
++        && event_mask((Event*)itr->portev_user) & POLLIN)
++      ((Event*)itr->portev_user)->event_read();
++
++    if (itr->portev_events & POLLOUT && itr->portev_user != NULL
++        && event_mask((Event*)itr->portev_user) & POLLOUT)
++      ((Event*)itr->portev_user)->event_write();
++  }
++
++  m_waitingEvents = 0;
++}
++
++uint32_t
++PollPorts::open_max() const {
++  return m_table.size();
++}
++
++void
++PollPorts::open(Event* event) {
++  if (event_mask(event) != 0)
++    throw internal_error("PollPorts::open(...) called but the file descriptor is active");
++}
++
++void
++PollPorts::close(Event* event) {
++  if (event_mask(event) != 0)
++    throw internal_error("PollPorts::close(...) called but the file descriptor is active");
++
++  for (port_event_t *itr = m_events, *last = m_events + m_waitingEvents; itr != last; ++itr)
++    if (itr->portev_user == event)
++      itr->portev_user = NULL;
++}
++
++bool
++PollPorts::in_read(Event* event) {
++  return event_mask(event) & POLLIN;
++}
++
++bool
++PollPorts::in_write(Event* event) {
++  return event_mask(event) & POLLOUT;
++}
++
++bool
++PollPorts::in_error(Event* event) {
++  return event_mask(event) & POLLERR;
++}
++
++void
++PollPorts::insert_read(Event* event) {
++  modify(event, event_mask(event) | POLLIN);
++}
++
++void
++PollPorts::insert_write(Event* event) {
++  modify(event, event_mask(event) | POLLOUT);
++}
++
++void
++PollPorts::insert_error(Event* event) {
++  modify(event, event_mask(event) | POLLERR);
++}
++
++void
++PollPorts::remove_read(Event* event) {
++  uint32_t mask = event_mask(event) & ~POLLIN;
++  modify(event, mask);
++}
++
++void
++PollPorts::remove_write(Event* event) {
++  uint32_t mask = event_mask(event) & ~POLLOUT;
++
++  modify(event, mask);
++}
++
++void
++PollPorts::remove_error(Event* event) {
++  uint32_t mask = event_mask(event) & ~POLLERR;
++
++  modify(event, mask);
++}
++
++#else // USE_PORTS
++
++PollPorts*
++PollPorts::create(int maxOpenSockets) {
++  return NULL;
++}
++
++PollPorts::~PollPorts() {
++}
++
++int
++PollPorts::poll(int msec) {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++void
++PollPorts::perform() {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++uint32_t
++PollPorts::open_max() const {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++void
++PollPorts::open(torrent::Event* event) {
++}
++
++void
++PollPorts::close(torrent::Event* event) {
++}
++
++bool
++PollPorts::in_read(torrent::Event* event) {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++bool
++PollPorts::in_write(torrent::Event* event) {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++bool
++PollPorts::in_error(torrent::Event* event) {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++void
++PollPorts::insert_read(torrent::Event* event) {
++}
++
++void
++PollPorts::insert_write(torrent::Event* event) {
++}
++
++void
++PollPorts::insert_error(torrent::Event* event) {
++}
++
++void
++PollPorts::remove_read(torrent::Event* event) {
++}
++
++void
++PollPorts::remove_write(torrent::Event* event) {
++}
++
++void
++PollPorts::remove_error(torrent::Event* event) {
++}
++
++PollPorts::PollPorts(int fd, int maxEvents, int maxOpenSockets) {
++  throw internal_error("An PollPorts function was called, but it is disabled.");
++}
++
++#endif // USE_PORTS
++
++}
+diff -urN libtorrent.orig/src/torrent/poll_ports.h libtorrent/src/torrent/poll_ports.h
+--- libtorrent.orig/src/torrent/poll_ports.h	1969-12-31 19:00:00.000000000 -0500
++++ libtorrent/src/torrent/poll_ports.h	2008-05-12 00:42:15.000000000 -0400
+@@ -0,0 +1,100 @@
++// libTorrent - BitTorrent library
++// Copyright (C) 2005-2007, 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 <[email protected]>
++//
++//           Skomakerveien 33
++//           3185 Skoppum, NORWAY
++
++#ifndef LIBTORRENT_TORRENT_POLL_PORTS_H
++#define LIBTORRENT_TORRENT_POLL_PORTS_H
++
++#include <vector>
++#include <torrent/poll.h>
++
++struct port_event;
++
++namespace torrent {
++
++class LIBTORRENT_EXPORT PollPorts : public torrent::Poll {
++public:
++  typedef std::vector<uint32_t> Table;
++
++  static PollPorts*   create(int maxOpenSockets);
++  virtual ~PollPorts();
++
++  int                 poll(int msec);
++  void                perform();
++
++  int                 file_descriptor() { return m_fd; }
++
++  virtual uint32_t    open_max() const;
++
++  // 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:
++  PollPorts(int fd, int maxEvents, int maxOpenSockets);
++
++  inline uint32_t     event_mask(Event* e);
++  inline void         set_event_mask(Event* e, uint32_t m);
++
++  inline void         modify(torrent::Event* event, uint32_t mask);
++
++  int                 m_fd;
++
++  int                 m_maxEvents;
++  int                 m_waitingEvents;
++
++  Table               m_table;
++  port_event*        m_events;
++};
++
++}
++
++#endif
--- a/patches/rtorrent-01-solaris.diff	Sat May 24 06:34:23 2008 +0000
+++ b/patches/rtorrent-01-solaris.diff	Sat May 24 09:11:53 2008 +0000
@@ -89,3 +89,15 @@
    std::memcpy(sa->sun_path, filename.c_str(), filename.size() + 1);
  
    if (!get_fd().open_local())
+diff -urN rtorrent-0.8.2.orig/src/core/curl_get.cc rtorrent-0.8.2/src/core/curl_get.cc
+--- rtorrent-0.8.2.orig/src/core/curl_get.cc	2008-05-07 08:19:11.000000000 -0400
++++ rtorrent-0.8.2/src/core/curl_get.cc	2008-05-24 04:58:48.995868197 -0400
+@@ -81,7 +81,7 @@
+   curl_easy_setopt(m_handle, CURLOPT_NOSIGNAL,       1);
+   curl_easy_setopt(m_handle, CURLOPT_FOLLOWLOCATION, 1);
+   curl_easy_setopt(m_handle, CURLOPT_MAXREDIRS,      5);
+-  curl_easy_setopt(m_handle, CURLOPT_IPRESOLVE,      CURL_IPRESOLVE_V4);
++  curl_easy_setopt(m_handle, CURLOPT_IPRESOLVE,      CURL_IPRESOLVE_V6);
+   curl_easy_setopt(m_handle, CURLOPT_ENCODING,       "");
+ 
+   m_stack->add_get(this);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/rtorrent-02-event-ports.diff	Sat May 24 09:11:53 2008 +0000
@@ -0,0 +1,820 @@
+diff -urN rtorrent-0.8.2.orig/src/core/Makefile.am rtorrent-0.8.2/src/core/Makefile.am
+--- rtorrent-0.8.2.orig/src/core/Makefile.am	2008-05-07 08:19:11.000000000 -0400
++++ rtorrent-0.8.2/src/core/Makefile.am	2008-05-24 04:58:48.995508910 -0400
+@@ -26,6 +26,8 @@
+ 	poll_manager.h \
+ 	poll_manager_epoll.cc \
+ 	poll_manager_epoll.h \
++	poll_manager_ports.cc \
++	poll_manager_ports.h \
+ 	poll_manager_kqueue.cc \
+ 	poll_manager_kqueue.h \
+ 	poll_manager_select.cc \
+diff -urN rtorrent-0.8.2.orig/src/core/Makefile.am.orig rtorrent-0.8.2/src/core/Makefile.am.orig
+--- rtorrent-0.8.2.orig/src/core/Makefile.am.orig	1969-12-31 19:00:00.000000000 -0500
++++ rtorrent-0.8.2/src/core/Makefile.am.orig	2008-05-07 08:19:11.000000000 -0400
+@@ -0,0 +1,40 @@
++noinst_LIBRARIES = libsub_core.a
++
++libsub_core_a_SOURCES = \
++	curl_get.cc \
++	curl_get.h \
++	curl_stack.cc \
++	curl_stack.h \
++	dht_manager.cc \
++	dht_manager.h \
++	download.cc \
++	download.h \
++	download_factory.cc \
++	download_factory.h \
++	download_list.cc \
++	download_list.h \
++	download_slot_map.h \
++	download_store.cc \
++	download_store.h \
++	http_queue.cc \
++	http_queue.h \
++	log.cc \
++	log.h \
++	manager.cc \
++	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 \
++	scheduler.cc \
++	scheduler.h \
++	view.cc \
++	view.h \
++	view_manager.cc \
++	view_manager.h
++
++INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
+diff -urN rtorrent-0.8.2.orig/src/core/manager.cc rtorrent-0.8.2/src/core/manager.cc
+--- rtorrent-0.8.2.orig/src/core/manager.cc	2008-05-07 08:19:11.000000000 -0400
++++ rtorrent-0.8.2/src/core/manager.cc	2008-05-24 04:58:48.996596707 -0400
+@@ -69,6 +69,7 @@
+ #include "manager.h"
+ #include "poll_manager_epoll.h"
+ #include "poll_manager_kqueue.h"
++#include "poll_manager_ports.h"
+ #include "poll_manager_select.h"
+ #include "view.h"
+ 
+@@ -189,6 +190,9 @@
+   if ((m_pollManager = PollManagerEPoll::create(sysconf(_SC_OPEN_MAX))) != NULL)
+     m_logImportant.push_front("Using 'epoll' based polling.");
+ 
++  else if ((m_pollManager = PollManagerPorts::create(sysconf(_SC_OPEN_MAX))) != NULL)
++    m_logImportant.push_front("Using 'ports' based polling.");
++
+   else if ((m_pollManager = PollManagerKQueue::create(sysconf(_SC_OPEN_MAX))) != NULL)
+     m_logImportant.push_front("Using 'kqueue' based polling.");
+ 
+diff -urN rtorrent-0.8.2.orig/src/core/manager.cc.orig rtorrent-0.8.2/src/core/manager.cc.orig
+--- rtorrent-0.8.2.orig/src/core/manager.cc.orig	1969-12-31 19:00:00.000000000 -0500
++++ rtorrent-0.8.2/src/core/manager.cc.orig	2008-05-07 08:19:11.000000000 -0400
+@@ -0,0 +1,550 @@
++// rTorrent - BitTorrent client
++// Copyright (C) 2005-2007, 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 <[email protected]>
++//
++//           Skomakerveien 33
++//           3185 Skoppum, NORWAY
++
++#include "config.h"
++
++#include <cstdio>
++#include <cstring>
++#include <fstream>
++#include <unistd.h>
++#include <sys/select.h>
++#include <rak/address_info.h>
++#include <rak/error_number.h>
++#include <rak/regex.h>
++#include <rak/path.h>
++#include <rak/string_manip.h>
++#include <sigc++/adaptors/bind.h>
++#include <sigc++/adaptors/hide.h>
++#include <torrent/object.h>
++#include <torrent/connection_manager.h>
++#include <torrent/error.h>
++#include <torrent/exceptions.h>
++#include <torrent/resume.h>
++#include <torrent/tracker_list.h>
++
++#include "rpc/parse_commands.h"
++#include "utils/directory.h"
++#include "utils/file_status_cache.h"
++
++#include "globals.h"
++#include "curl_get.h"
++#include "control.h"
++#include "download.h"
++#include "download_factory.h"
++#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 "view.h"
++
++namespace core {
++
++void
++receive_tracker_dump(const std::string& url, const char* data, size_t size) {
++  const std::string& filename = rpc::call_command_string("get_tracker_dump");
++
++  if (filename.empty())
++    return;
++
++  std::fstream fstr(filename.c_str(), std::ios::out | std::ios::app);
++
++  if (!fstr.is_open())
++    return;
++
++  fstr << "url: " << url << std::endl << "---" << std::endl;
++  fstr.write(data, size);
++  fstr << std::endl <<"---" << std::endl;
++}
++
++void
++Manager::handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash) {
++  if (!rpc::call_command_value("get_handshake_log"))
++    return;
++  
++  std::string peer;
++  std::string download;
++
++  const rak::socket_address* socketAddress = rak::socket_address::cast_from(sa);
++
++  if (socketAddress->is_valid()) {
++    char port[6];
++    snprintf(port, sizeof(port), "%d", socketAddress->port());
++    peer = socketAddress->address_str() + ":" + port;
++  } else {
++    peer = "(unknown)";
++  }
++
++//   torrent::Download d = torrent::download_find(hash);
++
++//   if (d.is_valid())
++//     download = ": " + d.name();
++//   else
++    download = "";
++
++  switch (msg) {
++  case torrent::ConnectionManager::handshake_incoming:
++    m_logComplete.push_front("Incoming connection from " + peer + download);
++    break;
++  case torrent::ConnectionManager::handshake_outgoing:
++    m_logComplete.push_front("Outgoing connection to " + peer + download);
++    break;
++  case torrent::ConnectionManager::handshake_outgoing_encrypted:
++    m_logComplete.push_front("Outgoing encrypted connection to " + peer + download);
++    break;
++  case torrent::ConnectionManager::handshake_outgoing_proxy:
++    m_logComplete.push_front("Outgoing proxy connection to " + peer + download);
++    break;
++  case torrent::ConnectionManager::handshake_success:
++    m_logComplete.push_front("Successful handshake: " + peer + download);
++    break;
++  case torrent::ConnectionManager::handshake_dropped:
++    m_logComplete.push_front("Dropped handshake: " + peer + " - " + torrent::strerror(err) + download);
++    break;
++  case torrent::ConnectionManager::handshake_failed:
++    m_logComplete.push_front("Handshake failed: " + peer + " - " + torrent::strerror(err) + download);
++    break;
++  case torrent::ConnectionManager::handshake_retry_plaintext:
++    m_logComplete.push_front("Trying again without encryption: " + peer + download);
++    break;
++  case torrent::ConnectionManager::handshake_retry_encrypted:
++    m_logComplete.push_front("Trying again encrypted: " + peer + download);
++    break;
++  default:
++    m_logComplete.push_front("Unknown handshake message for " + peer + download);
++    break;
++  }
++}
++
++void
++Manager::push_log(const char* msg) {
++  m_logImportant.push_front(msg);
++  m_logComplete.push_front(msg);
++}
++
++Manager::Manager() :
++  m_hashingView(NULL),
++
++  m_pollManager(NULL) {
++
++  m_downloadStore   = new DownloadStore();
++  m_downloadList    = new DownloadList();
++  m_fileStatusCache = new FileStatusCache();
++  m_httpQueue       = new HttpQueue();
++}
++
++Manager::~Manager() {
++  delete m_downloadList;
++
++  delete m_downloadStore;
++  delete m_httpQueue;
++  delete m_fileStatusCache;
++}
++
++void
++Manager::set_hashing_view(View* v) {
++  if (v == NULL || m_hashingView != NULL)
++    throw torrent::internal_error("Manager::set_hashing_view(...) received NULL or is already set.");
++
++  m_hashingView = v;
++  v->signal_changed().connect(sigc::mem_fun(this, &Manager::receive_hashing_changed));
++}
++
++void
++Manager::initialize_first() {
++  if ((m_pollManager = PollManagerEPoll::create(sysconf(_SC_OPEN_MAX))) != NULL)
++    m_logImportant.push_front("Using 'epoll' based polling.");
++
++  else if ((m_pollManager = PollManagerKQueue::create(sysconf(_SC_OPEN_MAX))) != NULL)
++    m_logImportant.push_front("Using 'kqueue' based polling.");
++
++  else if ((m_pollManager = PollManagerSelect::create(sysconf(_SC_OPEN_MAX))) != NULL)
++    m_logImportant.push_front("Using 'select' based polling.");
++
++  else
++    throw std::runtime_error("Could not create any PollManager.");
++
++  // Need to initialize this before parseing options.
++  torrent::initialize(m_pollManager->get_torrent_poll());
++}
++
++// Most of this should be possible to move out.
++void
++Manager::initialize_second() {
++  torrent::Http::set_factory(sigc::mem_fun(m_pollManager->get_http_stack(), &CurlStack::new_object));
++  m_httpQueue->slot_factory(sigc::mem_fun(m_pollManager->get_http_stack(), &CurlStack::new_object));
++
++  CurlStack::global_init();
++
++  // Register slots to be called when a download is inserted/erased,
++  // opened or closed.
++  m_downloadList->slot_map_insert()["1_connect_logs"] = "d.initialize_logs=";
++  m_downloadList->slot_map_erase()["9_delete_tied"]   = "d.delete_tied=";
++
++  torrent::connection_manager()->set_signal_handshake_log(sigc::mem_fun(this, &Manager::handshake_log));
++}
++
++void
++Manager::cleanup() {
++  // Need to disconnect log signals? Not really since we won't receive
++  // any more.
++
++  m_downloadList->clear();
++
++  // When we implement asynchronous DNS lookups, we need to cancel them
++  // here before the torrent::* objects are deleted.
++
++  torrent::cleanup();
++  CurlStack::global_cleanup();
++
++  delete m_pollManager;
++}
++
++void
++Manager::shutdown(bool force) {
++  if (!force)
++    std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::pause_default), m_downloadList));
++  else
++    std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::close_quick), m_downloadList));
++}
++
++void
++Manager::listen_open() {
++  // This stuff really should be moved outside of manager, make it
++  // part of the init script.
++  if (!rpc::call_command_value("get_port_open"))
++    return;
++
++  int portFirst, portLast;
++  torrent::Object portRange = rpc::call_command_void("get_port_range");
++
++  if (portRange.is_string()) {
++    if (std::sscanf(portRange.as_string().c_str(), "%i-%i", &portFirst, &portLast) != 2)
++      throw torrent::input_error("Invalid port_range argument.");
++    
++//   } else if (portRange.is_list()) {
++
++  } else {
++    throw torrent::input_error("Invalid port_range argument.");
++  }
++
++  if (portFirst > portLast || portLast >= (1 << 16))
++    throw torrent::input_error("Invalid port range.");
++
++  if (rpc::call_command_value("get_port_random")) {
++    int boundary = portFirst + random() % (portLast - portFirst + 1);
++
++    if (torrent::connection_manager()->listen_open(boundary, portLast) ||
++        torrent::connection_manager()->listen_open(portFirst, boundary))
++      return;
++
++  } else {
++    if (torrent::connection_manager()->listen_open(portFirst, portLast))
++      return;
++  }
++
++  throw torrent::input_error("Could not open/bind port for listening: " + std::string(rak::error_number::current().c_str()));
++}
++
++std::string
++Manager::bind_address() const {
++  return rak::socket_address::cast_from(torrent::connection_manager()->bind_address())->address_str();
++}
++
++void
++Manager::set_bind_address(const std::string& addr) {
++  int err;
++  rak::address_info* ai;
++
++  if ((err = rak::address_info::get_address_info(addr.c_str(), PF_INET, SOCK_STREAM, &ai)) != 0)
++    throw torrent::input_error("Could not set bind address: " + std::string(rak::address_info::strerror(err)) + ".");
++  
++  try {
++
++    if (torrent::connection_manager()->listen_port() != 0) {
++      torrent::connection_manager()->listen_close();
++      torrent::connection_manager()->set_bind_address(ai->address()->c_sockaddr());
++      listen_open();
++
++    } else {
++      torrent::connection_manager()->set_bind_address(ai->address()->c_sockaddr());
++    }
++
++    m_pollManager->get_http_stack()->set_bind_address(!ai->address()->is_address_any() ? ai->address()->address_str() : std::string());
++
++    rak::address_info::free_address_info(ai);
++
++  } catch (torrent::input_error& e) {
++    rak::address_info::free_address_info(ai);
++    throw e;
++  }
++}
++
++std::string
++Manager::local_address() const {
++  return rak::socket_address::cast_from(torrent::connection_manager()->local_address())->address_str();
++}
++
++void
++Manager::set_local_address(const std::string& addr) {
++  int err;
++  rak::address_info* ai;
++
++  if ((err = rak::address_info::get_address_info(addr.c_str(), PF_INET, SOCK_STREAM, &ai)) != 0)
++    throw torrent::input_error("Could not set local address: " + std::string(rak::address_info::strerror(err)) + ".");
++  
++  try {
++
++    torrent::connection_manager()->set_local_address(ai->address()->c_sockaddr());
++    rak::address_info::free_address_info(ai);
++
++  } catch (torrent::input_error& e) {
++    rak::address_info::free_address_info(ai);
++    throw e;
++  }
++}
++
++std::string
++Manager::proxy_address() const {
++  return rak::socket_address::cast_from(torrent::connection_manager()->proxy_address())->address_str();
++}
++
++void
++Manager::set_proxy_address(const std::string& addr) {
++  int port;
++  rak::address_info* ai;
++
++  char buf[addr.length() + 1];
++
++  int err = std::sscanf(addr.c_str(), "%[^:]:%i", buf, &port);
++
++  if (err <= 0)
++    throw torrent::input_error("Could not parse proxy address.");
++
++  if (err == 1)
++    port = 80;
++
++  if ((err = rak::address_info::get_address_info(buf, PF_INET, SOCK_STREAM, &ai)) != 0)
++    throw torrent::input_error("Could not set proxy address: " + std::string(rak::address_info::strerror(err)) + ".");
++  
++  try {
++
++    ai->address()->set_port(port);
++    torrent::connection_manager()->set_proxy_address(ai->address()->c_sockaddr());
++    
++    rak::address_info::free_address_info(ai);
++
++  } catch (torrent::input_error& e) {
++    rak::address_info::free_address_info(ai);
++    throw e;
++  }
++}
++
++void
++Manager::receive_http_failed(std::string msg) {
++  m_logImportant.push_front("Http download error: \"" + msg + "\"");
++  m_logComplete.push_front("Http download error: \"" + msg + "\"");
++}
++
++void
++Manager::try_create_download(const std::string& uri, int flags, const command_list_type& commands) {
++  // If the path was attempted loaded before, skip it.
++  if (!(flags & create_raw_data) &&
++      !is_network_uri(uri) &&
++      !file_status_cache()->insert(uri, 0))
++    return;
++
++  // Adding download.
++  DownloadFactory* f = new DownloadFactory(this);
++
++  f->variables()["tied_to_file"] = (int64_t)(bool)(flags & create_tied);
++  f->commands().insert(f->commands().end(), commands.begin(), commands.end());
++
++  f->set_start(flags & create_start);
++  f->set_print_log(!(flags & create_quiet));
++  f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func<core::DownloadFactory>), f));
++
++  if (flags & create_raw_data)
++    f->load_raw_data(uri);
++  else
++    f->load(uri);
++
++  f->commit();
++}
++
++utils::Directory
++path_expand_transform(std::string path, const utils::directory_entry& entry) {
++  return path + entry.d_name;
++}
++
++// Move this somewhere better.
++void
++path_expand(std::vector<std::string>* paths, const std::string& pattern) {
++  std::vector<utils::Directory> currentCache;
++  std::vector<utils::Directory> nextCache;
++
++  rak::split_iterator_t<std::string> first = rak::split_iterator(pattern, '/');
++  rak::split_iterator_t<std::string> last  = rak::split_iterator(pattern);
++    
++  if (first == last)
++    return;
++
++  // Check for initial '/' that indicates the root.
++  if ((*first).empty()) {
++    currentCache.push_back(utils::Directory("/"));
++    ++first;
++  } else if (rak::trim(*first) == "~") {
++    currentCache.push_back(utils::Directory("~"));
++    ++first;
++  } else {
++    currentCache.push_back(utils::Directory("."));
++  }
++
++  // Might be an idea to use depth-first search instead.
++
++  for (; first != last; ++first) {
++    rak::regex r(*first);
++
++    if (r.pattern().empty())
++      continue;
++
++    // Special case for ".."?
++
++    for (std::vector<utils::Directory>::iterator itr = currentCache.begin(); itr != currentCache.end(); ++itr) {
++      // Only include filenames starting with '.' if the pattern
++      // starts with the same.
++      itr->update((r.pattern()[0] != '.') ? utils::Directory::update_hide_dot : 0);
++      itr->erase(std::remove_if(itr->begin(), itr->end(), rak::on(rak::mem_ref(&utils::directory_entry::d_name), std::not1(r))), itr->end());
++
++      std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), rak::bind1st(std::ptr_fun(&path_expand_transform), itr->path() + "/"));
++    }
++
++    currentCache.clear();
++    currentCache.swap(nextCache);
++  }
++
++  std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::path));
++}
++
++bool
++manager_equal_tied(const std::string& path, Download* download) {
++  return path == rpc::call_command_string("d.get_tied_to_file", rpc::make_target(download));
++}
++
++void
++Manager::try_create_download_expand(const std::string& uri, int flags, command_list_type commands) {
++  if (flags & create_raw_data) {
++    try_create_download(uri, flags, commands);
++    return;
++  }
++
++  std::vector<std::string> paths;
++  paths.reserve(256);
++
++  path_expand(&paths, uri);
++
++  if (!paths.empty())
++    for (std::vector<std::string>::iterator itr = paths.begin(); itr != paths.end(); ++itr)
++      try_create_download(*itr, flags, commands);
++
++  else
++    try_create_download(uri, flags, commands);
++}
++
++// DownloadList's hashing related functions don't actually start the
++// hashing, it only reacts to events. This functions checks the
++// hashing view and starts hashing if nessesary.
++void
++Manager::receive_hashing_changed() {
++  bool foundHashing = std::find_if(m_hashingView->begin_visible(), m_hashingView->end_visible(),
++                                   std::mem_fun(&Download::is_hash_checking)) != m_hashingView->end_visible();
++  
++  // Try quick hashing all those with hashing == initial, set them to
++  // something else when failed.
++  for (View::iterator itr = m_hashingView->begin_visible(), last = m_hashingView->end_visible(); itr != last; ++itr) {
++    if ((*itr)->is_hash_checked())
++      throw torrent::internal_error("core::Manager::receive_hashing_changed() (*itr)->is_hash_checked().");
++  
++    if ((*itr)->is_hash_checking() || (*itr)->is_hash_failed())
++      continue;
++
++    bool tryQuick =
++      rpc::call_command_value("d.get_hashing", rpc::make_target(*itr)) == Download::variable_hashing_initial &&
++      (*itr)->download()->file_list()->bitfield()->empty();
++
++    if (!tryQuick && foundHashing)
++      continue;
++
++    try {
++      m_downloadList->open_throw(*itr);
++
++      // Since the bitfield is allocated on loading of resume load or
++      // hash start, and unallocated on close, we know that if it it
++      // not empty then we have already loaded any existing resume
++      // data.
++      if ((*itr)->download()->file_list()->bitfield()->empty())
++        torrent::resume_load_progress(*(*itr)->download(), (*itr)->download()->bencode()->get_key("libtorrent_resume"));
++
++      if (tryQuick) {
++        if ((*itr)->download()->hash_check(true))
++          continue;
++
++        (*itr)->download()->hash_stop();
++
++        if (foundHashing) {
++          rpc::call_command_set_value("d.set_hashing", Download::variable_hashing_rehash, rpc::make_target(*itr));
++          continue;
++        }
++      }
++
++      (*itr)->download()->hash_check(false);
++      foundHashing = true;
++
++    } catch (torrent::local_error& e) {
++      if (tryQuick) {
++        // Make sure we don't repeat the quick hashing.
++        rpc::call_command_set_value("d.set_hashing", Download::variable_hashing_rehash, rpc::make_target(*itr));
++
++      } else {
++        (*itr)->set_hash_failed(true);
++        push_log(e.what());
++      }
++    }
++  }
++}
++
++}
+diff -urN rtorrent-0.8.2.orig/src/core/poll_manager_ports.cc rtorrent-0.8.2/src/core/poll_manager_ports.cc
+--- rtorrent-0.8.2.orig/src/core/poll_manager_ports.cc	1969-12-31 19:00:00.000000000 -0500
++++ rtorrent-0.8.2/src/core/poll_manager_ports.cc	2008-05-10 19:04:07.000000000 -0400
+@@ -0,0 +1,118 @@
++// rTorrent - BitTorrent client
++// Copyright (C) 2005-2007, 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 <[email protected]>
++//
++//           Skomakerveien 33
++//           3185 Skoppum, NORWAY
++
++#include "config.h"
++
++#include <cstring>
++#include <iostream>
++#include <stdexcept>
++#include <unistd.h>
++#include <sys/time.h>
++#include <torrent/poll_ports.h>
++#include <torrent/torrent.h>
++
++#include "poll_manager_ports.h"
++
++namespace core {
++
++PollManagerPorts*
++PollManagerPorts::create(int maxOpenSockets) {
++  torrent::PollPorts* p = torrent::PollPorts::create(maxOpenSockets);
++
++  if (p == NULL)
++    return NULL;
++  else
++    return new PollManagerPorts(p);
++}
++
++PollManagerPorts::~PollManagerPorts() {
++}
++
++void
++PollManagerPorts::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;
++
++  if (!m_httpStack.empty()) {
++    // When we're using libcurl we need to use select, but as this is
++    // inefficient we try avoiding it whenever possible.
++#if defined USE_VARIABLE_FDSET
++    std::memset(m_readSet, 0, m_setSize);
++    std::memset(m_writeSet, 0, m_setSize);
++    std::memset(m_errorSet, 0, m_setSize);
++#else
++    FD_ZERO(m_readSet);
++    FD_ZERO(m_writeSet);
++    FD_ZERO(m_errorSet);
++#endif    
++    FD_SET(static_cast<torrent::PollPorts*>(m_poll)->file_descriptor(), m_readSet);
++
++    unsigned int maxFd = std::max((unsigned int)static_cast<torrent::PollPorts*>(m_poll)->file_descriptor(),
++                                  m_httpStack.fdset(m_readSet, m_writeSet, m_errorSet));
++
++    timeval t = timeout.tval();
++
++    if (select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t) == -1) {
++	    std::cerr << "error from select\n";
++      return check_error();
++    }
++    m_httpStack.perform();
++
++    if (!FD_ISSET(static_cast<torrent::PollPorts*>(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();
++      return;
++    }
++
++    // Clear the timeout since we've already used it in the select call.
++    timeout = rak::timer();
++  }
++
++  // Yes, below is how much code really *should* have been in this
++  // function. ;)
++
++  if (static_cast<torrent::PollPorts*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1) {
++	  std::cerr << "error from ports poll\n";
++    return check_error();
++  }
++  torrent::perform();
++  static_cast<torrent::PollPorts*>(m_poll)->perform();
++}
++
++}
+diff -urN rtorrent-0.8.2.orig/src/core/poll_manager_ports.h rtorrent-0.8.2/src/core/poll_manager_ports.h
+--- rtorrent-0.8.2.orig/src/core/poll_manager_ports.h	1969-12-31 19:00:00.000000000 -0500
++++ rtorrent-0.8.2/src/core/poll_manager_ports.h	2008-05-10 19:04:07.000000000 -0400
+@@ -0,0 +1,63 @@
++// rTorrent - BitTorrent client
++// Copyright (C) 2005-2007, 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 <[email protected]>
++//
++//           Skomakerveien 33
++//           3185 Skoppum, NORWAY
++
++#ifndef RTORRENT_CORE_POLL_MANAGER_PORTS_H
++#define RTORRENT_CORE_POLL_MANAGER_PORTS_H
++
++#include "poll_manager.h"
++
++namespace torrent {
++  class PollPorts;
++}
++
++namespace core {
++
++class PollManagerPorts : public PollManager {
++public:
++  static PollManagerPorts* create(int maxOpenSockets);
++  ~PollManagerPorts();
++
++  torrent::Poll*      get_torrent_poll();
++
++  void                poll(rak::timer timeout);
++
++private:
++  PollManagerPorts(torrent::Poll* p) : PollManager(p) {}
++};
++
++}
++
++#endif