Commit | Line | Data |
---|---|---|
91fcc471 TJ |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
f4fc8957 GMF |
20 | #include "host/pinginterval.h" |
21 | ||
780b0bca | 22 | #include "boost_assert_handler.h" |
f4fc8957 GMF |
23 | |
24 | //----------------------------------------------------------------------------- | |
25 | // PingInterval | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | PingInterval::PingInterval( | |
29 | PingIntervalType interval | |
30 | ) : | |
31 | OriginalInterval( interval ), | |
32 | Interval( interval ) | |
33 | { | |
34 | BOOST_ASSERT( 0 < interval ); | |
35 | } | |
36 | ||
37 | PingInterval::~PingInterval() | |
38 | { | |
39 | } | |
40 | ||
6fd0993e | 41 | PingInterval::operator PingIntervalType() const |
f4fc8957 GMF |
42 | { |
43 | BOOST_ASSERT( 0 < Interval ); | |
44 | ||
45 | return Interval; | |
46 | } | |
47 | ||
48 | void PingInterval::back_to_original() | |
49 | { | |
50 | Interval = OriginalInterval; | |
51 | ||
52 | BOOST_ASSERT( 0 < Interval ); | |
53 | } | |
54 | ||
55 | void PingInterval::speed_up() | |
56 | { | |
57 | BOOST_ASSERT( 0 < Interval ); | |
58 | ||
59 | if ( can_speed_up() ) | |
60 | { | |
61 | Interval = Interval / 2; | |
62 | } | |
63 | ||
64 | if ( Interval < 1 ) | |
65 | { | |
66 | Interval = 1; | |
67 | } | |
68 | ||
69 | BOOST_ASSERT( 0 < Interval ); | |
70 | } | |
71 | ||
242e5fb3 | 72 | /** returns true if have not speeded up yet */ |
f4fc8957 GMF |
73 | bool PingInterval::can_speed_up() const |
74 | { | |
242e5fb3 | 75 | return Interval == OriginalInterval; |
f4fc8957 | 76 | } |