Bug 1164417: Add |UnixSocketConnector::Duplicate|, r=kmachulis
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 21 May 2015 13:34:37 +0200
changeset 244968 0b9b45499f77ffae41b412e0a410499d95687cba
parent 244919 8bf3f2b345484ff26d343aeb2dc93f99a5d33497
child 244969 13411cc00f09398a731d74da1502fd183601ceff
push id60070
push userkwierso@gmail.com
push dateThu, 21 May 2015 22:45:11 +0000
treeherdermozilla-inbound@3e737d30f842 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmachulis
bugs1164417
milestone41.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 1164417: Add |UnixSocketConnector::Duplicate|, r=kmachulis The new method |UnixSocketConnector::Duplicate| allows a socket connector to duplicate itself. Listening sockets will used this feature to create socket connectors for accepted connections.
dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
dom/bluetooth/bluedroid/BluetoothDaemonConnector.h
dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
dom/bluetooth/bluez/BluetoothUnixSocketConnector.h
ipc/keystore/KeyStoreConnector.cpp
ipc/keystore/KeyStoreConnector.h
ipc/nfc/NfcConnector.cpp
ipc/nfc/NfcConnector.h
ipc/ril/RilConnector.cpp
ipc/ril/RilConnector.h
ipc/unixsocket/UnixSocketConnector.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
@@ -166,9 +166,17 @@ BluetoothDaemonConnector::CreateStreamSo
                                              socklen_t* aAddressLength,
                                              int& aStreamFd)
 {
   MOZ_CRASH("|BluetoothDaemonConnector| does not support "
             "creating stream sockets.");
   return NS_ERROR_ABORT;
 }
 
+nsresult
+BluetoothDaemonConnector::Duplicate(UnixSocketConnector*& aConnector)
+{
+  aConnector = new BluetoothDaemonConnector(*this);
+
+  return NS_OK;
+}
+
 END_BLUETOOTH_NAMESPACE
--- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h
@@ -35,16 +35,18 @@ public:
                               struct sockaddr* aAddress,
                               socklen_t* aAddressLen,
                               int& aStreamFd) override;
 
   nsresult CreateStreamSocket(struct sockaddr* aAddress,
                               socklen_t* aAddressLength,
                               int& aStreamFd) override;
 
+  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
+
 private:
   nsresult CreateSocket(int& aFd) const;
   nsresult SetSocketFlags(int aFd) const;
   nsresult CreateAddress(struct sockaddr& aAddress,
                          socklen_t& aAddressLength) const;
 
   nsCString mSocketName;
 };
--- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
+++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
@@ -403,9 +403,17 @@ BluetoothUnixSocketConnector::CreateStre
     }
   }
 
   aStreamFd = fd.forget();
 
   return NS_OK;
 }
 
+nsresult
+BluetoothUnixSocketConnector::Duplicate(UnixSocketConnector*& aConnector)
+{
+  aConnector = new BluetoothUnixSocketConnector(*this);
+
+  return NS_OK;
+}
+
 END_BLUETOOTH_NAMESPACE
--- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h
+++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h
@@ -36,16 +36,18 @@ public:
                               struct sockaddr* aAddress,
                               socklen_t* aAddressLen,
                               int& aStreamFd) override;
 
   nsresult CreateStreamSocket(struct sockaddr* aAddress,
                               socklen_t* aAddressLength,
                               int& aStreamFd) override;
 
+  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
+
 private:
   nsresult CreateSocket(int& aFd) const;
   nsresult SetSocketFlags(int aFd) const;
   nsresult CreateAddress(struct sockaddr& aAddress,
                          socklen_t& aAddressLength) const;
   static nsresult ConvertAddressString(const char* aAddressString,
                                        bdaddr_t& aAddress);
 
--- a/ipc/keystore/KeyStoreConnector.cpp
+++ b/ipc/keystore/KeyStoreConnector.cpp
@@ -217,10 +217,18 @@ nsresult
 KeyStoreConnector::CreateStreamSocket(struct sockaddr* aAddress,
                                       socklen_t* aAddressLength,
                                       int& aStreamFd)
 {
   MOZ_CRASH("|KeyStoreConnector| does not support creating stream sockets.");
   return NS_ERROR_FAILURE;
 }
 
+nsresult
+KeyStoreConnector::Duplicate(UnixSocketConnector*& aConnector)
+{
+  aConnector = new KeyStoreConnector(*this);
+
+  return NS_OK;
+}
+
 }
 }
--- a/ipc/keystore/KeyStoreConnector.h
+++ b/ipc/keystore/KeyStoreConnector.h
@@ -34,16 +34,18 @@ public:
                               struct sockaddr* aAddress,
                               socklen_t* aAddressLength,
                               int& aStreamFd) override;
 
   nsresult CreateStreamSocket(struct sockaddr* aAddress,
                               socklen_t* aAddressLength,
                               int& aStreamFd) override;
 
+  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
+
 private:
   nsresult CreateSocket(int& aFd) const;
   nsresult SetSocketFlags(int aFd) const;
   nsresult CheckPermission(int aFd) const;
   nsresult CreateAddress(struct sockaddr& aAddress,
                          socklen_t& aAddressLength) const;
 
   const char** const mAllowedUsers;
--- a/ipc/nfc/NfcConnector.cpp
+++ b/ipc/nfc/NfcConnector.cpp
@@ -185,10 +185,18 @@ NfcConnector::CreateStreamSocket(struct 
     }
   }
 
   aStreamFd = fd.forget();
 
   return NS_OK;
 }
 
+nsresult
+NfcConnector::Duplicate(UnixSocketConnector*& aConnector)
+{
+  aConnector = new NfcConnector(*this);
+
+  return NS_OK;
+}
+
 }
 }
--- a/ipc/nfc/NfcConnector.h
+++ b/ipc/nfc/NfcConnector.h
@@ -38,16 +38,18 @@ public:
                               struct sockaddr* aAddress,
                               socklen_t* aAddressLen,
                               int& aStreamFd) override;
 
   nsresult CreateStreamSocket(struct sockaddr* aAddress,
                               socklen_t* aAddressLength,
                               int& aStreamFd) override;
 
+  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
+
 private:
   nsresult CreateSocket(int& aFd) const;
   nsresult SetSocketFlags(int aFd) const;
   nsresult CreateAddress(struct sockaddr& aAddress,
                          socklen_t& aAddressLength) const;
 
   nsCString mAddressString;
 };
--- a/ipc/ril/RilConnector.cpp
+++ b/ipc/ril/RilConnector.cpp
@@ -199,10 +199,18 @@ RilConnector::CreateStreamSocket(struct 
     }
   }
 
   aStreamFd = fd.forget();
 
   return NS_OK;
 }
 
+nsresult
+RilConnector::Duplicate(UnixSocketConnector*& aConnector)
+{
+  aConnector = new RilConnector(*this);
+
+  return NS_OK;
+}
+
 }
 }
--- a/ipc/ril/RilConnector.h
+++ b/ipc/ril/RilConnector.h
@@ -38,16 +38,19 @@ public:
                               struct sockaddr* aAddress,
                               socklen_t* aAddressLen,
                               int& aStreamFd) override;
 
   nsresult CreateStreamSocket(struct sockaddr* aAddress,
                               socklen_t* aAddressLength,
                               int& aStreamFd) override;
 
+  nsresult Duplicate(UnixSocketConnector*& aConnector) override;
+
+
 private:
   nsresult CreateSocket(int aDomain, int& aFd) const;
   nsresult SetSocketFlags(int aFd) const;
   nsresult CreateAddress(int aDomain,
                          struct sockaddr& aAddress,
                          socklen_t& aAddressLength) const;
 
   nsCString mAddressString;
--- a/ipc/unixsocket/UnixSocketConnector.h
+++ b/ipc/unixsocket/UnixSocketConnector.h
@@ -71,16 +71,24 @@ public:
    * @param[in|out] aAddressLength The number of valid bytes in |aAddress|
    * @param[out] aStreamFd The socket's file descriptor
    * @return NS_OK on success, or an XPCOM error code otherwise.
    */
   virtual nsresult CreateStreamSocket(struct sockaddr* aAddress,
                                       socklen_t* aAddressLength,
                                       int& aStreamFd) = 0;
 
+  /**
+   * Copies the instance of |UnixSocketConnector|. I/O thread only.
+   *
+   * @param[in] aConnector Returns a new instance of the connector class
+   * @return NS_OK on success, or an XPCOM error code otherwise
+   */
+  virtual nsresult Duplicate(UnixSocketConnector*& aConnector) = 0;
+
 protected:
   UnixSocketConnector();
 };
 
 }
 }
 
 #endif