Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: content/browser/renderer_host/pepper_udp_socket.cc

Issue 9212047: Add GetBoundAddress to PPB_UDPSocket_Private (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fix build error after rebase Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
52 SendBindACK(result == net::OK); 52 if (result == net::OK &&
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
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() {
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 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper_udp_socket.h ('k') | content/renderer/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698