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/bind.h" | 10 #include "base/bind.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 class ReadWriteTracker { | 219 class ReadWriteTracker { |
220 public: | 220 public: |
221 ReadWriteTracker( | 221 ReadWriteTracker( |
222 net::WebSocketServerSocket* ws, int bytes_to_read, int bytes_to_write) | 222 net::WebSocketServerSocket* ws, int bytes_to_read, int bytes_to_write) |
223 : ws_(ws), | 223 : ws_(ws), |
224 buf_size_(1 << 14), | 224 buf_size_(1 << 14), |
225 read_buf_(new net::IOBuffer(buf_size_)), | 225 read_buf_(new net::IOBuffer(buf_size_)), |
226 write_buf_(new net::IOBuffer(buf_size_)), | 226 write_buf_(new net::IOBuffer(buf_size_)), |
227 bytes_remaining_to_read_(bytes_to_read), | 227 bytes_remaining_to_read_(bytes_to_read), |
228 bytes_remaining_to_write_(bytes_to_write), | 228 bytes_remaining_to_write_(bytes_to_write), |
229 read_initiated_(false), | |
230 write_initiated_(false), | |
231 got_final_zero_(false) { | 229 got_final_zero_(false) { |
232 int rv = ws_->Accept( | 230 int rv = ws_->Accept( |
233 base::Bind(&ReadWriteTracker::OnAccept, base::Unretained(this))); | 231 base::Bind(&ReadWriteTracker::OnAccept, base::Unretained(this))); |
234 if (rv != net::ERR_IO_PENDING) | 232 if (rv != net::ERR_IO_PENDING) |
235 OnAccept(rv); | 233 OnAccept(rv); |
236 } | 234 } |
237 | 235 |
238 ~ReadWriteTracker() { | 236 ~ReadWriteTracker() { |
239 CHECK_EQ(bytes_remaining_to_write_, 0); | 237 CHECK_EQ(bytes_remaining_to_write_, 0); |
240 CHECK_EQ(bytes_remaining_to_read_, 0); | 238 CHECK_EQ(bytes_remaining_to_read_, 0); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 DoRead(); | 301 DoRead(); |
304 } | 302 } |
305 | 303 |
306 private: | 304 private: |
307 net::WebSocketServerSocket* const ws_; | 305 net::WebSocketServerSocket* const ws_; |
308 int const buf_size_; | 306 int const buf_size_; |
309 scoped_refptr<net::IOBuffer> read_buf_; | 307 scoped_refptr<net::IOBuffer> read_buf_; |
310 scoped_refptr<net::IOBuffer> write_buf_; | 308 scoped_refptr<net::IOBuffer> write_buf_; |
311 int bytes_remaining_to_read_; | 309 int bytes_remaining_to_read_; |
312 int bytes_remaining_to_write_; | 310 int bytes_remaining_to_write_; |
313 bool read_initiated_; | |
314 bool write_initiated_; | |
315 bool got_final_zero_; | 311 bool got_final_zero_; |
316 }; | 312 }; |
317 | 313 |
318 } // namespace | 314 } // namespace |
319 | 315 |
320 namespace net { | 316 namespace net { |
321 | 317 |
322 class WebSocketServerSocketTest : public testing::Test { | 318 class WebSocketServerSocketTest : public testing::Test { |
323 public: | 319 public: |
324 virtual ~WebSocketServerSocketTest() { | 320 virtual ~WebSocketServerSocketTest() { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 MessageLoop::current()->RunAllPending(); | 582 MessageLoop::current()->RunAllPending(); |
587 | 583 |
588 for (size_t i = kill_list.size(); i--;) | 584 for (size_t i = kill_list.size(); i--;) |
589 delete kill_list[i]; | 585 delete kill_list[i]; |
590 for (size_t i = tracker_list.size(); i--;) | 586 for (size_t i = tracker_list.size(); i--;) |
591 delete tracker_list[i]; | 587 delete tracker_list[i]; |
592 MessageLoop::current()->RunAllPending(); | 588 MessageLoop::current()->RunAllPending(); |
593 } | 589 } |
594 | 590 |
595 } // namespace net | 591 } // namespace net |
OLD | NEW |