Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (78 sloc) 4.078 kb
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
1 // libTorrent - BitTorrent library
b25af84 @rakshasa * Bumping the copyright year to 2006.
authored
2 // Copyright (C) 2005-2006, Jari Sundell
da764db @rakshasa 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 @rakshasa 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 @rakshasa 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 @rakshasa * Moved Timer to rak/timer.h.
authored
37 #ifndef RAK_TIMER_H
38 #define RAK_TIMER_H
e029745 @rakshasa Alot of UI work, resize fixed.
authored
39
40 #include <inttypes.h>
41 #include <sys/time.h>
42
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
43 namespace rak {
a5f23ad @rakshasa Reorganized, moing stuff to src/utils subdir.
authored
44
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
45 // Don't convert negative Timer to timeval and then back to Timer, that will bork.
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
46 class timer {
e029745 @rakshasa Alot of UI work, resize fixed.
authored
47 public:
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
48 timer() : m_time(0) {}
49 timer(int64_t usec) : m_time(usec) {}
50 timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
e029745 @rakshasa Alot of UI work, resize fixed.
authored
51
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
52 int32_t seconds() const { return m_time / 1000000; }
53 int64_t usec() const { return m_time; }
e029745 @rakshasa Alot of UI work, resize fixed.
authored
54
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
55 timer round_seconds() const { return (m_time / 1000000) * 1000000; }
e029745 @rakshasa Alot of UI work, resize fixed.
authored
56
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
57 timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
e029745 @rakshasa Alot of UI work, resize fixed.
authored
58
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
59 static timer current();
66bb95a @rakshasa * Select the proper encoding for a torrent's name so that multi-file
authored
60 static timer from_seconds(uint32_t seconds) { return rak::timer((uint64_t)seconds * 1000000); }
61 static timer from_milliseconds(uint32_t seconds) { return rak::timer((uint64_t)seconds * 1000); }
e029745 @rakshasa Alot of UI work, resize fixed.
authored
62
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
63 bool operator < (const timer& t) const { return m_time < t.m_time; }
64 bool operator > (const timer& t) const { return m_time > t.m_time; }
65 bool operator <= (const timer& t) const { return m_time <= t.m_time; }
66 bool operator >= (const timer& t) const { return m_time >= t.m_time; }
67 bool operator == (const timer& t) const { return m_time == t.m_time; }
68 bool operator != (const timer& t) const { return m_time != t.m_time; }
fd0c10d @rakshasa Moved over to a next time based display update.
authored
69
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
70 timer operator - (const timer& t) const { return timer(m_time - t.m_time); }
71 timer operator + (const timer& t) const { return timer(m_time + t.m_time); }
c89ae51 @rakshasa * Allow clock time for command scheduler interval and start time using
authored
72 timer operator * (int64_t t) const { return timer(m_time * t); }
73 timer operator / (int64_t t) const { return timer(m_time / t); }
fd0c10d @rakshasa Moved over to a next time based display update.
authored
74
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
75 timer operator -= (int64_t t) { m_time -= t; return *this; }
76 timer operator -= (const timer& t) { m_time -= t.m_time; return *this; }
fd0c10d @rakshasa Moved over to a next time based display update.
authored
77
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
78 timer operator += (int64_t t) { m_time += t; return *this; }
79 timer operator += (const timer& t) { m_time += t.m_time; return *this; }
e029745 @rakshasa Alot of UI work, resize fixed.
authored
80
81 private:
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
82 int64_t m_time;
e029745 @rakshasa Alot of UI work, resize fixed.
authored
83 };
84
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
85 inline timer
86 timer::current() {
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
87 timeval t;
88 gettimeofday(&t, 0);
89
32a3619 @rakshasa * Moved Timer to rak/timer.h.
authored
90 return timer(t);
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
91 }
92
a5f23ad @rakshasa Reorganized, moing stuff to src/utils subdir.
authored
93 }
94
407f338 @rakshasa * Automagically set the max open sockets and files to resonable values
authored
95 #endif
Something went wrong with that request. Please try again.