| 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/renderer/p2p/ipc_socket_factory.h" | 5 #include "content/renderer/p2p/ipc_socket_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // Always takes ownership of client even if initialization fails. | 72 // Always takes ownership of client even if initialization fails. |
| 73 bool Init(P2PSocketType type, P2PSocketClientImpl* client, | 73 bool Init(P2PSocketType type, P2PSocketClientImpl* client, |
| 74 const talk_base::SocketAddress& local_address, | 74 const talk_base::SocketAddress& local_address, |
| 75 const talk_base::SocketAddress& remote_address); | 75 const talk_base::SocketAddress& remote_address); |
| 76 | 76 |
| 77 // talk_base::AsyncPacketSocket interface. | 77 // talk_base::AsyncPacketSocket interface. |
| 78 virtual talk_base::SocketAddress GetLocalAddress() const OVERRIDE; | 78 virtual talk_base::SocketAddress GetLocalAddress() const OVERRIDE; |
| 79 virtual talk_base::SocketAddress GetRemoteAddress() const OVERRIDE; | 79 virtual talk_base::SocketAddress GetRemoteAddress() const OVERRIDE; |
| 80 virtual int Send(const void *pv, size_t cb, | 80 virtual int Send(const void *pv, size_t cb, |
| 81 talk_base::DiffServCodePoint dscp) OVERRIDE; | 81 const talk_base::PacketOptions& options) OVERRIDE; |
| 82 virtual int SendTo(const void *pv, size_t cb, | 82 virtual int SendTo(const void *pv, size_t cb, |
| 83 const talk_base::SocketAddress& addr, | 83 const talk_base::SocketAddress& addr, |
| 84 talk_base::DiffServCodePoint dscp) OVERRIDE; | 84 const talk_base::PacketOptions& options) OVERRIDE; |
| 85 virtual int Close() OVERRIDE; | 85 virtual int Close() OVERRIDE; |
| 86 virtual State GetState() const OVERRIDE; | 86 virtual State GetState() const OVERRIDE; |
| 87 virtual int GetOption(talk_base::Socket::Option option, int* value) OVERRIDE; | 87 virtual int GetOption(talk_base::Socket::Option option, int* value) OVERRIDE; |
| 88 virtual int SetOption(talk_base::Socket::Option option, int value) OVERRIDE; | 88 virtual int SetOption(talk_base::Socket::Option option, int value) OVERRIDE; |
| 89 virtual int GetError() const OVERRIDE; | 89 virtual int GetError() const OVERRIDE; |
| 90 virtual void SetError(int error) OVERRIDE; | 90 virtual void SetError(int error) OVERRIDE; |
| 91 | 91 |
| 92 // P2PSocketClientDelegate implementation. | 92 // P2PSocketClientDelegate implementation. |
| 93 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; | 93 virtual void OnOpen(const net::IPEndPoint& address) OVERRIDE; |
| 94 virtual void OnIncomingTcpConnection( | 94 virtual void OnIncomingTcpConnection( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 236 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 237 return local_address_; | 237 return local_address_; |
| 238 } | 238 } |
| 239 | 239 |
| 240 talk_base::SocketAddress IpcPacketSocket::GetRemoteAddress() const { | 240 talk_base::SocketAddress IpcPacketSocket::GetRemoteAddress() const { |
| 241 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 241 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 242 return remote_address_; | 242 return remote_address_; |
| 243 } | 243 } |
| 244 | 244 |
| 245 int IpcPacketSocket::Send(const void *data, size_t data_size, | 245 int IpcPacketSocket::Send(const void *data, size_t data_size, |
| 246 talk_base::DiffServCodePoint dscp) { | 246 const talk_base::PacketOptions& options) { |
| 247 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 247 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 248 return SendTo(data, data_size, remote_address_, dscp); | 248 return SendTo(data, data_size, remote_address_, options); |
| 249 } | 249 } |
| 250 | 250 |
| 251 int IpcPacketSocket::SendTo(const void *data, size_t data_size, | 251 int IpcPacketSocket::SendTo(const void *data, size_t data_size, |
| 252 const talk_base::SocketAddress& address, | 252 const talk_base::SocketAddress& address, |
| 253 talk_base::DiffServCodePoint dscp) { | 253 const talk_base::PacketOptions& options) { |
| 254 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 254 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 255 | 255 |
| 256 switch (state_) { | 256 switch (state_) { |
| 257 case IS_UNINITIALIZED: | 257 case IS_UNINITIALIZED: |
| 258 NOTREACHED(); | 258 NOTREACHED(); |
| 259 return EWOULDBLOCK; | 259 return EWOULDBLOCK; |
| 260 case IS_OPENING: | 260 case IS_OPENING: |
| 261 return EWOULDBLOCK; | 261 return EWOULDBLOCK; |
| 262 case IS_CLOSED: | 262 case IS_CLOSED: |
| 263 return ENOTCONN; | 263 return ENOTCONN; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 290 return -1; | 290 return -1; |
| 291 } | 291 } |
| 292 | 292 |
| 293 send_bytes_available_ -= data_size; | 293 send_bytes_available_ -= data_size; |
| 294 in_flight_packet_sizes_.push_back(data_size); | 294 in_flight_packet_sizes_.push_back(data_size); |
| 295 TraceSendThrottlingState(); | 295 TraceSendThrottlingState(); |
| 296 | 296 |
| 297 const char* data_char = reinterpret_cast<const char*>(data); | 297 const char* data_char = reinterpret_cast<const char*>(data); |
| 298 std::vector<char> data_vector(data_char, data_char + data_size); | 298 std::vector<char> data_vector(data_char, data_char + data_size); |
| 299 client_->SendWithDscp(address_chrome, data_vector, | 299 client_->SendWithDscp(address_chrome, data_vector, |
| 300 static_cast<net::DiffServCodePoint>(dscp)); | 300 static_cast<net::DiffServCodePoint>(options.dscp)); |
| 301 | 301 |
| 302 // Fake successful send. The caller ignores result anyway. | 302 // Fake successful send. The caller ignores result anyway. |
| 303 return data_size; | 303 return data_size; |
| 304 } | 304 } |
| 305 | 305 |
| 306 int IpcPacketSocket::Close() { | 306 int IpcPacketSocket::Close() { |
| 307 DCHECK_EQ(base::MessageLoop::current(), message_loop_); | 307 DCHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 308 | 308 |
| 309 client_->Close(); | 309 client_->Close(); |
| 310 state_ = IS_CLOSED; | 310 state_ = IS_CLOSED; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 return NULL; | 532 return NULL; |
| 533 return socket.release(); | 533 return socket.release(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 talk_base::AsyncResolverInterface* | 536 talk_base::AsyncResolverInterface* |
| 537 IpcPacketSocketFactory::CreateAsyncResolver() { | 537 IpcPacketSocketFactory::CreateAsyncResolver() { |
| 538 return new P2PAsyncAddressResolver(socket_dispatcher_); | 538 return new P2PAsyncAddressResolver(socket_dispatcher_); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace content | 541 } // namespace content |
| OLD | NEW |