]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/pingtimer.h
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / pingtimer.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #pragma once
21
22 class TreeServer;
23
24 /** Handles PINGing servers and killing them on timeout
25  */
26 class PingTimer : public Timer
27 {
28         enum State
29         {
30                 /** Send PING next */
31                 PS_SENDPING,
32                 /** Warn opers next */
33                 PS_WARN,
34                 /** Kill the server next due to ping timeout */
35                 PS_TIMEOUT,
36                 /** Do nothing */
37                 PS_IDLE
38         };
39
40         /** Server the timer is interacting with
41          */
42         TreeServer* const server;
43
44         /** What to do when the timer ticks next
45          */
46         State state;
47
48         /** Last ping time in milliseconds, used to calculate round trip time
49          */
50         unsigned long LastPingMsec;
51
52         /** Update internal state and reschedule timer according to the new state
53          * @param newstate State to change to
54          */
55         void SetState(State newstate);
56
57         /** Process timer tick event
58          * @return State to change to
59          */
60         State TickInternal();
61
62         /** Called by the TimerManager when the timer expires
63          * @param currtime Time now
64          * @return Always false, we reschedule ourselves instead
65          */
66         bool Tick(time_t currtime) CXX11_OVERRIDE;
67
68  public:
69         /** Construct the timer. This doesn't schedule the timer.
70          * @param server TreeServer to interact with
71          */
72         PingTimer(TreeServer* server);
73
74         /** Register a PONG from the server
75          */
76         void OnPong();
77 };