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

Unified Diff: remoting/protocol/fake_session.cc

Issue 10836030: Add unittests for BufferedSocketWriter and fix some bugs in that code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/fake_session.cc
diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc
index 69f87db58137c131c5fd18f5d11b777a89163a8f..c65e863108c94d4df5cd80c670aa8427a4d1c718 100644
--- a/remoting/protocol/fake_session.cc
+++ b/remoting/protocol/fake_session.cc
@@ -18,7 +18,10 @@ namespace protocol {
const char kTestJid[] = "host1@gmail.com/chromoting123";
FakeSocket::FakeSocket()
- : next_read_error_(net::OK),
+ : async_write_(false),
simonmorris 2012/07/31 20:19:50 Initialize write_pending_.
Sergey Ulanov 2012/07/31 21:37:53 Done.
+ write_limit_(0),
+ next_write_error_(net::OK),
+ next_read_error_(net::OK),
read_pending_(false),
read_buffer_size_(0),
input_pos_(0),
@@ -81,6 +84,37 @@ int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
int FakeSocket::Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) {
EXPECT_EQ(message_loop_, MessageLoop::current());
+ EXPECT_FALSE(write_pending_);
+
+ if (next_write_error_ != net::OK) {
+ int r = next_write_error_;
+ next_write_error_ = net::OK;
+ return r;
+ }
simonmorris 2012/07/31 20:19:50 Is next_write_error_ used anywhere else?
Sergey Ulanov 2012/07/31 21:37:53 It's set in set_next_write_error() and used only h
+
+ if (write_limit_ > 0)
+ buf_len = std::min(write_limit_, buf_len);
+
+ if (async_write_) {
+ message_loop_->PostTask(FROM_HERE, base::Bind(
+ &FakeSocket::DoAsyncWrite, weak_factory_.GetWeakPtr(),
+ scoped_refptr<net::IOBuffer>(buf), buf_len, callback));
+ write_pending_ = true;
+ return net::ERR_IO_PENDING;
+ } else {
+ DoWrite(buf, buf_len);
+ return buf_len;
+ }
+}
+
+void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len,
+ const net::CompletionCallback& callback) {
+ write_pending_ = false;
+ DoWrite(buf, buf_len);
+ callback.Run(buf_len);
+}
+
+void FakeSocket::DoWrite(net::IOBuffer* buf, int buf_len) {
written_data_.insert(written_data_.end(),
buf->data(), buf->data() + buf_len);
@@ -89,8 +123,6 @@ int FakeSocket::Write(net::IOBuffer* buf, int buf_len,
&FakeSocket::AppendInputData, peer_socket_,
std::vector<char>(buf->data(), buf->data() + buf_len)));
}
-
- return buf_len;
}
bool FakeSocket::SetReceiveBufferSize(int32 size) {

Powered by Google App Engine
This is Rietveld 408576698