Index: content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
diff --git a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
index 26c0e44ee34f6277a36309c6dd4b5c2c73a0e4c1..1f32678dcfffb3f974f79a2ae82166518e180392 100644 |
--- a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
+++ b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
@@ -44,8 +44,7 @@ PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( |
BrowserPpapiHostImpl* host, |
PP_Instance instance, |
bool private_api) |
- : allow_address_reuse_(false), |
- allow_broadcast_(false), |
+ : socket_options_(0), |
closed_(false), |
remaining_recv_slots_( |
ppapi::proxy::UDPSocketResourceBase::kPluginReceiveBufferSlots), |
@@ -114,49 +113,71 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( |
return PP_ERROR_FAILED; |
switch (name) { |
- case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: |
- case PP_UDPSOCKET_OPTION_BROADCAST: { |
+ case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: { |
+ bool boolean_value = false; |
+ if (!value.GetBool(&boolean_value)) |
+ return PP_ERROR_BADARGUMENT; |
+ |
if (socket_.get()) { |
- // They only take effect before the socket is bound. |
- return PP_ERROR_FAILED; |
+ return NetErrorToPepperError( |
+ boolean_value ? |
+ socket_->AllowAddressReuse() : socket_->DisallowAddressReuse()); |
} |
- |
+ if (boolean_value) { |
+ socket_options_ |= SOCKET_OPTION_ADDRESS_REUSE; |
+ } else { |
+ socket_options_ &= ~SOCKET_OPTION_ADDRESS_REUSE; |
+ } |
+ return PP_OK; |
+ } |
+ case PP_UDPSOCKET_OPTION_BROADCAST: { |
bool boolean_value = false; |
if (!value.GetBool(&boolean_value)) |
return PP_ERROR_BADARGUMENT; |
- if (name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) |
- allow_address_reuse_ = boolean_value; |
- else |
- allow_broadcast_ = boolean_value; |
+ if (socket_.get()) { |
+ return NetErrorToPepperError( |
+ boolean_value ? |
+ socket_->AllowBroadcast() : socket_->DisallowBroadcast()); |
+ } |
+ if (boolean_value) { |
+ socket_options_ |= SOCKET_OPTION_BROADCAST; |
+ } else { |
+ socket_options_ &= ~SOCKET_OPTION_BROADCAST; |
+ } |
return PP_OK; |
} |
case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: |
case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { |
- if (!socket_.get()) { |
- // They only take effect after the socket is bound. |
- return PP_ERROR_FAILED; |
- } |
int32_t integer_value = 0; |
if (!value.GetInt32(&integer_value) || integer_value <= 0) |
return PP_ERROR_BADARGUMENT; |
- int net_result = net::ERR_UNEXPECTED; |
if (name == PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE) { |
if (integer_value > |
ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) { |
return PP_ERROR_BADARGUMENT; |
} |
- net_result = socket_->SetSendBufferSize(integer_value); |
+ if (socket_.get()) { |
+ return NetErrorToPepperError( |
+ socket_->SetSendBufferSize(integer_value)); |
+ } |
+ socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE; |
+ sndbuf_size_ = integer_value; |
+ return PP_OK; |
} else { |
if (integer_value > |
ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) { |
return PP_ERROR_BADARGUMENT; |
} |
- net_result = socket_->SetReceiveBufferSize(integer_value); |
+ if (socket_.get()) { |
+ return NetErrorToPepperError( |
+ socket_->SetReceiveBufferSize(integer_value)); |
+ } |
+ socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE; |
+ rcvbuf_size_ = integer_value; |
+ return PP_OK; |
} |
- // TODO(wtc): Add error mapping code. |
- return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED; |
} |
default: { |
NOTREACHED(); |
@@ -263,12 +284,38 @@ void PepperUDPSocketMessageFilter::DoBind( |
return; |
} |
- if (allow_address_reuse_) |
- socket->AllowAddressReuse(); |
- if (allow_broadcast_) |
- socket->AllowBroadcast(); |
+ int32_t pp_result; |
+ if (socket_options_ & SOCKET_OPTION_ADDRESS_REUSE) { |
+ pp_result = NetErrorToPepperError(socket->AllowAddressReuse()); |
+ if (pp_result != PP_OK) { |
+ SendBindError(context, pp_result); |
+ return; |
+ } |
+ } |
+ if (socket_options_ & SOCKET_OPTION_BROADCAST) { |
+ pp_result = NetErrorToPepperError(socket->AllowBroadcast()); |
+ if (pp_result != PP_OK) { |
+ SendBindError(context, pp_result); |
+ return; |
+ } |
+ } |
+ if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) { |
+ pp_result = NetErrorToPepperError( |
+ socket->SetReceiveBufferSize(rcvbuf_size_)); |
+ if (pp_result != PP_OK) { |
+ SendBindError(context, pp_result); |
+ return; |
+ } |
+ } |
+ if (socket_options_ & SOCKET_OPTION_SNDBUF_SIZE) { |
+ pp_result = NetErrorToPepperError(socket->SetSendBufferSize(sndbuf_size_)); |
+ if (pp_result != PP_OK) { |
+ SendBindError(context, pp_result); |
+ return; |
+ } |
+ } |
- int32_t pp_result = |
+ pp_result = |
NetErrorToPepperError(socket->Listen(net::IPEndPoint(address, port))); |
if (pp_result != PP_OK) { |
SendBindError(context, pp_result); |
@@ -289,8 +336,7 @@ void PepperUDPSocketMessageFilter::DoBind( |
return; |
} |
- allow_address_reuse_ = false; |
- allow_broadcast_ = false; |
+ socket_options_ = 0; |
socket_.swap(socket); |
SendBindReply(context, PP_OK, net_address); |