OLD | NEW |
---|---|
1 // Copyright (c) 2011 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_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" |
11 #include "content/browser/renderer_host/pepper_message_filter.h" | 11 #include "content/browser/renderer_host/pepper_message_filter.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
36 if (socket_.get()) | 36 if (socket_.get()) |
37 socket_->Close(); | 37 socket_->Close(); |
38 } | 38 } |
39 | 39 |
40 void PepperUDPSocket::Bind(const PP_NetAddress_Private& addr) { | 40 void PepperUDPSocket::Bind(const PP_NetAddress_Private& addr) { |
41 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source())); | 41 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source())); |
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 SendBindACKError(); |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 int result = socket_->Listen(address); | 50 int result = socket_->Listen(address); |
51 | 51 |
viettrungluu
2012/02/16 18:47:10
Probably you want to reset the socket in the failu
mtilburg1
2012/02/17 12:14:23
Trung - I'm not sure this is necessary, since the
| |
52 SendBindACK(result == net::OK); | 52 if (result == net::OK && |
viettrungluu
2012/02/16 18:47:10
(See comment below. I guess you'll need to modify
mtilburg1
2012/02/17 12:14:23
Trung-
While this method will also work, I don't
| |
53 socket_->GetLocalAddress(&bound_address_) != net::OK) { | |
54 SendBindACKError(); | |
55 return; | |
56 } | |
57 | |
58 OnBindCompleted(result); | |
53 } | 59 } |
54 | 60 |
55 void PepperUDPSocket::RecvFrom(int32_t num_bytes) { | 61 void PepperUDPSocket::RecvFrom(int32_t num_bytes) { |
56 if (recvfrom_buffer_.get()) { | 62 if (recvfrom_buffer_.get()) { |
57 SendRecvFromACKError(); | 63 SendRecvFromACKError(); |
58 return; | 64 return; |
59 } | 65 } |
60 | 66 |
61 recvfrom_buffer_ = new net::IOBuffer(num_bytes); | 67 recvfrom_buffer_ = new net::IOBuffer(num_bytes); |
62 int result = socket_->RecvFrom( | 68 int result = socket_->RecvFrom( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( | 104 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( |
99 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string(), | 105 routing_id_, plugin_dispatcher_id_, socket_id_, false, std::string(), |
100 addr)); | 106 addr)); |
101 } | 107 } |
102 | 108 |
103 void PepperUDPSocket::SendSendToACKError() { | 109 void PepperUDPSocket::SendSendToACKError() { |
104 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( | 110 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( |
105 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); | 111 routing_id_, plugin_dispatcher_id_, socket_id_, false, 0)); |
106 } | 112 } |
107 | 113 |
108 void PepperUDPSocket::SendBindACK(bool result) { | 114 void PepperUDPSocket::SendBindACKError() { |
viettrungluu
2012/02/16 18:47:10
This is now needlessly redundant and convoluted. I
mtilburg1
2012/02/17 12:14:23
I don't agree... we need an Error case (as we have
| |
115 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; | |
109 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( | 116 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( |
110 routing_id_, plugin_dispatcher_id_, socket_id_, result)); | 117 routing_id_, plugin_dispatcher_id_, socket_id_, false, addr)); |
118 } | |
119 | |
120 void PepperUDPSocket::OnBindCompleted(int result) { | |
121 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; | |
122 if (result < 0 || | |
123 !NetAddressPrivateImpl::IPEndPointToNetAddress(bound_address_, | |
124 &addr)) { | |
125 SendBindACKError(); | |
126 } else { | |
127 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( | |
128 routing_id_, plugin_dispatcher_id_, socket_id_, true, addr)); | |
129 } | |
111 } | 130 } |
112 | 131 |
113 void PepperUDPSocket::OnRecvFromCompleted(int result) { | 132 void PepperUDPSocket::OnRecvFromCompleted(int result) { |
114 DCHECK(recvfrom_buffer_.get()); | 133 DCHECK(recvfrom_buffer_.get()); |
115 | 134 |
116 // Convert IPEndPoint we get back from RecvFrom to a PP_NetAddress_Private, | 135 // Convert IPEndPoint we get back from RecvFrom to a PP_NetAddress_Private, |
117 // to send back. | 136 // to send back. |
118 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; | 137 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; |
119 if (result < 0 || | 138 if (result < 0 || |
120 !NetAddressPrivateImpl::IPEndPointToNetAddress(recvfrom_address_, | 139 !NetAddressPrivateImpl::IPEndPointToNetAddress(recvfrom_address_, |
121 &addr)) { | 140 &addr)) { |
122 SendRecvFromACKError(); | 141 SendRecvFromACKError(); |
123 } else { | 142 } else { |
124 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( | 143 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( |
125 routing_id_, plugin_dispatcher_id_, socket_id_, true, | 144 routing_id_, plugin_dispatcher_id_, socket_id_, true, |
126 std::string(recvfrom_buffer_->data(), result), addr)); | 145 std::string(recvfrom_buffer_->data(), result), addr)); |
127 } | 146 } |
128 | 147 |
129 recvfrom_buffer_ = NULL; | 148 recvfrom_buffer_ = NULL; |
130 } | 149 } |
131 | 150 |
132 void PepperUDPSocket::OnSendToCompleted(int result) { | 151 void PepperUDPSocket::OnSendToCompleted(int result) { |
133 DCHECK(sendto_buffer_.get()); | 152 DCHECK(sendto_buffer_.get()); |
134 | 153 |
135 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( | 154 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( |
136 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); | 155 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); |
137 | 156 |
138 sendto_buffer_ = NULL; | 157 sendto_buffer_ = NULL; |
139 } | 158 } |
OLD | NEW |