Backed out changeset 17bd0777339a (bug 1164425)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 20 May 2015 10:30:55 +0200
changeset 275320 e7911141b44fb856965e9f1f3bcd3a145236f4ed
parent 275319 75cc1cf46093190577ecf7038fc9fc2b05ce6bf2
child 275321 94ab7aa2012ffb4520cba847273ef94bae06d335
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1164425
milestone41.0a1
backs out17bd0777339ab9987658f59ef0f0203e5693504b
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
Backed out changeset 17bd0777339a (bug 1164425)
dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
dom/nfc/gonk/NfcService.cpp
ipc/unixsocket/ListenSocket.cpp
ipc/unixsocket/ListenSocket.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp
@@ -1908,17 +1908,17 @@ BluetoothDaemonInterface::OnConnectSucce
       // Init, step 3: Listen for notification channel...
       if (!mNtfChannel) {
         mNtfChannel = new BluetoothDaemonChannel(this, NTF_CHANNEL, mProtocol);
       } else if (
         NS_WARN_IF(mNtfChannel->GetConnectionStatus() == SOCKET_CONNECTED)) {
         /* Notification channel should not be open; let's close it. */
         mNtfChannel->Close();
       }
-      if (NS_FAILED(mListenSocket->Listen(mNtfChannel))) {
+      if (!mListenSocket->Listen(mNtfChannel)) {
         OnConnectError(NTF_CHANNEL);
       }
       break;
     case NTF_CHANNEL: {
         nsRefPtr<BluetoothResultHandler> res = mResultHandlerQ.ElementAt(0);
         mResultHandlerQ.RemoveElementAt(0);
 
         // Init, step 4: Register Core module
@@ -2131,19 +2131,19 @@ BluetoothDaemonInterface::Init(
   // simply use the base name as-is.
   nsresult rv = CreateRandomAddressString(NS_LITERAL_CSTRING(BASE_SOCKET_NAME),
                                           POSTFIX_LENGTH,
                                           mListenSocketName);
   if (NS_FAILED(rv)) {
     mListenSocketName.AssignLiteral(BASE_SOCKET_NAME);
   }
 
-  rv = mListenSocket->Listen(new BluetoothDaemonConnector(mListenSocketName),
-                             mCmdChannel);
-  if (NS_FAILED(rv)) {
+  bool success = mListenSocket->Listen(
+    new BluetoothDaemonConnector(mListenSocketName), mCmdChannel);
+  if (!success) {
     OnConnectError(CMD_CHANNEL);
     return;
   }
 
   // The protocol implementation needs a command channel for
   // sending commands to the daemon. We set it here, because
   // this is the earliest time when it's available.
   mProtocol->SetConnection(mCmdChannel);
--- a/dom/nfc/gonk/NfcService.cpp
+++ b/dom/nfc/gonk/NfcService.cpp
@@ -307,24 +307,25 @@ NfcService::Start(nsINfcGonkEventListene
 
   mListener = aListener;
   mHandler = new NfcMessageHandler();
   mConsumer = new NfcConsumer(this);
 
   mListenSocketName = BASE_SOCKET_NAME;
 
   mListenSocket = new NfcListenSocket(this);
-  nsresult rv = mListenSocket->Listen(new NfcConnector(mListenSocketName),
-                                      mConsumer);
-  if (NS_FAILED(rv)) {
+
+  bool success = mListenSocket->Listen(new NfcConnector(mListenSocketName),
+                                       mConsumer);
+  if (!success) {
     mConsumer = nullptr;
-    return rv;
+    return NS_ERROR_FAILURE;
   }
 
-  rv = NS_NewNamedThread("NfcThread", getter_AddRefs(mThread));
+  nsresult rv = NS_NewNamedThread("NfcThread", getter_AddRefs(mThread));
   if (NS_FAILED(rv)) {
     NS_WARNING("Can't create Nfc worker thread.");
     mListenSocket->Close();
     mListenSocket = nullptr;
     mConsumer->Shutdown();
     mConsumer = nullptr;
     return NS_ERROR_FAILURE;
   }
--- a/ipc/unixsocket/ListenSocket.cpp
+++ b/ipc/unixsocket/ListenSocket.cpp
@@ -26,16 +26,18 @@ class ListenSocketIO final
 public:
   class ListenTask;
 
   ListenSocketIO(MessageLoop* mIOLoop,
                  ListenSocket* aListenSocket,
                  UnixSocketConnector* aConnector);
   ~ListenSocketIO();
 
+  void GetSocketAddr(nsAString& aAddrStr) const;
+
   // Task callback methods
   //
 
   /**
    * Run bind/listen to prepare for further runs of accept()
    */
   void Listen(ConnectionOrientedSocketIO* aCOSocketIO);
 
@@ -108,16 +110,36 @@ ListenSocketIO::ListenSocketIO(MessageLo
 
 ListenSocketIO::~ListenSocketIO()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(IsShutdownOnMainThread());
 }
 
 void
+ListenSocketIO::GetSocketAddr(nsAString& aAddrStr) const
+{
+  if (!mConnector) {
+    NS_WARNING("No connector to get socket address from!");
+    aAddrStr.Truncate();
+    return;
+  }
+
+  nsCString addressString;
+  nsresult rv = mConnector->ConvertAddressToString(
+    *reinterpret_cast<const struct sockaddr*>(&mAddress), mAddressLength,
+    addressString);
+  if (NS_FAILED(rv)) {
+    return;
+  }
+
+  aAddrStr.Assign(NS_ConvertUTF8toUTF16(addressString));
+}
+
+void
 ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO)
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(mConnector);
   MOZ_ASSERT(aCOSocketIO);
 
   struct sockaddr* address = reinterpret_cast<struct sockaddr*>(&mAddress);
   mAddressLength = sizeof(mAddress);
@@ -287,42 +309,61 @@ ListenSocket::ListenSocket()
 : mIO(nullptr)
 { }
 
 ListenSocket::~ListenSocket()
 {
   MOZ_ASSERT(!mIO);
 }
 
-nsresult
+bool
 ListenSocket::Listen(UnixSocketConnector* aConnector,
                      ConnectionOrientedSocket* aCOSocket)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!mIO);
+  MOZ_ASSERT(aConnector);
+  MOZ_ASSERT(aCOSocket);
+
+  nsAutoPtr<UnixSocketConnector> connector(aConnector);
 
-  mIO = new ListenSocketIO(XRE_GetIOMessageLoop(), this, aConnector);
+  if (mIO) {
+    NS_WARNING("Socket already connecting/connected!");
+    return false;
+  }
+
+  mIO = new ListenSocketIO(XRE_GetIOMessageLoop(), this, connector.forget());
 
   // Prepared I/O object, now start listening.
   return Listen(aCOSocket);
 }
 
-nsresult
+bool
 ListenSocket::Listen(ConnectionOrientedSocket* aCOSocket)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(mIO);
   MOZ_ASSERT(aCOSocket);
-  MOZ_ASSERT(mIO);
 
   SetConnectionStatus(SOCKET_LISTENING);
 
   XRE_GetIOMessageLoop()->PostTask(
     FROM_HERE, new ListenSocketIO::ListenTask(mIO, aCOSocket->GetIO()));
 
-  return NS_OK;
+  return true;
+}
+
+void
+ListenSocket::GetSocketAddr(nsAString& aAddrStr)
+{
+  aAddrStr.Truncate();
+  if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
+    NS_WARNING("No socket currently open!");
+    return;
+  }
+  mIO->GetSocketAddr(aAddrStr);
 }
 
 // |SocketBase|
 
 void
 ListenSocket::Close()
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/ipc/unixsocket/ListenSocket.h
+++ b/ipc/unixsocket/ListenSocket.h
@@ -27,31 +27,38 @@ public:
 
   /**
    * Starts a task on the socket that will try to accept a new connection
    * in a non-blocking manner.
    *
    * @param aConnector Connector object for socket-type-specific functions
    * @param aCOSocket The connection-oriented socket for handling the
    *                  accepted connection.
-   * @return NS_OK on success, or an XPCOM error code otherwise.
+   *
+   * @return true on listen started, false otherwise
    */
-  nsresult Listen(UnixSocketConnector* aConnector,
-                  ConnectionOrientedSocket* aCOSocket);
+  bool Listen(UnixSocketConnector* aConnector,
+              ConnectionOrientedSocket* aCOSocket);
 
   /**
    * Starts a task on the socket that will try to accept a new connection
    * in a non-blocking manner. This method re-uses a previously created
    * listen socket.
    *
    * @param aCOSocket The connection-oriented socket for handling the
    *                  accepted connection.
-   * @return NS_OK on success, or an XPCOM error code otherwise.
+   *
+   * @return true on listen started, false otherwise
    */
-  nsresult Listen(ConnectionOrientedSocket* aCOSocket);
+  bool Listen(ConnectionOrientedSocket* aCOSocket);
+
+  /**
+   * Get the current sockaddr for the socket
+   */
+  void GetSocketAddr(nsAString& aAddrStr);
 
   // Methods for |SocketBase|
   //
 
   void Close() override;
 
 private:
   ListenSocketIO* mIO;