1152
|
1 |
diff -urN rtorrent-0.8.2.orig/src/core/Makefile.am rtorrent-0.8.2/src/core/Makefile.am
|
|
2 |
--- rtorrent-0.8.2.orig/src/core/Makefile.am 2008-05-07 08:19:11.000000000 -0400
|
|
3 |
+++ rtorrent-0.8.2/src/core/Makefile.am 2008-05-24 04:58:48.995508910 -0400
|
|
4 |
@@ -26,6 +26,8 @@
|
|
5 |
poll_manager.h \
|
|
6 |
poll_manager_epoll.cc \
|
|
7 |
poll_manager_epoll.h \
|
|
8 |
+ poll_manager_ports.cc \
|
|
9 |
+ poll_manager_ports.h \
|
|
10 |
poll_manager_kqueue.cc \
|
|
11 |
poll_manager_kqueue.h \
|
|
12 |
poll_manager_select.cc \
|
|
13 |
diff -urN rtorrent-0.8.2.orig/src/core/manager.cc rtorrent-0.8.2/src/core/manager.cc
|
|
14 |
--- rtorrent-0.8.2.orig/src/core/manager.cc 2008-05-07 08:19:11.000000000 -0400
|
|
15 |
+++ rtorrent-0.8.2/src/core/manager.cc 2008-05-24 04:58:48.996596707 -0400
|
|
16 |
@@ -69,6 +69,7 @@
|
|
17 |
#include "manager.h"
|
|
18 |
#include "poll_manager_epoll.h"
|
|
19 |
#include "poll_manager_kqueue.h"
|
|
20 |
+#include "poll_manager_ports.h"
|
|
21 |
#include "poll_manager_select.h"
|
|
22 |
#include "view.h"
|
|
23 |
|
|
24 |
@@ -189,6 +190,9 @@
|
|
25 |
if ((m_pollManager = PollManagerEPoll::create(sysconf(_SC_OPEN_MAX))) != NULL)
|
|
26 |
m_logImportant.push_front("Using 'epoll' based polling.");
|
|
27 |
|
|
28 |
+ else if ((m_pollManager = PollManagerPorts::create(sysconf(_SC_OPEN_MAX))) != NULL)
|
|
29 |
+ m_logImportant.push_front("Using 'ports' based polling.");
|
|
30 |
+
|
|
31 |
else if ((m_pollManager = PollManagerKQueue::create(sysconf(_SC_OPEN_MAX))) != NULL)
|
|
32 |
m_logImportant.push_front("Using 'kqueue' based polling.");
|
|
33 |
|
|
34 |
diff -urN rtorrent-0.8.2.orig/src/core/poll_manager_ports.cc rtorrent-0.8.2/src/core/poll_manager_ports.cc
|
|
35 |
--- rtorrent-0.8.2.orig/src/core/poll_manager_ports.cc 1969-12-31 19:00:00.000000000 -0500
|
|
36 |
+++ rtorrent-0.8.2/src/core/poll_manager_ports.cc 2008-05-10 19:04:07.000000000 -0400
|
|
37 |
@@ -0,0 +1,118 @@
|
|
38 |
+// rTorrent - BitTorrent client
|
|
39 |
+// Copyright (C) 2005-2007, Jari Sundell
|
|
40 |
+//
|
|
41 |
+// This program is free software; you can redistribute it and/or modify
|
|
42 |
+// it under the terms of the GNU General Public License as published by
|
|
43 |
+// the Free Software Foundation; either version 2 of the License, or
|
|
44 |
+// (at your option) any later version.
|
|
45 |
+//
|
|
46 |
+// This program is distributed in the hope that it will be useful,
|
|
47 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
48 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
49 |
+// GNU General Public License for more details.
|
|
50 |
+//
|
|
51 |
+// You should have received a copy of the GNU General Public License
|
|
52 |
+// along with this program; if not, write to the Free Software
|
|
53 |
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
54 |
+//
|
|
55 |
+// In addition, as a special exception, the copyright holders give
|
|
56 |
+// permission to link the code of portions of this program with the
|
|
57 |
+// OpenSSL library under certain conditions as described in each
|
|
58 |
+// individual source file, and distribute linked combinations
|
|
59 |
+// including the two.
|
|
60 |
+//
|
|
61 |
+// You must obey the GNU General Public License in all respects for
|
|
62 |
+// all of the code used other than OpenSSL. If you modify file(s)
|
|
63 |
+// with this exception, you may extend this exception to your version
|
|
64 |
+// of the file(s), but you are not obligated to do so. If you do not
|
|
65 |
+// wish to do so, delete this exception statement from your version.
|
|
66 |
+// If you delete this exception statement from all source files in the
|
|
67 |
+// program, then also delete it here.
|
|
68 |
+//
|
|
69 |
+// Contact: Jari Sundell <[email protected]>
|
|
70 |
+//
|
|
71 |
+// Skomakerveien 33
|
|
72 |
+// 3185 Skoppum, NORWAY
|
|
73 |
+
|
|
74 |
+#include "config.h"
|
|
75 |
+
|
|
76 |
+#include <cstring>
|
|
77 |
+#include <iostream>
|
|
78 |
+#include <stdexcept>
|
|
79 |
+#include <unistd.h>
|
|
80 |
+#include <sys/time.h>
|
|
81 |
+#include <torrent/poll_ports.h>
|
|
82 |
+#include <torrent/torrent.h>
|
|
83 |
+
|
|
84 |
+#include "poll_manager_ports.h"
|
|
85 |
+
|
|
86 |
+namespace core {
|
|
87 |
+
|
|
88 |
+PollManagerPorts*
|
|
89 |
+PollManagerPorts::create(int maxOpenSockets) {
|
|
90 |
+ torrent::PollPorts* p = torrent::PollPorts::create(maxOpenSockets);
|
|
91 |
+
|
|
92 |
+ if (p == NULL)
|
|
93 |
+ return NULL;
|
|
94 |
+ else
|
|
95 |
+ return new PollManagerPorts(p);
|
|
96 |
+}
|
|
97 |
+
|
|
98 |
+PollManagerPorts::~PollManagerPorts() {
|
|
99 |
+}
|
|
100 |
+
|
|
101 |
+void
|
|
102 |
+PollManagerPorts::poll(rak::timer timeout) {
|
|
103 |
+ // Add 1ms to ensure we don't idle loop due to the lack of
|
|
104 |
+ // resolution.
|
|
105 |
+ torrent::perform();
|
|
106 |
+ timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
107 |
+
|
|
108 |
+ if (!m_httpStack.empty()) {
|
|
109 |
+ // When we're using libcurl we need to use select, but as this is
|
|
110 |
+ // inefficient we try avoiding it whenever possible.
|
|
111 |
+#if defined USE_VARIABLE_FDSET
|
|
112 |
+ std::memset(m_readSet, 0, m_setSize);
|
|
113 |
+ std::memset(m_writeSet, 0, m_setSize);
|
|
114 |
+ std::memset(m_errorSet, 0, m_setSize);
|
|
115 |
+#else
|
|
116 |
+ FD_ZERO(m_readSet);
|
|
117 |
+ FD_ZERO(m_writeSet);
|
|
118 |
+ FD_ZERO(m_errorSet);
|
|
119 |
+#endif
|
|
120 |
+ FD_SET(static_cast<torrent::PollPorts*>(m_poll)->file_descriptor(), m_readSet);
|
|
121 |
+
|
|
122 |
+ unsigned int maxFd = std::max((unsigned int)static_cast<torrent::PollPorts*>(m_poll)->file_descriptor(),
|
|
123 |
+ m_httpStack.fdset(m_readSet, m_writeSet, m_errorSet));
|
|
124 |
+
|
|
125 |
+ timeval t = timeout.tval();
|
|
126 |
+
|
|
127 |
+ if (select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t) == -1) {
|
|
128 |
+ std::cerr << "error from select\n";
|
|
129 |
+ return check_error();
|
|
130 |
+ }
|
|
131 |
+ m_httpStack.perform();
|
|
132 |
+
|
|
133 |
+ if (!FD_ISSET(static_cast<torrent::PollPorts*>(m_poll)->file_descriptor(), m_readSet)) {
|
|
134 |
+ // Need to call perform here so that scheduled task get done
|
|
135 |
+ // even if there's no socket events outside of the http stuff.
|
|
136 |
+ torrent::perform();
|
|
137 |
+ return;
|
|
138 |
+ }
|
|
139 |
+
|
|
140 |
+ // Clear the timeout since we've already used it in the select call.
|
|
141 |
+ timeout = rak::timer();
|
|
142 |
+ }
|
|
143 |
+
|
|
144 |
+ // Yes, below is how much code really *should* have been in this
|
|
145 |
+ // function. ;)
|
|
146 |
+
|
|
147 |
+ if (static_cast<torrent::PollPorts*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1) {
|
|
148 |
+ std::cerr << "error from ports poll\n";
|
|
149 |
+ return check_error();
|
|
150 |
+ }
|
|
151 |
+ torrent::perform();
|
|
152 |
+ static_cast<torrent::PollPorts*>(m_poll)->perform();
|
|
153 |
+}
|
|
154 |
+
|
|
155 |
+}
|
|
156 |
diff -urN rtorrent-0.8.2.orig/src/core/poll_manager_ports.h rtorrent-0.8.2/src/core/poll_manager_ports.h
|
|
157 |
--- rtorrent-0.8.2.orig/src/core/poll_manager_ports.h 1969-12-31 19:00:00.000000000 -0500
|
|
158 |
+++ rtorrent-0.8.2/src/core/poll_manager_ports.h 2008-05-10 19:04:07.000000000 -0400
|
|
159 |
@@ -0,0 +1,63 @@
|
|
160 |
+// rTorrent - BitTorrent client
|
|
161 |
+// Copyright (C) 2005-2007, Jari Sundell
|
|
162 |
+//
|
|
163 |
+// This program is free software; you can redistribute it and/or modify
|
|
164 |
+// it under the terms of the GNU General Public License as published by
|
|
165 |
+// the Free Software Foundation; either version 2 of the License, or
|
|
166 |
+// (at your option) any later version.
|
|
167 |
+//
|
|
168 |
+// This program is distributed in the hope that it will be useful,
|
|
169 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
170 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
171 |
+// GNU General Public License for more details.
|
|
172 |
+//
|
|
173 |
+// You should have received a copy of the GNU General Public License
|
|
174 |
+// along with this program; if not, write to the Free Software
|
|
175 |
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
176 |
+//
|
|
177 |
+// In addition, as a special exception, the copyright holders give
|
|
178 |
+// permission to link the code of portions of this program with the
|
|
179 |
+// OpenSSL library under certain conditions as described in each
|
|
180 |
+// individual source file, and distribute linked combinations
|
|
181 |
+// including the two.
|
|
182 |
+//
|
|
183 |
+// You must obey the GNU General Public License in all respects for
|
|
184 |
+// all of the code used other than OpenSSL. If you modify file(s)
|
|
185 |
+// with this exception, you may extend this exception to your version
|
|
186 |
+// of the file(s), but you are not obligated to do so. If you do not
|
|
187 |
+// wish to do so, delete this exception statement from your version.
|
|
188 |
+// If you delete this exception statement from all source files in the
|
|
189 |
+// program, then also delete it here.
|
|
190 |
+//
|
|
191 |
+// Contact: Jari Sundell <[email protected]>
|
|
192 |
+//
|
|
193 |
+// Skomakerveien 33
|
|
194 |
+// 3185 Skoppum, NORWAY
|
|
195 |
+
|
|
196 |
+#ifndef RTORRENT_CORE_POLL_MANAGER_PORTS_H
|
|
197 |
+#define RTORRENT_CORE_POLL_MANAGER_PORTS_H
|
|
198 |
+
|
|
199 |
+#include "poll_manager.h"
|
|
200 |
+
|
|
201 |
+namespace torrent {
|
|
202 |
+ class PollPorts;
|
|
203 |
+}
|
|
204 |
+
|
|
205 |
+namespace core {
|
|
206 |
+
|
|
207 |
+class PollManagerPorts : public PollManager {
|
|
208 |
+public:
|
|
209 |
+ static PollManagerPorts* create(int maxOpenSockets);
|
|
210 |
+ ~PollManagerPorts();
|
|
211 |
+
|
|
212 |
+ torrent::Poll* get_torrent_poll();
|
|
213 |
+
|
|
214 |
+ void poll(rak::timer timeout);
|
|
215 |
+
|
|
216 |
+private:
|
|
217 |
+ PollManagerPorts(torrent::Poll* p) : PollManager(p) {}
|
|
218 |
+};
|
|
219 |
+
|
|
220 |
+}
|
|
221 |
+
|
|
222 |
+#endif
|