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/p2p/socket_host_tcp_server.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
11 #include "content/common/p2p_messages.h" | 11 #include "content/common/p2p_messages.h" |
12 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 #include "net/socket/stream_socket.h" | 15 #include "net/socket/stream_socket.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 const int kListenBacklog = 5; | 18 const int kListenBacklog = 5; |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 P2PSocketHostTcpServer::P2PSocketHostTcpServer( | 23 P2PSocketHostTcpServer::P2PSocketHostTcpServer(IPC::Sender* message_sender, |
24 IPC::Sender* message_sender, int id, P2PSocketType client_type) | 24 int socket_id, |
25 : P2PSocketHost(message_sender, id), | 25 int render_process_host_id, |
| 26 P2PSocketType client_type) |
| 27 : P2PSocketHost(message_sender, socket_id, render_process_host_id), |
26 client_type_(client_type), | 28 client_type_(client_type), |
27 socket_(new net::TCPServerSocket(NULL, net::NetLog::Source())), | 29 socket_(new net::TCPServerSocket(NULL, net::NetLog::Source())), |
28 accept_callback_( | 30 accept_callback_(base::Bind(&P2PSocketHostTcpServer::OnAccepted, |
29 base::Bind(&P2PSocketHostTcpServer::OnAccepted, | 31 base::Unretained(this))) { |
30 base::Unretained(this))) { | |
31 } | 32 } |
32 | 33 |
33 P2PSocketHostTcpServer::~P2PSocketHostTcpServer() { | 34 P2PSocketHostTcpServer::~P2PSocketHostTcpServer() { |
34 STLDeleteContainerPairSecondPointers(accepted_sockets_.begin(), | 35 STLDeleteContainerPairSecondPointers(accepted_sockets_.begin(), |
35 accepted_sockets_.end()); | 36 accepted_sockets_.end()); |
36 | 37 |
37 if (state_ == STATE_OPEN) { | 38 if (state_ == STATE_OPEN) { |
38 DCHECK(socket_.get()); | 39 DCHECK(socket_.get()); |
39 socket_.reset(); | 40 socket_.reset(); |
40 } | 41 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 const net::IPEndPoint& remote_address, int id) { | 127 const net::IPEndPoint& remote_address, int id) { |
127 AcceptedSocketsMap::iterator it = accepted_sockets_.find(remote_address); | 128 AcceptedSocketsMap::iterator it = accepted_sockets_.find(remote_address); |
128 if (it == accepted_sockets_.end()) | 129 if (it == accepted_sockets_.end()) |
129 return NULL; | 130 return NULL; |
130 | 131 |
131 net::StreamSocket* socket = it->second; | 132 net::StreamSocket* socket = it->second; |
132 accepted_sockets_.erase(it); | 133 accepted_sockets_.erase(it); |
133 | 134 |
134 scoped_ptr<P2PSocketHostTcpBase> result; | 135 scoped_ptr<P2PSocketHostTcpBase> result; |
135 if (client_type_ == P2P_SOCKET_TCP_CLIENT) { | 136 if (client_type_ == P2P_SOCKET_TCP_CLIENT) { |
136 result.reset(new P2PSocketHostTcp(message_sender_, id, client_type_, NULL)); | 137 result.reset(new P2PSocketHostTcp( |
| 138 message_sender_, id, render_process_host_id_, client_type_, NULL)); |
137 } else { | 139 } else { |
138 result.reset(new P2PSocketHostStunTcp( | 140 result.reset(new P2PSocketHostStunTcp( |
139 message_sender_, id, client_type_, NULL)); | 141 message_sender_, id, render_process_host_id_, client_type_, NULL)); |
140 } | 142 } |
141 if (!result->InitAccepted(remote_address, socket)) | 143 if (!result->InitAccepted(remote_address, socket)) |
142 return NULL; | 144 return NULL; |
143 return result.release(); | 145 return result.release(); |
144 } | 146 } |
145 | 147 |
146 bool P2PSocketHostTcpServer::SetOption(P2PSocketOption option, | 148 bool P2PSocketHostTcpServer::SetOption(P2PSocketOption option, |
147 int value) { | 149 int value) { |
148 // Currently we don't have use case tcp server sockets are used for p2p. | 150 // Currently we don't have use case tcp server sockets are used for p2p. |
149 return false; | 151 return false; |
150 } | 152 } |
151 | 153 |
152 } // namespace content | 154 } // namespace content |
OLD | NEW |