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

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

Issue 1197853003: Add P2PDatagramSocket and P2PStreamSocket interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/protocol/fake_datagram_socket.h ('k') | remoting/protocol/fake_stream_socket.h » ('j') | 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/protocol/fake_datagram_socket.h" 5 #include "remoting/protocol/fake_datagram_socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 void FakeDatagramSocket::PairWith(FakeDatagramSocket* peer_socket) { 44 void FakeDatagramSocket::PairWith(FakeDatagramSocket* peer_socket) {
45 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 45 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
46 peer_socket_ = peer_socket->GetWeakPtr(); 46 peer_socket_ = peer_socket->GetWeakPtr();
47 peer_socket->peer_socket_ = GetWeakPtr(); 47 peer_socket->peer_socket_ = GetWeakPtr();
48 } 48 }
49 49
50 base::WeakPtr<FakeDatagramSocket> FakeDatagramSocket::GetWeakPtr() { 50 base::WeakPtr<FakeDatagramSocket> FakeDatagramSocket::GetWeakPtr() {
51 return weak_factory_.GetWeakPtr(); 51 return weak_factory_.GetWeakPtr();
52 } 52 }
53 53
54 int FakeDatagramSocket::Read(net::IOBuffer* buf, int buf_len, 54 int FakeDatagramSocket::Recv(const scoped_refptr<net::IOBuffer>& buf,
55 int buf_len,
55 const net::CompletionCallback& callback) { 56 const net::CompletionCallback& callback) {
56 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 57 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
57 if (input_pos_ < static_cast<int>(input_packets_.size())) { 58 if (input_pos_ < static_cast<int>(input_packets_.size())) {
58 return CopyReadData(buf, buf_len); 59 return CopyReadData(buf, buf_len);
59 } else { 60 } else {
60 read_buffer_ = buf; 61 read_buffer_ = buf;
61 read_buffer_size_ = buf_len; 62 read_buffer_size_ = buf_len;
62 read_callback_ = callback; 63 read_callback_ = callback;
63 return net::ERR_IO_PENDING; 64 return net::ERR_IO_PENDING;
64 } 65 }
65 } 66 }
66 67
67 int FakeDatagramSocket::Write(net::IOBuffer* buf, int buf_len, 68 int FakeDatagramSocket::Send(const scoped_refptr<net::IOBuffer>& buf,
68 const net::CompletionCallback& callback) { 69 int buf_len,
70 const net::CompletionCallback& callback) {
69 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 71 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
70 written_packets_.push_back(std::string()); 72 written_packets_.push_back(std::string());
71 written_packets_.back().assign(buf->data(), buf->data() + buf_len); 73 written_packets_.back().assign(buf->data(), buf->data() + buf_len);
72 74
73 if (peer_socket_.get()) { 75 if (peer_socket_.get()) {
74 task_runner_->PostTask( 76 task_runner_->PostTask(
75 FROM_HERE, 77 FROM_HERE,
76 base::Bind(&FakeDatagramSocket::AppendInputPacket, 78 base::Bind(&FakeDatagramSocket::AppendInputPacket, peer_socket_,
77 peer_socket_,
78 std::string(buf->data(), buf->data() + buf_len))); 79 std::string(buf->data(), buf->data() + buf_len)));
79 } 80 }
80 81
81 return buf_len; 82 return buf_len;
82 } 83 }
83 84
84 int FakeDatagramSocket::SetReceiveBufferSize(int32 size) { 85 int FakeDatagramSocket::CopyReadData(const scoped_refptr<net::IOBuffer>& buf,
85 NOTIMPLEMENTED(); 86 int buf_len) {
86 return net::ERR_NOT_IMPLEMENTED;
87 }
88
89 int FakeDatagramSocket::SetSendBufferSize(int32 size) {
90 NOTIMPLEMENTED();
91 return net::ERR_NOT_IMPLEMENTED;
92 }
93
94 int FakeDatagramSocket::CopyReadData(net::IOBuffer* buf, int buf_len) {
95 int size = std::min( 87 int size = std::min(
96 buf_len, static_cast<int>(input_packets_[input_pos_].size())); 88 buf_len, static_cast<int>(input_packets_[input_pos_].size()));
97 memcpy(buf->data(), &(*input_packets_[input_pos_].begin()), size); 89 memcpy(buf->data(), &(*input_packets_[input_pos_].begin()), size);
98 ++input_pos_; 90 ++input_pos_;
99 return size; 91 return size;
100 } 92 }
101 93
102 FakeDatagramChannelFactory::FakeDatagramChannelFactory() 94 FakeDatagramChannelFactory::FakeDatagramChannelFactory()
103 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 95 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
104 asynchronous_create_(false), 96 asynchronous_create_(false),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 callback.Run(owned_socket.Pass()); 152 callback.Run(owned_socket.Pass());
161 } 153 }
162 154
163 void FakeDatagramChannelFactory::CancelChannelCreation( 155 void FakeDatagramChannelFactory::CancelChannelCreation(
164 const std::string& name) { 156 const std::string& name) {
165 channels_.erase(name); 157 channels_.erase(name);
166 } 158 }
167 159
168 } // namespace protocol 160 } // namespace protocol
169 } // namespace remoting 161 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/fake_datagram_socket.h ('k') | remoting/protocol/fake_stream_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698