OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/libjingle/xmpp/pingtask.h" | 11 #include "webrtc/libjingle/xmpp/pingtask.h" |
12 | 12 |
| 13 #include <memory> |
| 14 |
13 #include "webrtc/libjingle/xmpp/constants.h" | 15 #include "webrtc/libjingle/xmpp/constants.h" |
14 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
15 #include "webrtc/base/scoped_ptr.h" | |
16 | 17 |
17 namespace buzz { | 18 namespace buzz { |
18 | 19 |
19 PingTask::PingTask(buzz::XmppTaskParentInterface* parent, | 20 PingTask::PingTask(buzz::XmppTaskParentInterface* parent, |
20 rtc::MessageQueue* message_queue, | 21 rtc::MessageQueue* message_queue, |
21 uint32_t ping_period_millis, | 22 uint32_t ping_period_millis, |
22 uint32_t ping_timeout_millis) | 23 uint32_t ping_timeout_millis) |
23 : buzz::XmppTask(parent, buzz::XmppEngine::HL_SINGLE), | 24 : buzz::XmppTask(parent, buzz::XmppEngine::HL_SINGLE), |
24 message_queue_(message_queue), | 25 message_queue_(message_queue), |
25 ping_period_millis_(ping_period_millis), | 26 ping_period_millis_(ping_period_millis), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 uint32_t now = rtc::Time(); | 60 uint32_t now = rtc::Time(); |
60 | 61 |
61 // If the ping timed out, signal. | 62 // If the ping timed out, signal. |
62 if (ping_response_deadline_ != 0 && now >= ping_response_deadline_) { | 63 if (ping_response_deadline_ != 0 && now >= ping_response_deadline_) { |
63 SignalTimeout(); | 64 SignalTimeout(); |
64 return STATE_ERROR; | 65 return STATE_ERROR; |
65 } | 66 } |
66 | 67 |
67 // Send a ping if it's time. | 68 // Send a ping if it's time. |
68 if (now >= next_ping_time_) { | 69 if (now >= next_ping_time_) { |
69 rtc::scoped_ptr<buzz::XmlElement> stanza( | 70 std::unique_ptr<buzz::XmlElement> stanza( |
70 MakeIq(buzz::STR_GET, Jid(STR_EMPTY), task_id())); | 71 MakeIq(buzz::STR_GET, Jid(STR_EMPTY), task_id())); |
71 stanza->AddElement(new buzz::XmlElement(QN_PING)); | 72 stanza->AddElement(new buzz::XmlElement(QN_PING)); |
72 SendStanza(stanza.get()); | 73 SendStanza(stanza.get()); |
73 | 74 |
74 ping_response_deadline_ = now + ping_timeout_millis_; | 75 ping_response_deadline_ = now + ping_timeout_millis_; |
75 next_ping_time_ = now + ping_period_millis_; | 76 next_ping_time_ = now + ping_period_millis_; |
76 | 77 |
77 // Wake ourselves up when it's time to send another ping or when the ping | 78 // Wake ourselves up when it's time to send another ping or when the ping |
78 // times out (so we can fire a signal). | 79 // times out (so we can fire a signal). |
79 message_queue_->PostDelayed(ping_timeout_millis_, this); | 80 message_queue_->PostDelayed(ping_timeout_millis_, this); |
80 message_queue_->PostDelayed(ping_period_millis_, this); | 81 message_queue_->PostDelayed(ping_period_millis_, this); |
81 } | 82 } |
82 | 83 |
83 return STATE_BLOCKED; | 84 return STATE_BLOCKED; |
84 } | 85 } |
85 | 86 |
86 void PingTask::OnMessage(rtc::Message* msg) { | 87 void PingTask::OnMessage(rtc::Message* msg) { |
87 // Get the task manager to run this task so we can send a ping or signal or | 88 // Get the task manager to run this task so we can send a ping or signal or |
88 // process a ping response. | 89 // process a ping response. |
89 Wake(); | 90 Wake(); |
90 } | 91 } |
91 | 92 |
92 } // namespace buzz | 93 } // namespace buzz |
OLD | NEW |