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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 read_buffer_size_ = buf_len; | 62 read_buffer_size_ = buf_len; |
63 read_callback_ = callback; | 63 read_callback_ = callback; |
64 return net::ERR_IO_PENDING; | 64 return net::ERR_IO_PENDING; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 int FakeDatagramSocket::Send(const scoped_refptr<net::IOBuffer>& buf, | 68 int FakeDatagramSocket::Send(const scoped_refptr<net::IOBuffer>& buf, |
69 int buf_len, | 69 int buf_len, |
70 const net::CompletionCallback& callback) { | 70 const net::CompletionCallback& callback) { |
71 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 71 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
| 72 EXPECT_FALSE(send_pending_); |
| 73 |
| 74 if (async_send_) { |
| 75 send_pending_ = true; |
| 76 task_runner_->PostTask( |
| 77 FROM_HERE, |
| 78 base::Bind(&FakeDatagramSocket::DoAsyncSend, weak_factory_.GetWeakPtr(), |
| 79 buf, buf_len, callback)); |
| 80 return net::ERR_IO_PENDING; |
| 81 } else { |
| 82 return DoSend(buf, buf_len); |
| 83 } |
| 84 } |
| 85 |
| 86 void FakeDatagramSocket::DoAsyncSend(const scoped_refptr<net::IOBuffer>& buf, |
| 87 int buf_len, |
| 88 const net::CompletionCallback& callback) { |
| 89 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
| 90 |
| 91 EXPECT_TRUE(send_pending_); |
| 92 send_pending_ = false; |
| 93 callback.Run(DoSend(buf, buf_len)); |
| 94 } |
| 95 |
| 96 int FakeDatagramSocket::DoSend(const scoped_refptr<net::IOBuffer>& buf, |
| 97 int buf_len) { |
| 98 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
| 99 |
| 100 if (next_send_error_ != net::OK) { |
| 101 int r = next_send_error_; |
| 102 next_send_error_ = net::OK; |
| 103 return r; |
| 104 } |
| 105 |
72 written_packets_.push_back(std::string()); | 106 written_packets_.push_back(std::string()); |
73 written_packets_.back().assign(buf->data(), buf->data() + buf_len); | 107 written_packets_.back().assign(buf->data(), buf->data() + buf_len); |
74 | 108 |
75 if (peer_socket_.get()) { | 109 if (peer_socket_.get()) { |
76 task_runner_->PostTask( | 110 task_runner_->PostTask( |
77 FROM_HERE, | 111 FROM_HERE, |
78 base::Bind(&FakeDatagramSocket::AppendInputPacket, peer_socket_, | 112 base::Bind(&FakeDatagramSocket::AppendInputPacket, peer_socket_, |
79 std::string(buf->data(), buf->data() + buf_len))); | 113 std::string(buf->data(), buf->data() + buf_len))); |
80 } | 114 } |
81 | 115 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 callback.Run(owned_socket.Pass()); | 186 callback.Run(owned_socket.Pass()); |
153 } | 187 } |
154 | 188 |
155 void FakeDatagramChannelFactory::CancelChannelCreation( | 189 void FakeDatagramChannelFactory::CancelChannelCreation( |
156 const std::string& name) { | 190 const std::string& name) { |
157 channels_.erase(name); | 191 channels_.erase(name); |
158 } | 192 } |
159 | 193 |
160 } // namespace protocol | 194 } // namespace protocol |
161 } // namespace remoting | 195 } // namespace remoting |
OLD | NEW |