OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/curvecp/messenger.h" | 5 #include "net/curvecp/messenger.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 int Messenger::Write(IOBuffer* buf, int buf_len, CompletionCallback* callback) { | 89 int Messenger::Write(IOBuffer* buf, int buf_len, CompletionCallback* callback) { |
90 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
91 DCHECK(!pending_send_.get()); // Already a write pending! | 91 DCHECK(!pending_send_.get()); // Already a write pending! |
92 DCHECK(!send_complete_callback_); | 92 DCHECK(!send_complete_callback_); |
93 DCHECK_LT(0, buf_len); | 93 DCHECK_LT(0, buf_len); |
94 | 94 |
95 int len = send_buffer_.write(buf->data(), buf_len); | 95 int len = send_buffer_.write(buf->data(), buf_len); |
96 if (!send_timer_.IsRunning()) | 96 if (!send_timer_.IsRunning()) |
97 send_timer_.Start(base::TimeDelta(), this, &Messenger::OnSendTimer); | 97 send_timer_.Start(FROM_HERE, base::TimeDelta(), |
| 98 this, &Messenger::OnSendTimer); |
98 if (len) | 99 if (len) |
99 return len; | 100 return len; |
100 | 101 |
101 // We couldn't add data to the send buffer, so block the application. | 102 // We couldn't add data to the send buffer, so block the application. |
102 pending_send_ = buf; | 103 pending_send_ = buf; |
103 pending_send_length_ = buf_len; | 104 pending_send_length_ = buf_len; |
104 send_complete_callback_ = callback; | 105 send_complete_callback_ = callback; |
105 return ERR_IO_PENDING; | 106 return ERR_IO_PENDING; |
106 } | 107 } |
107 | 108 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 177 |
177 // If the send timer fired while we were waiting for this send to complete, | 178 // If the send timer fired while we were waiting for this send to complete, |
178 // we need to manually run the timer now. | 179 // we need to manually run the timer now. |
179 if (!send_timer_.IsRunning()) | 180 if (!send_timer_.IsRunning()) |
180 OnSendTimer(); | 181 OnSendTimer(); |
181 | 182 |
182 if (!send_timeout_timer_.IsRunning()) { | 183 if (!send_timeout_timer_.IsRunning()) { |
183 LOG(ERROR) << "RttTimeout is " << rtt_.rtt_timeout(); | 184 LOG(ERROR) << "RttTimeout is " << rtt_.rtt_timeout(); |
184 base::TimeDelta delay = | 185 base::TimeDelta delay = |
185 base::TimeDelta::FromMicroseconds(rtt_.rtt_timeout()); | 186 base::TimeDelta::FromMicroseconds(rtt_.rtt_timeout()); |
186 send_timeout_timer_.Start(delay, this, &Messenger::OnTimeout); | 187 send_timeout_timer_.Start(FROM_HERE, delay, this, &Messenger::OnTimeout); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 void Messenger::OnTimeout() { | 191 void Messenger::OnTimeout() { |
191 LOG(ERROR) << "OnTimeout fired"; | 192 LOG(ERROR) << "OnTimeout fired"; |
192 int64 position = sent_list_.FindPositionOfOldestSentBlock(); | 193 int64 position = sent_list_.FindPositionOfOldestSentBlock(); |
193 // XXXMB - need to verify that we really need to retransmit... | 194 // XXXMB - need to verify that we really need to retransmit... |
194 if (position >= 0) { | 195 if (position >= 0) { |
195 rtt_.OnTimeout(); // adjust our send rate. | 196 rtt_.OnTimeout(); // adjust our send rate. |
196 LOG(ERROR) << "OnTimeout retransmitting: " << position; | 197 LOG(ERROR) << "OnTimeout retransmitting: " << position; |
(...skipping 10 matching lines...) Expand all Loading... |
207 DCHECK(!send_timer_.IsRunning()); | 208 DCHECK(!send_timer_.IsRunning()); |
208 | 209 |
209 // If the send buffer is empty, then we don't need to keep firing. | 210 // If the send buffer is empty, then we don't need to keep firing. |
210 if (!send_buffer_.length()) { | 211 if (!send_buffer_.length()) { |
211 LOG(ERROR) << "OnSendTimer: send_buffer empty"; | 212 LOG(ERROR) << "OnSendTimer: send_buffer empty"; |
212 return; | 213 return; |
213 } | 214 } |
214 | 215 |
215 // Set the next send timer. | 216 // Set the next send timer. |
216 LOG(ERROR) << "SendRate is: " << rtt_.send_rate() << "us"; | 217 LOG(ERROR) << "SendRate is: " << rtt_.send_rate() << "us"; |
217 send_timer_.Start(base::TimeDelta::FromMicroseconds(rtt_.send_rate()), | 218 send_timer_.Start(FROM_HERE, |
218 this, | 219 base::TimeDelta::FromMicroseconds(rtt_.send_rate()), |
219 &Messenger::OnSendTimer); | 220 this, &Messenger::OnSendTimer); |
220 | 221 |
221 // Create a block from the send_buffer. | 222 // Create a block from the send_buffer. |
222 if (!sent_list_.is_full()) { | 223 if (!sent_list_.is_full()) { |
223 scoped_refptr<IOBufferWithSize> buffer = CreateBufferFromSendQueue(); | 224 scoped_refptr<IOBufferWithSize> buffer = CreateBufferFromSendQueue(); |
224 int64 position = sent_list_.CreateBlock(buffer.get()); | 225 int64 position = sent_list_.CreateBlock(buffer.get()); |
225 DCHECK_LE(0, position); | 226 DCHECK_LE(0, position); |
226 SendMessage(position); | 227 SendMessage(position); |
227 } | 228 } |
228 | 229 |
229 RecvMessage(); // Try to process an incoming message | 230 RecvMessage(); // Try to process an incoming message |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 362 |
362 int rv = packetizer_->SendMessage(key_, | 363 int rv = packetizer_->SendMessage(key_, |
363 buffer->data(), | 364 buffer->data(), |
364 sizeof(Message), | 365 sizeof(Message), |
365 &send_message_callback_); | 366 &send_message_callback_); |
366 // TODO(mbelshe): Fix me! Deal with the error cases | 367 // TODO(mbelshe): Fix me! Deal with the error cases |
367 DCHECK(rv == sizeof(Message)); | 368 DCHECK(rv == sizeof(Message)); |
368 } | 369 } |
369 | 370 |
370 } // namespace net | 371 } // namespace net |
OLD | NEW |