| 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/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/socket/stream_socket.h" | 12 #include "net/socket/stream_socket.h" |
| 13 | 13 |
| 14 namespace remoting { | 14 namespace remoting { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const size_t kRequestSizeBytes = 4; | 18 const size_t kRequestSizeBytes = 4; |
| 19 const size_t kMaxRequestLength = 16384; | 19 const size_t kMaxRequestLength = 16384; |
| 20 const size_t kRequestReadBufferLength = kRequestSizeBytes + kMaxRequestLength; | 20 const size_t kRequestReadBufferLength = kRequestSizeBytes + kMaxRequestLength; |
| 21 | 21 |
| 22 // SSH Failure Code | 22 // SSH Failure Code |
| 23 const char kSshError[] = {0x05}; | 23 const char kSshError[] = {0x05}; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 GnubbySocket::GnubbySocket(scoped_ptr<net::StreamSocket> socket, | 27 GnubbySocket::GnubbySocket(scoped_ptr<net::StreamSocket> socket, |
| 28 const base::TimeDelta& timeout, | 28 const base::TimeDelta& timeout, |
| 29 const base::Closure& timeout_callback) | 29 const base::Closure& timeout_callback) |
| 30 : socket_(socket.Pass()), | 30 : socket_(std::move(socket)), |
| 31 read_completed_(false), | 31 read_completed_(false), |
| 32 read_buffer_(new net::IOBufferWithSize(kRequestReadBufferLength)) { | 32 read_buffer_(new net::IOBufferWithSize(kRequestReadBufferLength)) { |
| 33 timer_.reset(new base::Timer(false, false)); | 33 timer_.reset(new base::Timer(false, false)); |
| 34 timer_->Start(FROM_HERE, timeout, timeout_callback); | 34 timer_->Start(FROM_HERE, timeout, timeout_callback); |
| 35 } | 35 } |
| 36 | 36 |
| 37 GnubbySocket::~GnubbySocket() {} | 37 GnubbySocket::~GnubbySocket() {} |
| 38 | 38 |
| 39 bool GnubbySocket::GetAndClearRequestData(std::string* data_out) { | 39 bool GnubbySocket::GetAndClearRequestData(std::string* data_out) { |
| 40 DCHECK(CalledOnValidThread()); | 40 DCHECK(CalledOnValidThread()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 void GnubbySocket::SendResponse(const std::string& response_data) { | 54 void GnubbySocket::SendResponse(const std::string& response_data) { |
| 55 DCHECK(CalledOnValidThread()); | 55 DCHECK(CalledOnValidThread()); |
| 56 DCHECK(!write_buffer_); | 56 DCHECK(!write_buffer_); |
| 57 | 57 |
| 58 std::string response_length_string = GetResponseLengthAsBytes(response_data); | 58 std::string response_length_string = GetResponseLengthAsBytes(response_data); |
| 59 int response_len = response_length_string.size() + response_data.size(); | 59 int response_len = response_length_string.size() + response_data.size(); |
| 60 scoped_ptr<std::string> response( | 60 scoped_ptr<std::string> response( |
| 61 new std::string(response_length_string + response_data)); | 61 new std::string(response_length_string + response_data)); |
| 62 write_buffer_ = new net::DrainableIOBuffer( | 62 write_buffer_ = new net::DrainableIOBuffer( |
| 63 new net::StringIOBuffer(response.Pass()), response_len); | 63 new net::StringIOBuffer(std::move(response)), response_len); |
| 64 DoWrite(); | 64 DoWrite(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void GnubbySocket::SendSshError() { | 67 void GnubbySocket::SendSshError() { |
| 68 DCHECK(CalledOnValidThread()); | 68 DCHECK(CalledOnValidThread()); |
| 69 | 69 |
| 70 SendResponse(std::string(kSshError, arraysize(kSshError))); | 70 SendResponse(std::string(kSshError, arraysize(kSshError))); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void GnubbySocket::StartReadingRequest( | 73 void GnubbySocket::StartReadingRequest( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 return response_len; | 178 return response_len; |
| 179 } | 179 } |
| 180 | 180 |
| 181 void GnubbySocket::ResetTimer() { | 181 void GnubbySocket::ResetTimer() { |
| 182 if (timer_->IsRunning()) | 182 if (timer_->IsRunning()) |
| 183 timer_->Reset(); | 183 timer_->Reset(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace remoting | 186 } // namespace remoting |
| OLD | NEW |