* 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
+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