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" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 void P2PSocketHostTcpServer::HandleAcceptResult(int result) { | 90 void P2PSocketHostTcpServer::HandleAcceptResult(int result) { |
91 if (result < 0) { | 91 if (result < 0) { |
92 if (result != net::ERR_IO_PENDING) | 92 if (result != net::ERR_IO_PENDING) |
93 OnError(); | 93 OnError(); |
94 return; | 94 return; |
95 } | 95 } |
96 | 96 |
97 net::AddressList addr_list; | 97 net::IPEndPoint address; |
98 if (accept_socket_->GetPeerAddress(&addr_list) != net::OK) { | 98 if (accept_socket_->GetPeerAddress(&address) != net::OK) { |
99 LOG(ERROR) << "Failed to get address of an accepted socket."; | 99 LOG(ERROR) << "Failed to get address of an accepted socket."; |
100 accept_socket_.reset(); | 100 accept_socket_.reset(); |
101 return; | 101 return; |
102 } | 102 } |
103 const net::IPEndPoint& address = addr_list.front(); | |
104 AcceptedSocketsMap::iterator it = accepted_sockets_.find(address); | 103 AcceptedSocketsMap::iterator it = accepted_sockets_.find(address); |
105 if (it != accepted_sockets_.end()) | 104 if (it != accepted_sockets_.end()) |
106 delete it->second; | 105 delete it->second; |
107 | 106 |
108 accepted_sockets_[address] = accept_socket_.release(); | 107 accepted_sockets_[address] = accept_socket_.release(); |
109 message_sender_->Send( | 108 message_sender_->Send( |
110 new P2PMsg_OnIncomingTcpConnection(routing_id_, id_, address)); | 109 new P2PMsg_OnIncomingTcpConnection(routing_id_, id_, address)); |
111 } | 110 } |
112 | 111 |
113 void P2PSocketHostTcpServer::OnAccepted(int result) { | 112 void P2PSocketHostTcpServer::OnAccepted(int result) { |
(...skipping 18 matching lines...) Expand all Loading... |
132 accepted_sockets_.erase(it); | 131 accepted_sockets_.erase(it); |
133 scoped_ptr<P2PSocketHostTcp> result( | 132 scoped_ptr<P2PSocketHostTcp> result( |
134 new P2PSocketHostTcp(message_sender_, routing_id_, id)); | 133 new P2PSocketHostTcp(message_sender_, routing_id_, id)); |
135 if (!result->InitAccepted(remote_address, socket)) | 134 if (!result->InitAccepted(remote_address, socket)) |
136 return NULL; | 135 return NULL; |
137 | 136 |
138 return result.release(); | 137 return result.release(); |
139 } | 138 } |
140 | 139 |
141 } // namespace content | 140 } // namespace content |
OLD | NEW |