Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/host/gnubby_socket.h" | 5 #include "remoting/host/gnubby_socket.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 | 65 |
| 66 void GnubbySocket::SendSshError() { | 66 void GnubbySocket::SendSshError() { |
| 67 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
| 68 | 68 |
| 69 SendResponse(std::string(kSshError, arraysize(kSshError))); | 69 SendResponse(std::string(kSshError, arraysize(kSshError))); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void GnubbySocket::StartReadingRequest( | 72 void GnubbySocket::StartReadingRequest( |
| 73 const base::Closure& request_received_callback) { | 73 const base::Closure& request_received_callback) { |
| 74 DCHECK(CalledOnValidThread()); | 74 DCHECK(CalledOnValidThread()); |
| 75 | 75 |
|
Sergey Ulanov
2015/07/16 23:20:54
DCHECK(!request_received_callback_);
Wez
2015/07/17 20:51:20
Done.
| |
| 76 request_received_callback_ = request_received_callback; | 76 request_received_callback_ = request_received_callback; |
| 77 DoRead(); | 77 DoRead(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void GnubbySocket::OnDataWritten(int result) { | 80 void GnubbySocket::OnDataWritten(int result) { |
| 81 DCHECK(CalledOnValidThread()); | 81 DCHECK(CalledOnValidThread()); |
| 82 DCHECK(write_buffer_); | 82 DCHECK(write_buffer_); |
| 83 | 83 |
| 84 if (result < 0) { | 84 if (result < 0) { |
| 85 LOG(ERROR) << "Error in sending response."; | 85 LOG(ERROR) << "Error in sending response."; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 101 int result = socket_->Write( | 101 int result = socket_->Write( |
| 102 write_buffer_.get(), write_buffer_->BytesRemaining(), | 102 write_buffer_.get(), write_buffer_->BytesRemaining(), |
| 103 base::Bind(&GnubbySocket::OnDataWritten, base::Unretained(this))); | 103 base::Bind(&GnubbySocket::OnDataWritten, base::Unretained(this))); |
| 104 if (result != net::ERR_IO_PENDING) | 104 if (result != net::ERR_IO_PENDING) |
| 105 OnDataWritten(result); | 105 OnDataWritten(result); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void GnubbySocket::OnDataRead(int bytes_read) { | 108 void GnubbySocket::OnDataRead(int bytes_read) { |
| 109 DCHECK(CalledOnValidThread()); | 109 DCHECK(CalledOnValidThread()); |
| 110 | 110 |
| 111 if (bytes_read < 0) { | 111 if (bytes_read <= 0) { |
| 112 LOG(ERROR) << "Error in reading request."; | 112 if (bytes_read < 0) |
| 113 LOG(ERROR) << "Error in reading request."; | |
|
Sergey Ulanov
2015/07/16 23:20:54
log the error code?
Wez
2015/07/17 20:51:19
Done.
| |
| 113 read_completed_ = true; | 114 read_completed_ = true; |
| 114 request_received_callback_.Run(); | 115 request_received_callback_.Run(); |
|
Sergey Ulanov
2015/07/16 23:20:54
This should be base::ResetAndReturn(request_receiv
Wez
2015/07/17 20:51:20
Done. Thanks for catching that!
| |
| 115 return; | 116 return; |
| 116 } | 117 } |
| 117 ResetTimer(); | 118 ResetTimer(); |
| 118 request_data_.insert(request_data_.end(), read_buffer_->data(), | 119 request_data_.insert(request_data_.end(), read_buffer_->data(), |
| 119 read_buffer_->data() + bytes_read); | 120 read_buffer_->data() + bytes_read); |
| 120 if (IsRequestComplete()) { | 121 if (IsRequestComplete()) { |
| 121 read_completed_ = true; | 122 read_completed_ = true; |
| 122 request_received_callback_.Run(); | 123 request_received_callback_.Run(); |
| 123 return; | 124 return; |
| 124 } | 125 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 | 173 |
| 173 return response_len; | 174 return response_len; |
| 174 } | 175 } |
| 175 | 176 |
| 176 void GnubbySocket::ResetTimer() { | 177 void GnubbySocket::ResetTimer() { |
| 177 if (timer_->IsRunning()) | 178 if (timer_->IsRunning()) |
| 178 timer_->Reset(); | 179 timer_->Reset(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 } // namespace remoting | 182 } // namespace remoting |
| OLD | NEW |