Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/protocol/message_reader.h" | 5 #include "remoting/protocol/message_reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 DoRead(); | 59 DoRead(); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void MessageReader::HandleReadResult(int result) { | 63 void MessageReader::HandleReadResult(int result) { |
| 64 if (closed_) | 64 if (closed_) |
| 65 return; | 65 return; |
| 66 | 66 |
| 67 if (result > 0) { | 67 if (result > 0) { |
| 68 OnDataReceived(read_buffer_, result); | 68 OnDataReceived(read_buffer_, result); |
| 69 } else if (result == net::ERR_IO_PENDING) { | |
| 70 read_pending_ = true; | |
| 69 } else { | 71 } else { |
| 70 if (result == net::ERR_CONNECTION_CLOSED) { | 72 if (result != net::ERR_CONNECTION_CLOSED) { |
| 71 closed_ = true; | |
| 72 } else if (result == net::ERR_IO_PENDING) { | |
| 73 read_pending_ = true; | |
| 74 } else { | |
| 75 LOG(ERROR) << "Read() returned error " << result; | 73 LOG(ERROR) << "Read() returned error " << result; |
| 76 } | 74 } |
| 75 // Stop reading after an error. | |
|
Wez
2012/07/14 00:58:34
nit: an -> any
Sergey Ulanov
2012/07/14 01:17:22
Done.
| |
| 76 closed_ = true; | |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) { | 80 void MessageReader::OnDataReceived(net::IOBuffer* data, int data_size) { |
| 81 message_decoder_.AddData(data, data_size); | 81 message_decoder_.AddData(data, data_size); |
| 82 | 82 |
| 83 // Get list of all new messages first, and then call the callback | 83 // Get list of all new messages first, and then call the callback |
| 84 // for all of them. | 84 // for all of them. |
| 85 std::vector<CompoundBuffer*> new_messages; | 85 std::vector<CompoundBuffer*> new_messages; |
| 86 while (true) { | 86 while (true) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 108 } else { | 108 } else { |
| 109 task_runner->PostTask( | 109 task_runner->PostTask( |
| 110 FROM_HERE, base::Bind(&MessageReader::ProcessDoneEvent, this)); | 110 FROM_HERE, base::Bind(&MessageReader::ProcessDoneEvent, this)); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void MessageReader::ProcessDoneEvent() { | 114 void MessageReader::ProcessDoneEvent() { |
| 115 pending_messages_--; | 115 pending_messages_--; |
| 116 DCHECK_GE(pending_messages_, 0); | 116 DCHECK_GE(pending_messages_, 0); |
| 117 | 117 |
| 118 if (!read_pending_) | |
| 118 DoRead(); // Start next read if neccessary. | 119 DoRead(); // Start next read if neccessary. |
|
Wez
2012/07/14 00:58:34
Indentation.
Sergey Ulanov
2012/07/14 01:17:22
Done.
| |
| 119 } | 120 } |
| 120 | 121 |
| 121 } // namespace protocol | 122 } // namespace protocol |
| 122 } // namespace remoting | 123 } // namespace remoting |
| OLD | NEW |