OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/socket/web_socket_server_socket.h" | 5 #include "net/socket/web_socket_server_socket.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/callback_old.h" | 10 #include "base/callback_old.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 int lot = std::min(remaining, buf_len); | 150 int lot = std::min(remaining, buf_len); |
151 if (GetRand(0, 1)) | 151 if (GetRand(0, 1)) |
152 lot = GetRand(1, lot); | 152 lot = GetRand(1, lot); |
153 std::copy(buf->data(), buf->data() + lot, answer_->data()); | 153 std::copy(buf->data(), buf->data() + lot, answer_->data()); |
154 answer_->DidConsume(lot); | 154 answer_->DidConsume(lot); |
155 if (GetRand(0, 1)) { | 155 if (GetRand(0, 1)) { |
156 return lot; | 156 return lot; |
157 } | 157 } |
158 MessageLoop::current()->PostTask(FROM_HERE, | 158 MessageLoop::current()->PostTask(FROM_HERE, |
159 method_factory_.NewRunnableMethod( | 159 method_factory_.NewRunnableMethod( |
| 160 &TestingTransportSocket::DoOldWriteCallback, callback, lot)); |
| 161 return net::ERR_IO_PENDING; |
| 162 } |
| 163 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 164 const net::CompletionCallback& callback) { |
| 165 CHECK_GT(buf_len, 0); |
| 166 int remaining = answer_->BytesRemaining(); |
| 167 CHECK_GE(remaining, buf_len); |
| 168 int lot = std::min(remaining, buf_len); |
| 169 if (GetRand(0, 1)) |
| 170 lot = GetRand(1, lot); |
| 171 std::copy(buf->data(), buf->data() + lot, answer_->data()); |
| 172 answer_->DidConsume(lot); |
| 173 if (GetRand(0, 1)) { |
| 174 return lot; |
| 175 } |
| 176 MessageLoop::current()->PostTask(FROM_HERE, |
| 177 method_factory_.NewRunnableMethod( |
160 &TestingTransportSocket::DoWriteCallback, callback, lot)); | 178 &TestingTransportSocket::DoWriteCallback, callback, lot)); |
161 return net::ERR_IO_PENDING; | 179 return net::ERR_IO_PENDING; |
162 } | 180 } |
163 | 181 |
164 virtual bool SetReceiveBufferSize(int32 size) { | 182 virtual bool SetReceiveBufferSize(int32 size) { |
165 return true; | 183 return true; |
166 } | 184 } |
167 | 185 |
168 virtual bool SetSendBufferSize(int32 size) { | 186 virtual bool SetSendBufferSize(int32 size) { |
169 return true; | 187 return true; |
(...skipping 15 matching lines...) Expand all Loading... |
185 if (result == 0 && !is_closed_) { | 203 if (result == 0 && !is_closed_) { |
186 MessageLoop::current()->PostTask(FROM_HERE, | 204 MessageLoop::current()->PostTask(FROM_HERE, |
187 method_factory_.NewRunnableMethod( | 205 method_factory_.NewRunnableMethod( |
188 &TestingTransportSocket::DoReadCallback, callback, 0)); | 206 &TestingTransportSocket::DoReadCallback, callback, 0)); |
189 } else { | 207 } else { |
190 if (!callback.is_null()) | 208 if (!callback.is_null()) |
191 callback.Run(result); | 209 callback.Run(result); |
192 } | 210 } |
193 } | 211 } |
194 | 212 |
195 void DoWriteCallback(net::OldCompletionCallback* callback, int result) { | 213 void DoOldWriteCallback(net::OldCompletionCallback* callback, int result) { |
196 if (callback) | 214 if (callback) |
197 callback->Run(result); | 215 callback->Run(result); |
198 } | 216 } |
| 217 void DoWriteCallback(const net::CompletionCallback& callback, int result) { |
| 218 if (!callback.is_null()) |
| 219 callback.Run(result); |
| 220 } |
199 | 221 |
200 bool is_closed_; | 222 bool is_closed_; |
201 | 223 |
202 // Data to return for Read requests. | 224 // Data to return for Read requests. |
203 scoped_refptr<net::DrainableIOBuffer> sample_; | 225 scoped_refptr<net::DrainableIOBuffer> sample_; |
204 | 226 |
205 // Data pushed to us by server socket (using Write calls). | 227 // Data pushed to us by server socket (using Write calls). |
206 scoped_refptr<net::DrainableIOBuffer> answer_; | 228 scoped_refptr<net::DrainableIOBuffer> answer_; |
207 | 229 |
208 // Final read callback to report zero (zero stands for EOF). | 230 // Final read callback to report zero (zero stands for EOF). |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 MessageLoop::current()->RunAllPending(); | 647 MessageLoop::current()->RunAllPending(); |
626 | 648 |
627 for (size_t i = kill_list.size(); i--;) | 649 for (size_t i = kill_list.size(); i--;) |
628 delete kill_list[i]; | 650 delete kill_list[i]; |
629 for (size_t i = tracker_list.size(); i--;) | 651 for (size_t i = tracker_list.size(); i--;) |
630 delete tracker_list[i]; | 652 delete tracker_list[i]; |
631 MessageLoop::current()->RunAllPending(); | 653 MessageLoop::current()->RunAllPending(); |
632 } | 654 } |
633 | 655 |
634 } // namespace net | 656 } // namespace net |
OLD | NEW |