OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "net/websockets/websocket.h" | 8 #include "net/websockets/websocket.h" |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void WebSocket::OnConnected(SocketStream* socket_stream, | 102 void WebSocket::OnConnected(SocketStream* socket_stream, |
103 int max_pending_send_allowed) { | 103 int max_pending_send_allowed) { |
104 DCHECK(socket_stream == socket_stream_); | 104 DCHECK(socket_stream == socket_stream_); |
105 max_pending_send_allowed_ = max_pending_send_allowed; | 105 max_pending_send_allowed_ = max_pending_send_allowed; |
106 | 106 |
107 // Use |max_pending_send_allowed| as hint for initial size of read buffer. | 107 // Use |max_pending_send_allowed| as hint for initial size of read buffer. |
108 current_read_buf_ = new GrowableIOBuffer(); | 108 current_read_buf_ = new GrowableIOBuffer(); |
109 current_read_buf_->set_capacity(max_pending_send_allowed_); | 109 current_read_buf_->SetCapacity(max_pending_send_allowed_); |
110 read_consumed_len_ = 0; | 110 read_consumed_len_ = 0; |
111 | 111 |
112 DCHECK(!current_write_buf_); | 112 DCHECK(!current_write_buf_); |
113 pending_write_bufs_.push_back(CreateClientHandshakeMessage()); | 113 pending_write_bufs_.push_back(CreateClientHandshakeMessage()); |
114 origin_loop_->PostTask(FROM_HERE, | 114 origin_loop_->PostTask(FROM_HERE, |
115 NewRunnableMethod(this, &WebSocket::SendPending)); | 115 NewRunnableMethod(this, &WebSocket::SendPending)); |
116 } | 116 } |
117 | 117 |
118 void WebSocket::OnSentData(SocketStream* socket_stream, int amount_sent) { | 118 void WebSocket::OnSentData(SocketStream* socket_stream, int amount_sent) { |
119 DCHECK(socket_stream == socket_stream_); | 119 DCHECK(socket_stream == socket_stream_); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 394 } |
395 } | 395 } |
396 } | 396 } |
397 SkipReadBuffer(next_frame - start_frame); | 397 SkipReadBuffer(next_frame - start_frame); |
398 } | 398 } |
399 | 399 |
400 void WebSocket::AddToReadBuffer(const char* data, int len) { | 400 void WebSocket::AddToReadBuffer(const char* data, int len) { |
401 DCHECK(current_read_buf_); | 401 DCHECK(current_read_buf_); |
402 // Check if |current_read_buf_| has enough space to store |len| of |data|. | 402 // Check if |current_read_buf_| has enough space to store |len| of |data|. |
403 if (len >= current_read_buf_->RemainingCapacity()) { | 403 if (len >= current_read_buf_->RemainingCapacity()) { |
404 current_read_buf_->set_capacity( | 404 current_read_buf_->SetCapacity( |
405 current_read_buf_->offset() + len); | 405 current_read_buf_->offset() + len); |
406 } | 406 } |
407 | 407 |
408 DCHECK(current_read_buf_->RemainingCapacity() >= len); | 408 DCHECK(current_read_buf_->RemainingCapacity() >= len); |
409 memcpy(current_read_buf_->data(), data, len); | 409 memcpy(current_read_buf_->data(), data, len); |
410 current_read_buf_->set_offset(current_read_buf_->offset() + len); | 410 current_read_buf_->set_offset(current_read_buf_->offset() + len); |
411 } | 411 } |
412 | 412 |
413 void WebSocket::SkipReadBuffer(int len) { | 413 void WebSocket::SkipReadBuffer(int len) { |
414 if (len == 0) | 414 if (len == 0) |
(...skipping 25 matching lines...) Expand all Loading... |
440 WebSocketDelegate* delegate = delegate_; | 440 WebSocketDelegate* delegate = delegate_; |
441 delegate_ = NULL; | 441 delegate_ = NULL; |
442 ready_state_ = CLOSED; | 442 ready_state_ = CLOSED; |
443 if (!socket_stream_) | 443 if (!socket_stream_) |
444 return; | 444 return; |
445 socket_stream_ = NULL; | 445 socket_stream_ = NULL; |
446 delegate->OnClose(this); | 446 delegate->OnClose(this); |
447 } | 447 } |
448 | 448 |
449 } // namespace net | 449 } // namespace net |
OLD | NEW |