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

Unified Diff: native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc

Issue 63573006: [NaCl SDK] nacl_io: Auto-bind UDP socket on first sendto(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: getsockname stuff Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc
index 3a98372241c91e2670948993273d85ff97aa6ca8..c35a8f5e4bf0fe7de9086fc677f82177fb165386 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc
@@ -218,10 +218,14 @@ Error MountNodeUDP::Bind(const struct sockaddr* addr, socklen_t len) {
int err = UDPInterface()->Bind(socket_resource_,
out_addr,
PP_BlockUntilComplete());
- if (err != 0) {
- mount_->ppapi()->ReleaseResource(out_addr);
+ mount_->ppapi()->ReleaseResource(out_addr);
+ if (err != 0)
return PPErrorToErrno(err);
- }
+
+ // Get the address that was actually bound (in case addr was 0.0.0.0:0).
+ out_addr = UDPInterface()->GetBoundAddress(socket_resource_);
+ if (out_addr == 0)
+ return EINVAL;
// Now that we are bound, we can start sending and receiving.
SetStreamFlags(SSF_CAN_SEND | SSF_CAN_RECV);
@@ -282,6 +286,18 @@ Error MountNodeUDP::Send_Locked(const void* buf,
size_t len,
PP_Resource addr,
int* out_len) {
+ if (!IsBound()) {
+ // Pepper requires a socket to be bound before it can send.
+ sockaddr_in addr;
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0;
+ memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
+ Error err =
+ Bind(reinterpret_cast<const struct sockaddr*>(&addr), sizeof(addr));
+ if (err != 0)
+ return err;
+ }
+
*out_len = 0;
int capped_len =
static_cast<int32_t>(std::min<int>(len, kMaxPacketSize));

Powered by Google App Engine
This is Rietveld 408576698