| 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(FROM_HERE, base::TimeDelta(), | 97 send_timer_.Start(base::TimeDelta(), this, &Messenger::OnSendTimer); |
| 98 this, &Messenger::OnSendTimer); | |
| 99 if (len) | 98 if (len) |
| 100 return len; | 99 return len; |
| 101 | 100 |
| 102 // We couldn't add data to the send buffer, so block the application. | 101 // We couldn't add data to the send buffer, so block the application. |
| 103 pending_send_ = buf; | 102 pending_send_ = buf; |
| 104 pending_send_length_ = buf_len; | 103 pending_send_length_ = buf_len; |
| 105 send_complete_callback_ = callback; | 104 send_complete_callback_ = callback; |
| 106 return ERR_IO_PENDING; | 105 return ERR_IO_PENDING; |
| 107 } | 106 } |
| 108 | 107 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 176 |
| 178 // If the send timer fired while we were waiting for this send to complete, | 177 // If the send timer fired while we were waiting for this send to complete, |
| 179 // we need to manually run the timer now. | 178 // we need to manually run the timer now. |
| 180 if (!send_timer_.IsRunning()) | 179 if (!send_timer_.IsRunning()) |
| 181 OnSendTimer(); | 180 OnSendTimer(); |
| 182 | 181 |
| 183 if (!send_timeout_timer_.IsRunning()) { | 182 if (!send_timeout_timer_.IsRunning()) { |
| 184 LOG(ERROR) << "RttTimeout is " << rtt_.rtt_timeout(); | 183 LOG(ERROR) << "RttTimeout is " << rtt_.rtt_timeout(); |
| 185 base::TimeDelta delay = | 184 base::TimeDelta delay = |
| 186 base::TimeDelta::FromMicroseconds(rtt_.rtt_timeout()); | 185 base::TimeDelta::FromMicroseconds(rtt_.rtt_timeout()); |
| 187 send_timeout_timer_.Start(FROM_HERE, delay, this, &Messenger::OnTimeout); | 186 send_timeout_timer_.Start(delay, this, &Messenger::OnTimeout); |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 191 void Messenger::OnTimeout() { | 190 void Messenger::OnTimeout() { |
| 192 LOG(ERROR) << "OnTimeout fired"; | 191 LOG(ERROR) << "OnTimeout fired"; |
| 193 int64 position = sent_list_.FindPositionOfOldestSentBlock(); | 192 int64 position = sent_list_.FindPositionOfOldestSentBlock(); |
| 194 // XXXMB - need to verify that we really need to retransmit... | 193 // XXXMB - need to verify that we really need to retransmit... |
| 195 if (position >= 0) { | 194 if (position >= 0) { |
| 196 rtt_.OnTimeout(); // adjust our send rate. | 195 rtt_.OnTimeout(); // adjust our send rate. |
| 197 LOG(ERROR) << "OnTimeout retransmitting: " << position; | 196 LOG(ERROR) << "OnTimeout retransmitting: " << position; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 208 DCHECK(!send_timer_.IsRunning()); | 207 DCHECK(!send_timer_.IsRunning()); |
| 209 | 208 |
| 210 // If the send buffer is empty, then we don't need to keep firing. | 209 // If the send buffer is empty, then we don't need to keep firing. |
| 211 if (!send_buffer_.length()) { | 210 if (!send_buffer_.length()) { |
| 212 LOG(ERROR) << "OnSendTimer: send_buffer empty"; | 211 LOG(ERROR) << "OnSendTimer: send_buffer empty"; |
| 213 return; | 212 return; |
| 214 } | 213 } |
| 215 | 214 |
| 216 // Set the next send timer. | 215 // Set the next send timer. |
| 217 LOG(ERROR) << "SendRate is: " << rtt_.send_rate() << "us"; | 216 LOG(ERROR) << "SendRate is: " << rtt_.send_rate() << "us"; |
| 218 send_timer_.Start(FROM_HERE, | 217 send_timer_.Start(base::TimeDelta::FromMicroseconds(rtt_.send_rate()), |
| 219 base::TimeDelta::FromMicroseconds(rtt_.send_rate()), | 218 this, |
| 220 this, &Messenger::OnSendTimer); | 219 &Messenger::OnSendTimer); |
| 221 | 220 |
| 222 // Create a block from the send_buffer. | 221 // Create a block from the send_buffer. |
| 223 if (!sent_list_.is_full()) { | 222 if (!sent_list_.is_full()) { |
| 224 scoped_refptr<IOBufferWithSize> buffer = CreateBufferFromSendQueue(); | 223 scoped_refptr<IOBufferWithSize> buffer = CreateBufferFromSendQueue(); |
| 225 int64 position = sent_list_.CreateBlock(buffer.get()); | 224 int64 position = sent_list_.CreateBlock(buffer.get()); |
| 226 DCHECK_LE(0, position); | 225 DCHECK_LE(0, position); |
| 227 SendMessage(position); | 226 SendMessage(position); |
| 228 } | 227 } |
| 229 | 228 |
| 230 RecvMessage(); // Try to process an incoming message | 229 RecvMessage(); // Try to process an incoming message |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 361 |
| 363 int rv = packetizer_->SendMessage(key_, | 362 int rv = packetizer_->SendMessage(key_, |
| 364 buffer->data(), | 363 buffer->data(), |
| 365 sizeof(Message), | 364 sizeof(Message), |
| 366 &send_message_callback_); | 365 &send_message_callback_); |
| 367 // TODO(mbelshe): Fix me! Deal with the error cases | 366 // TODO(mbelshe): Fix me! Deal with the error cases |
| 368 DCHECK(rv == sizeof(Message)); | 367 DCHECK(rv == sizeof(Message)); |
| 369 } | 368 } |
| 370 | 369 |
| 371 } // namespace net | 370 } // namespace net |
| OLD | NEW |