OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_udp_socket.h" | 5 #include "content/browser/renderer_host/pepper_udp_socket.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 net::IPEndPoint address; | 43 net::IPEndPoint address; |
44 if (!socket_.get() || | 44 if (!socket_.get() || |
45 !NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address)) { | 45 !NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address)) { |
46 SendBindACK(false); | 46 SendBindACK(false); |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 int result = socket_->Listen(address); | 50 int result = socket_->Listen(address); |
51 | 51 |
52 // If we are successful, get the local address we bound to. | |
53 if (result == net::OK) { | |
54 socket_->GetLocalAddress(&bound_address_); | |
55 } | |
56 | |
52 SendBindACK(result == net::OK); | 57 SendBindACK(result == net::OK); |
53 } | 58 } |
54 | 59 |
55 void PepperUDPSocket::RecvFrom(int32_t num_bytes) { | 60 void PepperUDPSocket::RecvFrom(int32_t num_bytes) { |
56 if (recvfrom_buffer_.get()) { | 61 if (recvfrom_buffer_.get()) { |
57 SendRecvFromACKError(); | 62 SendRecvFromACKError(); |
58 return; | 63 return; |
59 } | 64 } |
60 | 65 |
61 recvfrom_buffer_ = new net::IOBuffer(num_bytes); | 66 recvfrom_buffer_ = new net::IOBuffer(num_bytes); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string(), | 104 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string(), |
100 addr)); | 105 addr)); |
101 } | 106 } |
102 | 107 |
103 void PepperUDPSocket::SendSendToACKError() { | 108 void PepperUDPSocket::SendSendToACKError() { |
104 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( | 109 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( |
105 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); | 110 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); |
106 } | 111 } |
107 | 112 |
108 void PepperUDPSocket::SendBindACK(bool result) { | 113 void PepperUDPSocket::SendBindACK(bool result) { |
114 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; | |
115 NetAddressPrivateImpl::IPEndPointToNetAddress(bound_address_, &addr); | |
yzshen1
2012/02/06 06:51:27
nit: please check for failure as OnRecvFromComplet
mtilburg1
2012/02/06 15:11:35
Done.
| |
116 | |
109 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( | 117 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( |
110 routing_id_, plugin_dispatcher_id_, socket_id_, result)); | 118 routing_id_, plugin_dispatcher_id_, socket_id_, result, addr)); |
111 } | 119 } |
112 | 120 |
113 void PepperUDPSocket::OnRecvFromCompleted(int result) { | 121 void PepperUDPSocket::OnRecvFromCompleted(int result) { |
114 DCHECK(recvfrom_buffer_.get()); | 122 DCHECK(recvfrom_buffer_.get()); |
115 | 123 |
116 // Convert IPEndPoint we get back from RecvFrom to a PP_NetAddress_Private, | 124 // Convert IPEndPoint we get back from RecvFrom to a PP_NetAddress_Private, |
117 // to send back. | 125 // to send back. |
118 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; | 126 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; |
119 if (result < 0 || | 127 if (result < 0 || |
120 !NetAddressPrivateImpl::IPEndPointToNetAddress(recvfrom_address_, | 128 !NetAddressPrivateImpl::IPEndPointToNetAddress(recvfrom_address_, |
121 &addr)) { | 129 &addr)) { |
122 SendRecvFromACKError(); | 130 SendRecvFromACKError(); |
123 } else { | 131 } else { |
124 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( | 132 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( |
125 routing_id_, plugin_dispatcher_id_, socket_id_, true, | 133 routing_id_, plugin_dispatcher_id_, socket_id_, true, |
126 std::string(recvfrom_buffer_->data(), result), addr)); | 134 std::string(recvfrom_buffer_->data(), result), addr)); |
127 } | 135 } |
128 | 136 |
129 recvfrom_buffer_ = NULL; | 137 recvfrom_buffer_ = NULL; |
130 } | 138 } |
131 | 139 |
132 void PepperUDPSocket::OnSendToCompleted(int result) { | 140 void PepperUDPSocket::OnSendToCompleted(int result) { |
133 DCHECK(sendto_buffer_.get()); | 141 DCHECK(sendto_buffer_.get()); |
134 | 142 |
135 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( | 143 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( |
136 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); | 144 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); |
137 | 145 |
138 sendto_buffer_ = NULL; | 146 sendto_buffer_ = NULL; |
139 } | 147 } |
OLD | NEW |