Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 106 lines (87 sloc) 4.408 kb
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
1 // libTorrent - BitTorrent library
535db16 Jari Sundell * Bumping copyright year to 2007.
authored
2 // Copyright (C) 2005-2007, Jari Sundell
da764db Jari Sundell Adding copyright claim to source files.
authored
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
0588e66 Jari Sundell Added license exception for linking toward OpenSSL.
authored
18 // In addition, as a special exception, the copyright holders give
19 // permission to link the code of portions of this program with the
20 // OpenSSL library under certain conditions as described in each
21 // individual source file, and distribute linked combinations
22 // including the two.
23 //
24 // You must obey the GNU General Public License in all respects for
25 // all of the code used other than OpenSSL. If you modify file(s)
26 // with this exception, you may extend this exception to your version
27 // of the file(s), but you are not obligated to do so. If you do not
28 // wish to do so, delete this exception statement from your version.
29 // If you delete this exception statement from all source files in the
30 // program, then also delete it here.
31 //
da764db Jari Sundell Adding copyright claim to source files.
authored
32 // Contact: Jari Sundell <jaris@ifi.uio.no>
33 //
34 // Skomakerveien 33
35 // 3185 Skoppum, NORWAY
36
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
37 #ifndef RAK_TIMER_H
38 #define RAK_TIMER_H
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
39
eb7c0b5 Jari Sundell * Made FileManager::close_least_active() work when cachedTime is
authored
40 #include <limits>
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
41 #include <inttypes.h>
42 #include <sys/time.h>
43
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
44 namespace rak {
a5f23ad Jari Sundell Reorganized, moing stuff to src/utils subdir.
authored
45
407f338 Jari Sundell * Automagically set the max open sockets and files to resonable values
authored
46 // Don't convert negative Timer to timeval and then back to Timer, that will bork.
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
47 class timer {
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
48 public:
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
49 timer() : m_time(0) {}
50 timer(int64_t usec) : m_time(usec) {}
51 timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
52
407f338 Jari Sundell * Automagically set the max open sockets and files to resonable values
authored
53 int32_t seconds() const { return m_time / 1000000; }
54 int64_t usec() const { return m_time; }
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
55
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
56 timer round_seconds() const { return (m_time / 1000000) * 1000000; }
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
57
f117b9d Jari Sundell * Allow loading torrents from https and ftp uri's.
authored
58 timeval tval() const {
59 timeval val;
60 val.tv_sec = m_time / 1000000;
61 val.tv_usec = m_time % 1000000;
62 return val;
63 }
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
64
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
65 static timer current();
49bb643 Jari Sundell * Added system.time{,_seconds,_usec} commands.
authored
66 static int64_t current_seconds() { return current().seconds(); }
67 static int64_t current_usec() { return current().usec(); }
66bb95a Jari Sundell * Select the proper encoding for a torrent's name so that multi-file
authored
68 static timer from_seconds(uint32_t seconds) { return rak::timer((uint64_t)seconds * 1000000); }
69 static timer from_milliseconds(uint32_t seconds) { return rak::timer((uint64_t)seconds * 1000); }
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
70
eb7c0b5 Jari Sundell * Made FileManager::close_least_active() work when cachedTime is
authored
71 static timer max() { return std::numeric_limits<int64_t>::max(); }
72
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
73 bool operator < (const timer& t) const { return m_time < t.m_time; }
74 bool operator > (const timer& t) const { return m_time > t.m_time; }
75 bool operator <= (const timer& t) const { return m_time <= t.m_time; }
76 bool operator >= (const timer& t) const { return m_time >= t.m_time; }
77 bool operator == (const timer& t) const { return m_time == t.m_time; }
78 bool operator != (const timer& t) const { return m_time != t.m_time; }
fd0c10d Jari Sundell Moved over to a next time based display update.
authored
79
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
80 timer operator - (const timer& t) const { return timer(m_time - t.m_time); }
81 timer operator + (const timer& t) const { return timer(m_time + t.m_time); }
c89ae51 Jari Sundell * Allow clock time for command scheduler interval and start time using
authored
82 timer operator * (int64_t t) const { return timer(m_time * t); }
83 timer operator / (int64_t t) const { return timer(m_time / t); }
fd0c10d Jari Sundell Moved over to a next time based display update.
authored
84
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
85 timer operator -= (int64_t t) { m_time -= t; return *this; }
86 timer operator -= (const timer& t) { m_time -= t.m_time; return *this; }
fd0c10d Jari Sundell Moved over to a next time based display update.
authored
87
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
88 timer operator += (int64_t t) { m_time += t; return *this; }
89 timer operator += (const timer& t) { m_time += t.m_time; return *this; }
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
90
91 private:
407f338 Jari Sundell * Automagically set the max open sockets and files to resonable values
authored
92 int64_t m_time;
e029745 Jari Sundell Alot of UI work, resize fixed.
authored
93 };
94
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
95 inline timer
96 timer::current() {
407f338 Jari Sundell * Automagically set the max open sockets and files to resonable values
authored
97 timeval t;
98 gettimeofday(&t, 0);
99
32a3619 Jari Sundell * Moved Timer to rak/timer.h.
authored
100 return timer(t);
407f338 Jari Sundell * Automagically set the max open sockets and files to resonable values
authored
101 }
102
a5f23ad Jari Sundell Reorganized, moing stuff to src/utils subdir.
authored
103 }
104
407f338 Jari Sundell * Automagically set the max open sockets and files to resonable values
authored
105 #endif
Something went wrong with that request. Please try again.