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_tcp_server_socket.h" | 5 #include "content/browser/renderer_host/pepper_tcp_server_socket.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/browser/renderer_host/pepper_message_filter.h" | 10 #include "content/browser/renderer_host/pepper_message_filter.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 state_ = LISTEN_IN_PROGRESS; | 52 state_ = LISTEN_IN_PROGRESS; |
53 | 53 |
54 socket_.reset(new net::TCPServerSocket(NULL, net::NetLog::Source())); | 54 socket_.reset(new net::TCPServerSocket(NULL, net::NetLog::Source())); |
55 int result = socket_->Listen(ip_end_point, backlog); | 55 int result = socket_->Listen(ip_end_point, backlog); |
56 if (result != net::ERR_IO_PENDING) | 56 if (result != net::ERR_IO_PENDING) |
57 OnListenCompleted(result); | 57 OnListenCompleted(result); |
58 } | 58 } |
59 | 59 |
60 void PepperTCPServerSocket::Accept() { | 60 void PepperTCPServerSocket::Accept(int32 tcp_client_sockets_routing_id) { |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
62 | 62 |
63 if (state_ != LISTENING) { | 63 if (state_ != LISTENING) { |
64 SendAcceptACKError(); | 64 SendAcceptACKError(); |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 state_ = ACCEPT_IN_PROGRESS; | 68 state_ = ACCEPT_IN_PROGRESS; |
69 | 69 |
70 int result = socket_->Accept( | 70 int result = socket_->Accept( |
71 &socket_buffer_, | 71 &socket_buffer_, |
72 base::Bind(&PepperTCPServerSocket::OnAcceptCompleted, | 72 base::Bind(&PepperTCPServerSocket::OnAcceptCompleted, |
73 base::Unretained(this))); | 73 base::Unretained(this), |
| 74 tcp_client_sockets_routing_id)); |
74 if (result != net::ERR_IO_PENDING) | 75 if (result != net::ERR_IO_PENDING) |
75 OnAcceptCompleted(result); | 76 OnAcceptCompleted(tcp_client_sockets_routing_id, result); |
76 } | 77 } |
77 | 78 |
78 void PepperTCPServerSocket::CancelListenRequest() { | 79 void PepperTCPServerSocket::CancelListenRequest() { |
79 manager_->Send(new PpapiMsg_PPBTCPServerSocket_ListenACK( | 80 manager_->Send(new PpapiMsg_PPBTCPServerSocket_ListenACK( |
80 routing_id_, | 81 routing_id_, |
81 plugin_dispatcher_id_, | 82 plugin_dispatcher_id_, |
82 0, | 83 0, |
83 temp_socket_id_, | 84 temp_socket_id_, |
84 PP_ERROR_FAILED)); | 85 PP_ERROR_FAILED)); |
85 BrowserThread::PostTask( | 86 BrowserThread::PostTask( |
(...skipping 22 matching lines...) Expand all Loading... |
108 manager_->Send(new PpapiMsg_PPBTCPServerSocket_ListenACK( | 109 manager_->Send(new PpapiMsg_PPBTCPServerSocket_ListenACK( |
109 routing_id_, | 110 routing_id_, |
110 plugin_dispatcher_id_, | 111 plugin_dispatcher_id_, |
111 real_socket_id_, | 112 real_socket_id_, |
112 temp_socket_id_, | 113 temp_socket_id_, |
113 PP_OK)); | 114 PP_OK)); |
114 state_ = LISTENING; | 115 state_ = LISTENING; |
115 } | 116 } |
116 } | 117 } |
117 | 118 |
118 void PepperTCPServerSocket::OnAcceptCompleted(int result) { | 119 void PepperTCPServerSocket::OnAcceptCompleted( |
| 120 int32 tcp_client_sockets_routing_id, |
| 121 int result) { |
119 DCHECK(state_ == ACCEPT_IN_PROGRESS && socket_buffer_.get()); | 122 DCHECK(state_ == ACCEPT_IN_PROGRESS && socket_buffer_.get()); |
120 | 123 |
121 if (result != net::OK) { | 124 if (result != net::OK) { |
122 SendAcceptACKError(); | 125 SendAcceptACKError(); |
123 } else { | 126 } else { |
124 scoped_ptr<net::StreamSocket> socket(socket_buffer_.release()); | 127 scoped_ptr<net::StreamSocket> socket(socket_buffer_.release()); |
125 | 128 |
126 net::IPEndPoint ip_end_point; | 129 net::IPEndPoint ip_end_point; |
127 net::AddressList address_list; | 130 net::AddressList address_list; |
128 PP_NetAddress_Private local_addr = | 131 PP_NetAddress_Private local_addr = |
129 NetAddressPrivateImpl::kInvalidNetAddress; | 132 NetAddressPrivateImpl::kInvalidNetAddress; |
130 PP_NetAddress_Private remote_addr = | 133 PP_NetAddress_Private remote_addr = |
131 NetAddressPrivateImpl::kInvalidNetAddress; | 134 NetAddressPrivateImpl::kInvalidNetAddress; |
132 | 135 |
133 if (socket->GetLocalAddress(&ip_end_point) != net::OK || | 136 if (socket->GetLocalAddress(&ip_end_point) != net::OK || |
134 !NetAddressPrivateImpl::IPEndPointToNetAddress(ip_end_point, | 137 !NetAddressPrivateImpl::IPEndPointToNetAddress(ip_end_point, |
135 &local_addr) || | 138 &local_addr) || |
136 socket->GetPeerAddress(&address_list) != net::OK || | 139 socket->GetPeerAddress(&address_list) != net::OK || |
137 !NetAddressPrivateImpl::AddressListToNetAddress(address_list, | 140 !NetAddressPrivateImpl::AddressListToNetAddress(address_list, |
138 &remote_addr)) { | 141 &remote_addr)) { |
139 SendAcceptACKError(); | 142 SendAcceptACKError(); |
140 } else { | 143 } else { |
141 uint32 accepted_socket_id = | 144 uint32 accepted_socket_id = |
142 manager_->AddAcceptedTCPSocket(routing_id_, | 145 manager_->AddAcceptedTCPSocket(tcp_client_sockets_routing_id, |
143 plugin_dispatcher_id_, | 146 plugin_dispatcher_id_, |
144 socket.release()); | 147 socket.release()); |
145 if (accepted_socket_id != 0) { | 148 if (accepted_socket_id != 0) { |
146 manager_->Send(new PpapiMsg_PPBTCPServerSocket_AcceptACK( | 149 manager_->Send(new PpapiMsg_PPBTCPServerSocket_AcceptACK( |
147 routing_id_, | 150 routing_id_, |
148 plugin_dispatcher_id_, | 151 plugin_dispatcher_id_, |
149 real_socket_id_, | 152 real_socket_id_, |
150 accepted_socket_id, | 153 accepted_socket_id, |
151 local_addr, | 154 local_addr, |
152 remote_addr)); | 155 remote_addr)); |
153 } else { | 156 } else { |
154 SendAcceptACKError(); | 157 SendAcceptACKError(); |
155 } | 158 } |
156 } | 159 } |
157 } | 160 } |
158 | 161 |
159 state_ = LISTENING; | 162 state_ = LISTENING; |
160 } | 163 } |
OLD | NEW |