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