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

Unified Diff: content/browser/renderer_host/p2p/socket_host_test_utils.h

Issue 13926013: Fix P2PSocketHostTcp to handle async write correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/p2p/socket_host_test_utils.h
diff --git a/content/browser/renderer_host/p2p/socket_host_test_utils.h b/content/browser/renderer_host/p2p/socket_host_test_utils.h
index 86c7414c031f6f3a41d6cd5b6b5435065fc9bc48..77da0cdb792013e8b606ae7ccdbc2ff065998edd 100644
--- a/content/browser/renderer_host/p2p/socket_host_test_utils.h
+++ b/content/browser/renderer_host/p2p/socket_host_test_utils.h
@@ -7,10 +7,13 @@
#include <vector>
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
#include "base/sys_byteorder.h"
+#include "base/thread_task_runner_handle.h"
#include "content/common/p2p_messages.h"
-#include "ipc/ipc_sender.h"
#include "ipc/ipc_message_utils.h"
+#include "ipc/ipc_sender.h"
#include "net/base/address_list.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
@@ -49,6 +52,7 @@ class FakeSocket : public net::StreamSocket {
FakeSocket(std::string* written_data);
virtual ~FakeSocket();
+ void set_async_write(bool async_write) { async_write_ = async_write; }
void AppendInputData(const char* data, int data_size);
int input_pos() const { return input_pos_; }
bool read_pending() const { return read_pending_; }
@@ -78,15 +82,21 @@ class FakeSocket : public net::StreamSocket {
virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
private:
+ void DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len,
+ const net::CompletionCallback& callback);
+
bool read_pending_;
scoped_refptr<net::IOBuffer> read_buffer_;
int read_buffer_size_;
net::CompletionCallback read_callback_;
- std::string* written_data_;
std::string input_data_;
int input_pos_;
+ std::string* written_data_;
+ bool async_write_;
+ bool write_pending_;
+
net::IPEndPoint peer_address_;
net::IPEndPoint local_address_;
@@ -95,8 +105,10 @@ class FakeSocket : public net::StreamSocket {
FakeSocket::FakeSocket(std::string* written_data)
: read_pending_(false),
+ input_pos_(0),
written_data_(written_data),
- input_pos_(0) {
+ async_write_(false),
+ write_pending_(false) {
}
FakeSocket::~FakeSocket() { }
@@ -147,6 +159,17 @@ int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
int FakeSocket::Write(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) {
DCHECK(buf);
+ DCHECK(!write_pending_);
+
+ if (async_write_) {
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::Bind(
+ &FakeSocket::DoAsyncWrite, base::Unretained(this),
+ scoped_refptr<net::IOBuffer>(buf), buf_len, callback));
+ write_pending_ = true;
+ return net::ERR_IO_PENDING;
+ }
+
if (written_data_) {
written_data_->insert(written_data_->end(),
buf->data(), buf->data() + buf_len);
@@ -154,6 +177,16 @@ int FakeSocket::Write(net::IOBuffer* buf, int buf_len,
return buf_len;
}
+void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len,
+ const net::CompletionCallback& callback) {
+ write_pending_ = false;
+
+ if (written_data_) {
+ written_data_->insert(written_data_->end(),
+ buf->data(), buf->data() + buf_len);
+ }
+ callback.Run(buf_len);
+}
bool FakeSocket::SetReceiveBufferSize(int32 size) {
NOTIMPLEMENTED();
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698