Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: remoting/host/gnubby_socket.cc

Issue 1234003002: Fix GnubbyAuthHandlerPosix to handle requests correctly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@allowIo
Patch Set: Rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/gnubby_auth_handler_posix_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h" 8 #include "base/macros.h"
8 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
9 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "net/socket/stream_socket.h" 12 #include "net/socket/stream_socket.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 namespace { 16 namespace {
16 17
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 66
66 void GnubbySocket::SendSshError() { 67 void GnubbySocket::SendSshError() {
67 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
68 69
69 SendResponse(std::string(kSshError, arraysize(kSshError))); 70 SendResponse(std::string(kSshError, arraysize(kSshError)));
70 } 71 }
71 72
72 void GnubbySocket::StartReadingRequest( 73 void GnubbySocket::StartReadingRequest(
73 const base::Closure& request_received_callback) { 74 const base::Closure& request_received_callback) {
74 DCHECK(CalledOnValidThread()); 75 DCHECK(CalledOnValidThread());
76 DCHECK(request_received_callback_.is_null());
75 77
76 request_received_callback_ = request_received_callback; 78 request_received_callback_ = request_received_callback;
77 DoRead(); 79 DoRead();
78 } 80 }
79 81
80 void GnubbySocket::OnDataWritten(int result) { 82 void GnubbySocket::OnDataWritten(int result) {
81 DCHECK(CalledOnValidThread()); 83 DCHECK(CalledOnValidThread());
82 DCHECK(write_buffer_); 84 DCHECK(write_buffer_);
83 85
84 if (result < 0) { 86 if (result < 0) {
85 LOG(ERROR) << "Error in sending response."; 87 LOG(ERROR) << "Error sending response: " << result;
86 return; 88 return;
87 } 89 }
88 ResetTimer(); 90 ResetTimer();
89 write_buffer_->DidConsume(result); 91 write_buffer_->DidConsume(result);
90 DoWrite(); 92 DoWrite();
91 } 93 }
92 94
93 void GnubbySocket::DoWrite() { 95 void GnubbySocket::DoWrite() {
94 DCHECK(CalledOnValidThread()); 96 DCHECK(CalledOnValidThread());
95 DCHECK(write_buffer_); 97 DCHECK(write_buffer_);
96 98
97 if (!write_buffer_->BytesRemaining()) { 99 if (!write_buffer_->BytesRemaining()) {
98 write_buffer_ = nullptr; 100 write_buffer_ = nullptr;
99 return; 101 return;
100 } 102 }
101 int result = socket_->Write( 103 int result = socket_->Write(
102 write_buffer_.get(), write_buffer_->BytesRemaining(), 104 write_buffer_.get(), write_buffer_->BytesRemaining(),
103 base::Bind(&GnubbySocket::OnDataWritten, base::Unretained(this))); 105 base::Bind(&GnubbySocket::OnDataWritten, base::Unretained(this)));
104 if (result != net::ERR_IO_PENDING) 106 if (result != net::ERR_IO_PENDING)
105 OnDataWritten(result); 107 OnDataWritten(result);
106 } 108 }
107 109
108 void GnubbySocket::OnDataRead(int bytes_read) { 110 void GnubbySocket::OnDataRead(int result) {
109 DCHECK(CalledOnValidThread()); 111 DCHECK(CalledOnValidThread());
110 112
111 if (bytes_read < 0) { 113 if (result <= 0) {
112 LOG(ERROR) << "Error in reading request."; 114 if (result < 0)
115 LOG(ERROR) << "Error reading request: " << result;
113 read_completed_ = true; 116 read_completed_ = true;
114 request_received_callback_.Run(); 117 base::ResetAndReturn(&request_received_callback_).Run();
115 return; 118 return;
116 } 119 }
120
117 ResetTimer(); 121 ResetTimer();
118 request_data_.insert(request_data_.end(), read_buffer_->data(), 122 request_data_.insert(request_data_.end(), read_buffer_->data(),
119 read_buffer_->data() + bytes_read); 123 read_buffer_->data() + result);
120 if (IsRequestComplete()) { 124 if (IsRequestComplete()) {
121 read_completed_ = true; 125 read_completed_ = true;
122 request_received_callback_.Run(); 126 base::ResetAndReturn(&request_received_callback_).Run();
123 return; 127 return;
124 } 128 }
129
125 DoRead(); 130 DoRead();
126 } 131 }
127 132
128 void GnubbySocket::DoRead() { 133 void GnubbySocket::DoRead() {
129 DCHECK(CalledOnValidThread()); 134 DCHECK(CalledOnValidThread());
130 135
131 int result = socket_->Read( 136 int result = socket_->Read(
132 read_buffer_.get(), kRequestReadBufferLength, 137 read_buffer_.get(), kRequestReadBufferLength,
133 base::Bind(&GnubbySocket::OnDataRead, base::Unretained(this))); 138 base::Bind(&GnubbySocket::OnDataRead, base::Unretained(this)));
134 if (result != net::ERR_IO_PENDING) 139 if (result != net::ERR_IO_PENDING)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 177
173 return response_len; 178 return response_len;
174 } 179 }
175 180
176 void GnubbySocket::ResetTimer() { 181 void GnubbySocket::ResetTimer() {
177 if (timer_->IsRunning()) 182 if (timer_->IsRunning())
178 timer_->Reset(); 183 timer_->Reset();
179 } 184 }
180 185
181 } // namespace remoting 186 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/gnubby_auth_handler_posix_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698