OLD | NEW |
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 Loading... |
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(net::IOBuffer* buf, int buf_len, |
55 const net::CompletionCallback& callback) { | 55 const net::CompletionCallback& callback) { |
56 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 56 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
57 if (input_pos_ < static_cast<int>(input_packets_.size())) { | 57 if (input_pos_ < static_cast<int>(input_packets_.size())) { |
58 return CopyReadData(buf, buf_len); | 58 return CopyReadData(buf, buf_len); |
59 } else { | 59 } else { |
60 read_buffer_ = buf; | 60 read_buffer_ = buf; |
61 read_buffer_size_ = buf_len; | 61 read_buffer_size_ = buf_len; |
62 read_callback_ = callback; | 62 read_callback_ = callback; |
63 return net::ERR_IO_PENDING; | 63 return net::ERR_IO_PENDING; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 int FakeDatagramSocket::Write(net::IOBuffer* buf, int buf_len, | 67 int FakeDatagramSocket::Send(net::IOBuffer* buf, int buf_len, |
68 const net::CompletionCallback& callback) { | 68 const net::CompletionCallback& callback) { |
69 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 69 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
70 written_packets_.push_back(std::string()); | 70 written_packets_.push_back(std::string()); |
71 written_packets_.back().assign(buf->data(), buf->data() + buf_len); | 71 written_packets_.back().assign(buf->data(), buf->data() + buf_len); |
72 | 72 |
73 if (peer_socket_.get()) { | 73 if (peer_socket_.get()) { |
74 task_runner_->PostTask( | 74 task_runner_->PostTask( |
75 FROM_HERE, | 75 FROM_HERE, |
76 base::Bind(&FakeDatagramSocket::AppendInputPacket, | 76 base::Bind(&FakeDatagramSocket::AppendInputPacket, peer_socket_, |
77 peer_socket_, | |
78 std::string(buf->data(), buf->data() + buf_len))); | 77 std::string(buf->data(), buf->data() + buf_len))); |
79 } | 78 } |
80 | 79 |
81 return buf_len; | 80 return buf_len; |
82 } | 81 } |
83 | 82 |
84 int FakeDatagramSocket::SetReceiveBufferSize(int32 size) { | |
85 NOTIMPLEMENTED(); | |
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) { | 83 int FakeDatagramSocket::CopyReadData(net::IOBuffer* buf, int buf_len) { |
95 int size = std::min( | 84 int size = std::min( |
96 buf_len, static_cast<int>(input_packets_[input_pos_].size())); | 85 buf_len, static_cast<int>(input_packets_[input_pos_].size())); |
97 memcpy(buf->data(), &(*input_packets_[input_pos_].begin()), size); | 86 memcpy(buf->data(), &(*input_packets_[input_pos_].begin()), size); |
98 ++input_pos_; | 87 ++input_pos_; |
99 return size; | 88 return size; |
100 } | 89 } |
101 | 90 |
102 FakeDatagramChannelFactory::FakeDatagramChannelFactory() | 91 FakeDatagramChannelFactory::FakeDatagramChannelFactory() |
103 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 92 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 callback.Run(owned_socket.Pass()); | 149 callback.Run(owned_socket.Pass()); |
161 } | 150 } |
162 | 151 |
163 void FakeDatagramChannelFactory::CancelChannelCreation( | 152 void FakeDatagramChannelFactory::CancelChannelCreation( |
164 const std::string& name) { | 153 const std::string& name) { |
165 channels_.erase(name); | 154 channels_.erase(name); |
166 } | 155 } |
167 | 156 |
168 } // namespace protocol | 157 } // namespace protocol |
169 } // namespace remoting | 158 } // namespace remoting |
OLD | NEW |