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

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: A few more changes via review 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) 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
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.
viettrungluu 2012/02/07 23:03:58 Nit: This comment is useless; it's self-evident fr
mtilburg1 2012/02/08 15:27:01 Done.
53 if (result == net::OK) {
viettrungluu 2012/02/07 23:03:58 Nit: Other single-line if statements in the file d
mtilburg1 2012/02/08 15:27:01 Done.
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
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 if (!NetAddressPrivateImpl::IPEndPointToNetAddress(bound_address_, &addr))
viettrungluu 2012/02/07 23:03:58 Shouldn't you do some other cleanup here, rather t
mtilburg1 2012/02/08 15:27:01 Changed to be consistant with GetRecvFromACKError.
116 result = false;
117
109 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK( 118 manager_->Send(new PpapiMsg_PPBUDPSocket_BindACK(
110 routing_id_, plugin_dispatcher_id_, socket_id_, result)); 119 routing_id_, plugin_dispatcher_id_, socket_id_, result, addr));
111 } 120 }
112 121
113 void PepperUDPSocket::OnRecvFromCompleted(int result) { 122 void PepperUDPSocket::OnRecvFromCompleted(int result) {
114 DCHECK(recvfrom_buffer_.get()); 123 DCHECK(recvfrom_buffer_.get());
115 124
116 // Convert IPEndPoint we get back from RecvFrom to a PP_NetAddress_Private, 125 // Convert IPEndPoint we get back from RecvFrom to a PP_NetAddress_Private,
117 // to send back. 126 // to send back.
118 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress; 127 PP_NetAddress_Private addr = NetAddressPrivateImpl::kInvalidNetAddress;
119 if (result < 0 || 128 if (result < 0 ||
120 !NetAddressPrivateImpl::IPEndPointToNetAddress(recvfrom_address_, 129 !NetAddressPrivateImpl::IPEndPointToNetAddress(recvfrom_address_,
121 &addr)) { 130 &addr)) {
122 SendRecvFromACKError(); 131 SendRecvFromACKError();
123 } else { 132 } else {
124 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK( 133 manager_->Send(new PpapiMsg_PPBUDPSocket_RecvFromACK(
125 routing_id_, plugin_dispatcher_id_, socket_id_, true, 134 routing_id_, plugin_dispatcher_id_, socket_id_, true,
126 std::string(recvfrom_buffer_->data(), result), addr)); 135 std::string(recvfrom_buffer_->data(), result), addr));
127 } 136 }
128 137
129 recvfrom_buffer_ = NULL; 138 recvfrom_buffer_ = NULL;
130 } 139 }
131 140
132 void PepperUDPSocket::OnSendToCompleted(int result) { 141 void PepperUDPSocket::OnSendToCompleted(int result) {
133 DCHECK(sendto_buffer_.get()); 142 DCHECK(sendto_buffer_.get());
134 143
135 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( 144 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK(
136 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); 145 routing_id_, plugin_dispatcher_id_, socket_id_, true, result));
137 146
138 sendto_buffer_ = NULL; 147 sendto_buffer_ = NULL;
139 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698