* Automagically set the max open sockets and files to resonable values

according to sysconf(_SC_OPEN_MAX).

* Added timeout to torrent::TrackerHttp so connections that are left
open, but with no data being transmitted get closed after a resonable
time.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@524 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-08-12 16:05:54 +00:00
parent 202ed7928b
commit 407f3383f0
7 changed files with 39 additions and 47 deletions
-5
View File
@@ -95,11 +95,6 @@ Manager::initialize_second() {
CurlStack::global_init();
listen_open();
if (torrent::get_max_open_files() + torrent::get_max_open_sockets() + 32 > m_pollManager->max_open_sockets()) {
m_logImportant.push_front("Warning: Max open sockets and files exceeds poll manager's max open sockets");
m_logComplete.push_front("Warning: Max open sockets and files exceeds poll manager's max open sockets");
}
// Register slots to be called when a download is inserted/erased,
// opened or closed.
m_downloadList.slot_map_insert()["0_initialize_bencode"] = sigc::mem_fun(*this, &Manager::initialize_bencode);
+2 -2
View File
@@ -50,12 +50,12 @@ PollManager::PollManager(torrent::Poll* poll) :
throw std::logic_error("PollManager::PollManager(...) received poll == NULL");
#if defined USE_VARIABLE_FDSET
m_setSize = m_poll->max_open_sockets() / 8;
m_setSize = m_poll->get_open_max() / 8;
m_readSet = (fd_set*)new char[m_setSize];
m_writeSet = (fd_set*)new char[m_setSize];
m_errorSet = (fd_set*)new char[m_setSize];
#else
if (m_poll->max_open_sockets() > FD_SETSIZE)
if (m_poll->get_open_max() > FD_SETSIZE)
throw std::logic_error("PollManager::PollManager(...) received a max open sockets >= FD_SETSIZE, but USE_VARIABLE_FDSET was not defined");
m_setSize = FD_SETSIZE / 8;
+1 -1
View File
@@ -56,7 +56,7 @@ public:
PollManager(torrent::Poll* poll);
virtual ~PollManager();
unsigned int max_open_sockets() const { return m_poll->max_open_sockets(); }
unsigned int get_open_max() const { return m_poll->get_open_max(); }
CurlStack* get_http_stack() { return &m_httpStack; }
torrent::Poll* get_torrent_poll() { return m_poll; }
+1 -1
View File
@@ -70,7 +70,7 @@ print_download_info(char* buf, unsigned int length, core::Download* d) {
(double)d->get_download().get_bytes_done() / (double)(1 << 20),
(double)d->get_download().get_bytes_total() / (double)(1 << 20)));
buf += std::max(0, snprintf(buf, last - buf, " Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
buf += std::max(0, snprintf(buf, last - buf, " Rate: %5.1f / %5.1f KB Uploaded: %.1f MB",
(double)d->get_download().get_write_rate().rate() / (1 << 10),
(double)d->get_download().get_read_rate().rate() / (1 << 10),
(double)d->get_download().get_write_rate().total() / (1 << 20)));
+5 -3
View File
@@ -72,7 +72,7 @@ WindowStatusbar::redraw() {
else
pos = snprintf(buf + pos, 128 - pos, "%-3i", torrent::get_read_throttle() / 1024);
m_canvas->print(0, 0, "Throttle U/D: %s Rate: %5.1f / %5.1f KiB Listen: %s:%i%s",
m_canvas->print(0, 0, "Throttle U/D: %s Rate: %5.1f / %5.1f KB Listen: %s:%i%s",
buf,
(double)torrent::get_write_rate().rate() / 1024.0,
(double)torrent::get_read_rate().rate() / 1024.0,
@@ -80,10 +80,12 @@ WindowStatusbar::redraw() {
(int)torrent::get_listen_port(),
!torrent::get_bind_address().empty() ? (" Bind: " + torrent::get_bind_address()).c_str() : "");
pos = snprintf(buf, 128, "[%3i/%3i/%3i]",
pos = snprintf(buf, 128, "[S %i/%i/%i] [F %i/%i]",
torrent::get_total_handshakes(),
torrent::get_open_sockets(),
torrent::get_max_open_sockets());
torrent::get_max_open_sockets(),
torrent::get_open_files(),
torrent::get_max_open_files());
m_canvas->print(m_canvas->get_width() - pos, 0, "%s", buf);
}
+1 -1
View File
@@ -284,7 +284,7 @@ do_panic(int signum) {
void
receive_tracker_dump(std::istream* s) {
std::stringstream filename;
filename << "./tracker_dump." << utils::Timer::current().sec();
filename << "./tracker_dump." << utils::Timer::current().seconds();
std::fstream out(filename.str().c_str(), std::ios::out | std::ios::trunc);
+29 -34
View File
@@ -37,67 +37,62 @@
#ifndef RTORRENT_UTILS_TIMER_H
#define RTORRENT_UTILS_TIMER_H
#include <limits>
#include <inttypes.h>
#include <sys/time.h>
namespace utils {
// Don't convert negative Timer to timeval.
// Don't convert negative Timer to timeval and then back to Timer, that will bork.
class Timer {
public:
Timer() : m_time(0) {}
Timer(int64_t usec) : m_time(usec) {}
Timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
int64_t usec() const { return m_time; }
int32_t sec() const { return m_time / 1000000; }
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
int32_t seconds() const { return m_time / 1000000; }
int64_t usec() const { return m_time; }
Timer round_seconds() const { return (m_time / 1000000) * 1000000; }
Timer round_seconds() const { return (m_time / 1000000) * 1000000; }
static Timer current() {
timeval t;
gettimeofday(&t, 0);
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
return Timer(t);
}
static Timer current();
// Cached time, updated in the beginning of torrent::work call.
// Don't use outside socket_base read/write/except or Service::service.
// TODO: Find out if it's worth it. The kernel is supposed to cache the
// time. Though system calls would be more expensive than we can afford.
static Timer cache() { return Timer(m_cache); }
static Timer cache() { return Timer(m_cache); }
// TODO: Create sd::numeric_limits for these?
static Timer min() { return 0; }
static Timer max() { return (int64_t)std::numeric_limits<time_t>::max() * 1000000; }
static void update() { m_cache = Timer::current().usec(); }
static void update() { m_cache = Timer::current().usec(); }
bool operator < (const Timer& t) const { return m_time < t.m_time; }
bool operator > (const Timer& t) const { return m_time > t.m_time; }
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
Timer operator - (const Timer& t) const { return Timer(m_time - t.m_time); }
Timer operator + (const Timer& t) const { return Timer(m_time + t.m_time); }
Timer operator - (const Timer& t) const { return Timer(m_time - t.m_time); }
Timer operator + (const Timer& t) const { return Timer(m_time + t.m_time); }
Timer operator -= (int64_t t) { m_time -= t; return *this; }
Timer operator -= (const Timer& t) { m_time -= t.m_time; return *this; }
Timer operator -= (int64_t t) { m_time -= t; return *this; }
Timer operator -= (const Timer& t) { m_time -= t.m_time; return *this; }
Timer operator += (int64_t t) { m_time += t; return *this; }
Timer operator += (const Timer& t) { m_time += t.m_time; return *this; }
bool operator < (const Timer& t) const { return m_time < t.m_time; }
bool operator > (const Timer& t) const { return m_time > t.m_time; }
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
bool operator == (const Timer& t) const { return m_time == t.m_time; }
Timer operator += (int64_t t) { m_time += t; return *this; }
Timer operator += (const Timer& t) { m_time += t.m_time; return *this; }
private:
int64_t m_time;
int64_t m_time;
// Instantiated in torrent.cc
static int64_t m_cache;
static int64_t m_cache;
};
inline Timer
Timer::current() {
timeval t;
gettimeofday(&t, 0);
return Timer(t);
}
}
#endif // LIBTORRENT_TIMER_H
#endif