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

Side by Side Diff: remoting/protocol/fake_session.cc

Issue 6271004: Changed MessageReader so that it doesn't read from the socket if there are (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: proper handling of empty messages Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/fake_session.h" 5 #include "remoting/protocol/fake_session.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 10
11 namespace remoting { 11 namespace remoting {
12 namespace protocol { 12 namespace protocol {
13 13
14 const char kTestJid[] = "host1@gmail.com/chromoting123"; 14 const char kTestJid[] = "host1@gmail.com/chromoting123";
15 15
16 FakeSocket::FakeSocket() 16 FakeSocket::FakeSocket()
17 : read_pending_(false), 17 : read_pending_(false),
18 input_pos_(0) { 18 input_pos_(0) {
19 } 19 }
20 20
21 FakeSocket::~FakeSocket() { 21 FakeSocket::~FakeSocket() {
22 } 22 }
23 23
24 void FakeSocket::AppendInputData(char* data, int data_size) { 24 void FakeSocket::AppendInputData(const char* data, int data_size) {
25 input_data_.insert(input_data_.end(), data, data + data_size); 25 input_data_.insert(input_data_.end(), data, data + data_size);
26 // Complete pending read if any. 26 // Complete pending read if any.
27 if (read_pending_) { 27 if (read_pending_) {
28 read_pending_ = false; 28 read_pending_ = false;
29 int result = std::min(read_buffer_size_, 29 int result = std::min(read_buffer_size_,
30 static_cast<int>(input_data_.size() - input_pos_)); 30 static_cast<int>(input_data_.size() - input_pos_));
31 CHECK(result > 0); 31 CHECK(result > 0);
32 memcpy(read_buffer_->data(), 32 memcpy(read_buffer_->data(),
33 &(*input_data_.begin()) + input_pos_, result); 33 &(*input_data_.begin()) + input_pos_, result);
34 input_pos_ += result; 34 input_pos_ += result;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 FakeUdpSocket::FakeUdpSocket() 73 FakeUdpSocket::FakeUdpSocket()
74 : read_pending_(false), 74 : read_pending_(false),
75 input_pos_(0) { 75 input_pos_(0) {
76 } 76 }
77 77
78 FakeUdpSocket::~FakeUdpSocket() { 78 FakeUdpSocket::~FakeUdpSocket() {
79 } 79 }
80 80
81 void FakeUdpSocket::AppendInputPacket(char* data, int data_size) { 81 void FakeUdpSocket::AppendInputPacket(const char* data, int data_size) {
82 input_packets_.push_back(std::string()); 82 input_packets_.push_back(std::string());
83 input_packets_.back().assign(data, data + data_size); 83 input_packets_.back().assign(data, data + data_size);
84 84
85 // Complete pending read if any. 85 // Complete pending read if any.
86 if (read_pending_) { 86 if (read_pending_) {
87 read_pending_ = false; 87 read_pending_ = false;
88 int result = std::min(data_size, read_buffer_size_); 88 int result = std::min(data_size, read_buffer_size_);
89 memcpy(read_buffer_->data(), data, result); 89 memcpy(read_buffer_->data(), data, result);
90 input_pos_ = input_packets_.size(); 90 input_pos_ = input_packets_.size();
91 read_callback_->Run(result); 91 read_callback_->Run(result);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 199
200 void FakeSession::Close(Task* closed_task) { 200 void FakeSession::Close(Task* closed_task) {
201 closed_ = true; 201 closed_ = true;
202 closed_task->Run(); 202 closed_task->Run();
203 delete closed_task; 203 delete closed_task;
204 } 204 }
205 205
206 } // namespace protocol 206 } // namespace protocol
207 } // namespace remoting 207 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698