OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_LIBJINGLE_XMPP_PINGTASK_H_ | |
12 #define WEBRTC_LIBJINGLE_XMPP_PINGTASK_H_ | |
13 | |
14 #include "webrtc/libjingle/xmpp/xmpptask.h" | |
15 #include "webrtc/base/messagehandler.h" | |
16 #include "webrtc/base/messagequeue.h" | |
17 | |
18 namespace buzz { | |
19 | |
20 // Task to periodically send pings to the server to ensure that the network | |
21 // connection is valid, implementing XEP-0199. | |
22 // | |
23 // This is especially useful on cellular networks because: | |
24 // 1. It keeps the connections alive through the cellular network's NATs or | |
25 // proxies. | |
26 // 2. It detects when the server has crashed or any other case in which the | |
27 // connection has broken without a fin or reset packet being sent to us. | |
28 class PingTask : public buzz::XmppTask, private rtc::MessageHandler { | |
29 public: | |
30 PingTask(buzz::XmppTaskParentInterface* parent, | |
31 rtc::MessageQueue* message_queue, | |
32 uint32_t ping_period_millis, | |
33 uint32_t ping_timeout_millis); | |
34 | |
35 virtual bool HandleStanza(const buzz::XmlElement* stanza); | |
36 virtual int ProcessStart(); | |
37 | |
38 // Raised if there is no response to a ping within ping_timeout_millis. | |
39 // The task is automatically aborted after a timeout. | |
40 sigslot::signal0<> SignalTimeout; | |
41 | |
42 private: | |
43 // Implementation of MessageHandler. | |
44 virtual void OnMessage(rtc::Message* msg); | |
45 | |
46 rtc::MessageQueue* message_queue_; | |
47 uint32_t ping_period_millis_; | |
48 uint32_t ping_timeout_millis_; | |
49 int64_t next_ping_time_; | |
50 int64_t ping_response_deadline_; // 0 if the response has been received | |
51 }; | |
52 | |
53 } // namespace buzz | |
54 | |
55 #endif // WEBRTC_LIBJINGLE_XMPP_PINGTASK_H_ | |
OLD | NEW |