OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/pepper/pepper_tcp_socket.h" | 5 #include "content/browser/renderer_host/pepper/pepper_tcp_socket.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 NOTREACHED(); | 189 NOTREACHED(); |
190 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize; | 190 data_size = ppapi::TCPSocketPrivateImpl::kMaxWriteSize; |
191 } | 191 } |
192 | 192 |
193 write_buffer_base_ = new net::IOBuffer(data_size); | 193 write_buffer_base_ = new net::IOBuffer(data_size); |
194 memcpy(write_buffer_base_->data(), data.data(), data_size); | 194 memcpy(write_buffer_base_->data(), data.data(), data_size); |
195 write_buffer_ = new net::DrainableIOBuffer(write_buffer_base_, data_size); | 195 write_buffer_ = new net::DrainableIOBuffer(write_buffer_base_, data_size); |
196 DoWrite(); | 196 DoWrite(); |
197 } | 197 } |
198 | 198 |
199 void PepperTCPSocket::SetBoolFeature(uint32_t name, bool value) { | |
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
201 DCHECK(socket_.get()); | |
202 | |
203 switch (static_cast<PP_TCPSocketFeature_Private>(name)) { | |
204 case PP_TCPSOCKETFEATURE_NO_DELAY: | |
yzshen1
2013/02/08 21:51:11
wrong indent.
Wez
2013/02/10 04:47:02
Done.
| |
205 if (!IsSsl()) { | |
206 SendSetBoolFeatureACK( | |
207 static_cast<net::TCPClientSocket*>(socket_.get())->SetNoDelay(value)); | |
208 } else { | |
209 SendSetBoolFeatureACK(false); | |
210 } | |
211 return; | |
212 default: | |
213 break; | |
214 } | |
215 | |
216 NOTREACHED(); | |
217 SendSetBoolFeatureACK(false); | |
218 } | |
219 | |
199 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) { | 220 void PepperTCPSocket::StartConnect(const net::AddressList& addresses) { |
200 DCHECK(connection_state_ == CONNECT_IN_PROGRESS); | 221 DCHECK(connection_state_ == CONNECT_IN_PROGRESS); |
201 | 222 |
202 socket_.reset( | 223 socket_.reset(new net::TCPClientSocket(addresses, NULL, |
203 new net::TCPClientSocket(addresses, NULL, net::NetLog::Source())); | 224 net::NetLog::Source())); |
204 int result = socket_->Connect( | 225 int result = socket_->Connect( |
205 base::Bind(&PepperTCPSocket::OnConnectCompleted, | 226 base::Bind(&PepperTCPSocket::OnConnectCompleted, |
206 base::Unretained(this))); | 227 base::Unretained(this))); |
207 if (result != net::ERR_IO_PENDING) | 228 if (result != net::ERR_IO_PENDING) |
208 OnConnectCompleted(result); | 229 OnConnectCompleted(result); |
209 } | 230 } |
210 | 231 |
211 void PepperTCPSocket::SendConnectACKError() { | 232 void PepperTCPSocket::SendConnectACKError() { |
212 manager_->Send(new PpapiMsg_PPBTCPSocket_ConnectACK( | 233 manager_->Send(new PpapiMsg_PPBTCPSocket_ConnectACK( |
213 routing_id_, plugin_dispatcher_id_, socket_id_, false, | 234 routing_id_, plugin_dispatcher_id_, socket_id_, false, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 } | 419 } |
399 | 420 |
400 write_buffer_ = NULL; | 421 write_buffer_ = NULL; |
401 write_buffer_base_ = NULL; | 422 write_buffer_base_ = NULL; |
402 } | 423 } |
403 | 424 |
404 bool PepperTCPSocket::IsConnected() const { | 425 bool PepperTCPSocket::IsConnected() const { |
405 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED; | 426 return connection_state_ == CONNECTED || connection_state_ == SSL_CONNECTED; |
406 } | 427 } |
407 | 428 |
429 bool PepperTCPSocket::IsSsl() const { | |
430 return connection_state_ == SSL_HANDSHAKE_IN_PROGRESS || | |
431 connection_state_ == SSL_CONNECTED || | |
yzshen1
2013/02/08 21:51:11
wrong indent.
Wez
2013/02/10 04:47:02
Done.
| |
432 connection_state_ == SSL_HANDSHAKE_FAILED; | |
433 } | |
434 | |
408 void PepperTCPSocket::DoWrite() { | 435 void PepperTCPSocket::DoWrite() { |
409 DCHECK(write_buffer_base_.get()); | 436 DCHECK(write_buffer_base_.get()); |
410 DCHECK(write_buffer_.get()); | 437 DCHECK(write_buffer_.get()); |
411 DCHECK_GT(write_buffer_->BytesRemaining(), 0); | 438 DCHECK_GT(write_buffer_->BytesRemaining(), 0); |
412 | 439 |
413 int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(), | 440 int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(), |
414 base::Bind(&PepperTCPSocket::OnWriteCompleted, | 441 base::Bind(&PepperTCPSocket::OnWriteCompleted, |
415 base::Unretained(this))); | 442 base::Unretained(this))); |
416 if (result != net::ERR_IO_PENDING) | 443 if (result != net::ERR_IO_PENDING) |
417 OnWriteCompleted(result); | 444 OnWriteCompleted(result); |
418 } | 445 } |
419 | 446 |
420 } // namespace content | 447 } // namespace content |
OLD | NEW |