Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webrtc/p2p/base/stunrequest.cc

Issue 1821083002: Split ByteBuffer into writer/reader objects. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/stun_unittest.cc ('k') | webrtc/p2p/base/stunserver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 RequestMap::iterator iter = requests_.find(id); 132 RequestMap::iterator iter = requests_.find(id);
133 if (iter == requests_.end()) { 133 if (iter == requests_.end()) {
134 // TODO(pthatcher): Log unknown responses without being too spammy 134 // TODO(pthatcher): Log unknown responses without being too spammy
135 // in the logs. 135 // in the logs.
136 return false; 136 return false;
137 } 137 }
138 138
139 // Parse the STUN message and continue processing as usual. 139 // Parse the STUN message and continue processing as usual.
140 140
141 rtc::ByteBuffer buf(data, size); 141 rtc::ByteBufferReader buf(data, size);
142 rtc::scoped_ptr<StunMessage> response(iter->second->msg_->CreateNew()); 142 rtc::scoped_ptr<StunMessage> response(iter->second->msg_->CreateNew());
143 if (!response->Read(&buf)) { 143 if (!response->Read(&buf)) {
144 LOG(LS_WARNING) << "Failed to read STUN response " << rtc::hex_encode(id); 144 LOG(LS_WARNING) << "Failed to read STUN response " << rtc::hex_encode(id);
145 return false; 145 return false;
146 } 146 }
147 147
148 return CheckResponse(response.get()); 148 return CheckResponse(response.get());
149 } 149 }
150 150
151 StunRequest::StunRequest() 151 StunRequest::StunRequest()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 ASSERT(pmsg->message_id == MSG_STUN_SEND); 206 ASSERT(pmsg->message_id == MSG_STUN_SEND);
207 207
208 if (timeout_) { 208 if (timeout_) {
209 OnTimeout(); 209 OnTimeout();
210 delete this; 210 delete this;
211 return; 211 return;
212 } 212 }
213 213
214 tstamp_ = rtc::Time64(); 214 tstamp_ = rtc::Time64();
215 215
216 rtc::ByteBuffer buf; 216 rtc::ByteBufferWriter buf;
217 msg_->Write(&buf); 217 msg_->Write(&buf);
218 manager_->SignalSendPacket(buf.Data(), buf.Length(), this); 218 manager_->SignalSendPacket(buf.Data(), buf.Length(), this);
219 219
220 OnSent(); 220 OnSent();
221 manager_->thread_->PostDelayed(resend_delay(), this, MSG_STUN_SEND, NULL); 221 manager_->thread_->PostDelayed(resend_delay(), this, MSG_STUN_SEND, NULL);
222 } 222 }
223 223
224 void StunRequest::OnSent() { 224 void StunRequest::OnSent() {
225 count_ += 1; 225 count_ += 1;
226 if (count_ == MAX_SENDS) 226 if (count_ == MAX_SENDS)
227 timeout_ = true; 227 timeout_ = true;
228 } 228 }
229 229
230 int StunRequest::resend_delay() { 230 int StunRequest::resend_delay() {
231 if (count_ == 0) { 231 if (count_ == 0) {
232 return 0; 232 return 0;
233 } 233 }
234 return DELAY_UNIT * std::min(1 << (count_-1), DELAY_MAX_FACTOR); 234 return DELAY_UNIT * std::min(1 << (count_-1), DELAY_MAX_FACTOR);
235 } 235 }
236 236
237 } // namespace cricket 237 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/stun_unittest.cc ('k') | webrtc/p2p/base/stunserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698