From 407f3383f04ad2cf7c1e681b4f3672f322e051af Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 12 Aug 2005 16:05:54 +0000 Subject: [PATCH] * 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 --- src/core/manager.cc | 5 --- src/core/poll_manager.cc | 4 +-- src/core/poll_manager.h | 2 +- src/display/utils.cc | 2 +- src/display/window_statusbar.cc | 8 +++-- src/main.cc | 2 +- src/utils/timer.h | 63 +++++++++++++++------------------ 7 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/core/manager.cc b/src/core/manager.cc index cd34f95d..cb39fe2b 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -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); diff --git a/src/core/poll_manager.cc b/src/core/poll_manager.cc index 98f1413c..c75abed1 100644 --- a/src/core/poll_manager.cc +++ b/src/core/poll_manager.cc @@ -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; diff --git a/src/core/poll_manager.h b/src/core/poll_manager.h index 1a847125..e4e22a58 100644 --- a/src/core/poll_manager.h +++ b/src/core/poll_manager.h @@ -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; } diff --git a/src/display/utils.cc b/src/display/utils.cc index 7d5f4546..2f1b8bb3 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -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))); diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 8e1db8e3..1f3d20e7 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -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); } diff --git a/src/main.cc b/src/main.cc index db0702d8..2ac72fca 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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); diff --git a/src/utils/timer.h b/src/utils/timer.h index dfe147f3..6e70f33b 100644 --- a/src/utils/timer.h +++ b/src/utils/timer.h @@ -37,67 +37,62 @@ #ifndef RTORRENT_UTILS_TIMER_H #define RTORRENT_UTILS_TIMER_H -#include #include #include 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::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