Bug 979668 - [Bluetooth] Sender name is not shown in transfer requests, f=tzimmermann, r=kyle
authorBen Tian <btian@mozilla.com>
Mon, 10 Mar 2014 10:11:27 +0800
changeset 190950 a149c02682ef20ebd6e64a9cb28846d76ff7eea2
parent 190949 5777e4a633f49cd4bf58a54293b2e7319eab0e4d
child 190951 d2c7fd724b71db868bde143958fa8e49bb4e91ea
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskyle
bugs979668
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 979668 - [Bluetooth] Sender name is not shown in transfer requests, f=tzimmermann, r=kyle
ipc/unixfd/UnixSocketWatcher.cpp
ipc/unixfd/UnixSocketWatcher.h
ipc/unixsocket/UnixSocket.cpp
ipc/unixsocket/UnixSocket.h
--- a/ipc/unixfd/UnixSocketWatcher.cpp
+++ b/ipc/unixfd/UnixSocketWatcher.cpp
@@ -93,21 +93,24 @@ void
 UnixSocketWatcher::OnFileCanReadWithoutBlocking(int aFd)
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(aFd == GetFd());
 
   if (mConnectionStatus == SOCKET_IS_CONNECTED) {
     OnSocketCanReceiveWithoutBlocking();
   } else if (mConnectionStatus == SOCKET_IS_LISTENING) {
-    int fd = TEMP_FAILURE_RETRY(accept(GetFd(), NULL, NULL));
+    sockaddr_any addr;
+    socklen_t addrLen = sizeof(addr);
+    int fd = TEMP_FAILURE_RETRY(accept(GetFd(),
+      reinterpret_cast<struct sockaddr*>(&addr), &addrLen));
     if (fd < 0) {
       OnError("accept", errno);
     } else {
-      OnAccepted(fd);
+      OnAccepted(fd, &addr, addrLen);
     }
   } else {
     NS_NOTREACHED("invalid connection state for reading");
   }
 }
 
 void
 UnixSocketWatcher::OnFileCanWriteWithoutBlocking(int aFd)
--- a/ipc/unixfd/UnixSocketWatcher.h
+++ b/ipc/unixfd/UnixSocketWatcher.h
@@ -2,21 +2,44 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ipc_UnixSocketWatcher_h
 #define mozilla_ipc_UnixSocketWatcher_h
 
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#ifdef MOZ_B2G_BT_BLUEZ
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/sco.h>
+#include <bluetooth/l2cap.h>
+#include <bluetooth/rfcomm.h>
+#endif
 #include "UnixFdWatcher.h"
 
 namespace mozilla {
 namespace ipc {
 
+union sockaddr_any {
+  sockaddr_storage storage; // address-family only
+  sockaddr_un un;
+  sockaddr_in in;
+  sockaddr_in6 in6;
+#ifdef MOZ_B2G_BT_BLUEZ
+  sockaddr_sco sco;
+  sockaddr_rc rc;
+  sockaddr_l2 l2;
+#endif
+  // ... others
+};
+
 class UnixSocketWatcher : public UnixFdWatcher
 {
 public:
   enum ConnectionStatus {
     SOCKET_IS_DISCONNECTED = 0,
     SOCKET_IS_LISTENING,
     SOCKET_IS_CONNECTING,
     SOCKET_IS_CONNECTED
@@ -29,21 +52,22 @@ public:
   ConnectionStatus GetConnectionStatus() const
   {
     return mConnectionStatus;
   }
 
   // Connect to a peer
   nsresult Connect(const struct sockaddr* aAddr, socklen_t aAddrLen);
 
-  // Listen on socket for incomming connection requests
+  // Listen on socket for incoming connection requests
   nsresult Listen(const struct sockaddr* aAddr, socklen_t aAddrLen);
 
   // Callback method for accepted connections
-  virtual void OnAccepted(int aFd) {};
+  virtual void OnAccepted(int aFd, const sockaddr_any* aAddr,
+                          socklen_t aAddrLen) {};
 
   // Callback method for successful connection requests
   virtual void OnConnected() {};
 
   // Callback method for successful listen requests
   virtual void OnListening() {};
 
   // Callback method for receiving from socket
--- a/ipc/unixsocket/UnixSocket.cpp
+++ b/ipc/unixsocket/UnixSocket.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "UnixSocket.h"
-#include "mozilla/ipc/UnixSocketWatcher.h"
 #include "nsTArray.h"
 #include "nsXULAppAPI.h"
 #include <fcntl.h>
 
 static const size_t MAX_READ_SIZE = 1 << 16;
 
 namespace mozilla {
 namespace ipc {
@@ -114,17 +113,18 @@ public:
 
   /**
    * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
    * directly from main thread. All non-main-thread accesses should happen with
    * mImpl as container.
    */
   RefPtr<UnixSocketConsumer> mConsumer;
 
-  void OnAccepted(int aFd) MOZ_OVERRIDE;
+  void OnAccepted(int aFd, const sockaddr_any* aAddr,
+                  socklen_t aAddrLen) MOZ_OVERRIDE;
   void OnConnected() MOZ_OVERRIDE;
   void OnError(const char* aFunction, int aErrno) MOZ_OVERRIDE;
   void OnListening() MOZ_OVERRIDE;
   void OnSocketCanReceiveWithoutBlocking() MOZ_OVERRIDE;
   void OnSocketCanSendWithoutBlocking() MOZ_OVERRIDE;
 
 private:
   // Set up flags on whatever our current file descriptor is.
@@ -548,20 +548,27 @@ UnixSocketImpl::SetSocketFlags(int aFd)
   if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags))) {
     return false;
   }
 
   return true;
 }
 
 void
-UnixSocketImpl::OnAccepted(int aFd)
+UnixSocketImpl::OnAccepted(int aFd,
+                           const sockaddr_any* aAddr,
+                           socklen_t aAddrLen)
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING);
+  MOZ_ASSERT(aAddr);
+  MOZ_ASSERT(aAddrLen <= sizeof(mAddr));
+
+  memcpy (&mAddr, aAddr, aAddrLen);
+  mAddrSize = aAddrLen;
 
   if (!mConnector->SetUp(aFd)) {
     NS_WARNING("Could not set up socket!");
     return;
   }
 
   RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
   Close();
--- a/ipc/unixsocket/UnixSocket.h
+++ b/ipc/unixsocket/UnixSocket.h
@@ -3,48 +3,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ipc_UnixSocket_h
 #define mozilla_ipc_UnixSocket_h
 
 
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#ifdef MOZ_B2G_BT_BLUEZ
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/sco.h>
-#include <bluetooth/l2cap.h>
-#include <bluetooth/rfcomm.h>
-#endif
 #include <stdlib.h>
+#include "nsAutoPtr.h"
 #include "nsString.h"
-#include "nsAutoPtr.h"
+#include "nsThreadUtils.h"
+#include "mozilla/ipc/UnixSocketWatcher.h"
 #include "mozilla/RefPtr.h"
-#include "nsThreadUtils.h"
 
 namespace mozilla {
 namespace ipc {
 
-union sockaddr_any {
-  sockaddr_storage storage; // address-family only
-  sockaddr_un un;
-  sockaddr_in in;
-  sockaddr_in6 in6;
-#ifdef MOZ_B2G_BT_BLUEZ
-  sockaddr_sco sco;
-  sockaddr_rc rc;
-  sockaddr_l2 l2;
-#endif
-  // ... others
-};
-
 class UnixSocketRawData
 {
 public:
   // Number of octets in mData.
   size_t mSize;
   size_t mCurrentWriteOffset;
   nsAutoArrayPtr<uint8_t> mData;