Index: remoting/protocol/fake_session.cc |
diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc |
index 3b5499a55f150d8ffd840108665ed0db3bd82690..f1a890a22bec774dfc058747cb0599db0354b00a 100644 |
--- a/remoting/protocol/fake_session.cc |
+++ b/remoting/protocol/fake_session.cc |
@@ -36,7 +36,10 @@ void FakeSocket::AppendInputData(const char* data, int data_size) { |
memcpy(read_buffer_->data(), |
&(*input_data_.begin()) + input_pos_, result); |
input_pos_ += result; |
- read_callback_->Run(result); |
+ if (old_read_callback_) |
+ old_read_callback_->Run(result); |
+ else |
+ read_callback_.Run(result); |
read_buffer_ = NULL; |
} |
} |
@@ -54,6 +57,23 @@ int FakeSocket::Read(net::IOBuffer* buf, int buf_len, |
read_pending_ = true; |
read_buffer_ = buf; |
read_buffer_size_ = buf_len; |
+ old_read_callback_ = callback; |
+ return net::ERR_IO_PENDING; |
+ } |
+} |
+int FakeSocket::Read(net::IOBuffer* buf, int buf_len, |
+ const net::CompletionCallback& callback) { |
+ EXPECT_EQ(message_loop_, MessageLoop::current()); |
+ if (input_pos_ < static_cast<int>(input_data_.size())) { |
+ int result = std::min(buf_len, |
+ static_cast<int>(input_data_.size()) - input_pos_); |
+ memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result); |
+ input_pos_ += result; |
+ return result; |
+ } else { |
+ read_pending_ = true; |
+ read_buffer_ = buf; |
+ read_buffer_size_ = buf_len; |
read_callback_ = callback; |
return net::ERR_IO_PENDING; |
} |
@@ -146,6 +166,7 @@ base::TimeDelta FakeSocket::GetConnectTimeMicros() const { |
FakeUdpSocket::FakeUdpSocket() |
: read_pending_(false), |
+ old_read_callback_(NULL), |
input_pos_(0), |
message_loop_(MessageLoop::current()) { |
} |
@@ -165,7 +186,10 @@ void FakeUdpSocket::AppendInputPacket(const char* data, int data_size) { |
int result = std::min(data_size, read_buffer_size_); |
memcpy(read_buffer_->data(), data, result); |
input_pos_ = input_packets_.size(); |
- read_callback_->Run(result); |
+ if (old_read_callback_) |
+ old_read_callback_->Run(result); |
+ else |
+ old_read_callback_->Run(result); |
csilv
2011/12/07 00:03:48
read_callback_.Run(result)
|
read_buffer_ = NULL; |
} |
} |
@@ -183,6 +207,23 @@ int FakeUdpSocket::Read(net::IOBuffer* buf, int buf_len, |
read_pending_ = true; |
read_buffer_ = buf; |
read_buffer_size_ = buf_len; |
+ old_read_callback_ = callback; |
+ return net::ERR_IO_PENDING; |
+ } |
+} |
+int FakeUdpSocket::Read(net::IOBuffer* buf, int buf_len, |
+ const net::CompletionCallback& callback) { |
+ EXPECT_EQ(message_loop_, MessageLoop::current()); |
+ if (input_pos_ < static_cast<int>(input_packets_.size())) { |
+ int result = std::min( |
+ buf_len, static_cast<int>(input_packets_[input_pos_].size())); |
+ memcpy(buf->data(), &(*input_packets_[input_pos_].begin()), result); |
+ ++input_pos_; |
+ return result; |
+ } else { |
+ read_pending_ = true; |
+ read_buffer_ = buf; |
+ read_buffer_size_ = buf_len; |
read_callback_ = callback; |
return net::ERR_IO_PENDING; |
} |