Bug 928223 - 0001. Add function to perform setup for listen socket. r=qDot echou vicamo yoshi
authorChuck Lee <chulee@mozilla.com>
Fri, 25 Oct 2013 10:00:22 +0800
changeset 166973 c5a70830dc9a4643430c89274fb33d26ba235176
parent 166972 810cb9568dbfe6c8bbe7b291723d5b77cec4660f
child 166974 d2fed841795737ec0483614c6e36816f415886b1
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqDot
bugs928223
milestone27.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 928223 - 0001. Add function to perform setup for listen socket. r=qDot echou vicamo yoshi
dom/bluetooth/BluetoothUnixSocketConnector.cpp
dom/bluetooth/BluetoothUnixSocketConnector.h
ipc/nfc/Nfc.cpp
ipc/ril/Ril.cpp
ipc/unixsocket/UnixSocket.cpp
ipc/unixsocket/UnixSocket.h
--- a/dom/bluetooth/BluetoothUnixSocketConnector.cpp
+++ b/dom/bluetooth/BluetoothUnixSocketConnector.cpp
@@ -161,16 +161,23 @@ BluetoothUnixSocketConnector::SetUp(int 
         return false;
       }
     }
   }
 #endif
   return true;
 }
 
+bool
+BluetoothUnixSocketConnector::SetUpListenSocket(int aFd)
+{
+  // Nothing to do here.
+  return true;
+}
+
 int
 BluetoothUnixSocketConnector::Create()
 {
   MOZ_ASSERT(!NS_IsMainThread());
   int fd = -1;
 
 #ifdef MOZ_B2G_BT_BLUEZ
   switch (mType) {
--- a/dom/bluetooth/BluetoothUnixSocketConnector.h
+++ b/dom/bluetooth/BluetoothUnixSocketConnector.h
@@ -21,16 +21,17 @@ public:
   virtual ~BluetoothUnixSocketConnector()
   {}
   virtual int Create() MOZ_OVERRIDE;
   virtual bool CreateAddr(bool aIsServer,
                           socklen_t& aAddrSize,
                           mozilla::ipc::sockaddr_any& aAddr,
                           const char* aAddress) MOZ_OVERRIDE;
   virtual bool SetUp(int aFd) MOZ_OVERRIDE;
+  virtual bool SetUpListenSocket(int aFd) MOZ_OVERRIDE;
   virtual void GetSocketAddr(const mozilla::ipc::sockaddr_any& aAddr,
                              nsAString& aAddrStr) MOZ_OVERRIDE;
 
 private:
   BluetoothSocketType mType;
   int mChannel;
   bool mAuth;
   bool mEncrypt;
--- a/ipc/nfc/Nfc.cpp
+++ b/ipc/nfc/Nfc.cpp
@@ -72,16 +72,17 @@ public:
     {}
 
     virtual int Create();
     virtual bool CreateAddr(bool aIsServer,
                             socklen_t& aAddrSize,
                             sockaddr_any& aAddr,
                             const char* aAddress);
     virtual bool SetUp(int aFd);
+    virtual bool SetUpListenSocket(int aFd);
     virtual void GetSocketAddr(const sockaddr_any& aAddr,
                                nsAString& aAddrStr);
 };
 
 int
 NfcConnector::Create()
 {
     MOZ_ASSERT(!NS_IsMainThread());
@@ -146,16 +147,23 @@ NfcConnector::CreateAddr(bool aIsServer,
 
 bool
 NfcConnector::SetUp(int aFd)
 {
     // Nothing to do here.
     return true;
 }
 
+bool
+NfcConnector::SetUpListenSocket(int aFd)
+{
+    // Nothing to do here.
+    return true;
+}
+
 void
 NfcConnector::GetSocketAddr(const sockaddr_any& aAddr,
                             nsAString& aAddrStr)
 {
     MOZ_CRASH("This should never be called!");
 }
 
 } // anonymous namespace
--- a/ipc/ril/Ril.cpp
+++ b/ipc/ril/Ril.cpp
@@ -71,16 +71,17 @@ public:
   {}
 
   virtual int Create();
   virtual bool CreateAddr(bool aIsServer,
                           socklen_t& aAddrSize,
                           sockaddr_any& aAddr,
                           const char* aAddress);
   virtual bool SetUp(int aFd);
+  virtual bool SetUpListenSocket(int aFd);
   virtual void GetSocketAddr(const sockaddr_any& aAddr,
                              nsAString& aAddrStr);
 
 private:
   unsigned long mClientId;
 };
 
 int
@@ -147,16 +148,23 @@ RilConnector::CreateAddr(bool aIsServer,
 
 bool
 RilConnector::SetUp(int aFd)
 {
     // Nothing to do here.
     return true;
 }
 
+bool
+RilConnector::SetUpListenSocket(int aFd)
+{
+    // Nothing to do here.
+    return true;
+}
+
 void
 RilConnector::GetSocketAddr(const sockaddr_any& aAddr,
                             nsAString& aAddrStr)
 {
     MOZ_CRASH("This should never be called!");
 }
 
 } // anonymous namespace
--- a/ipc/unixsocket/UnixSocket.cpp
+++ b/ipc/unixsocket/UnixSocket.cpp
@@ -516,16 +516,24 @@ UnixSocketImpl::Accept()
 
     if (listen(mFd.get(), 1)) {
 #ifdef DEBUG
       LOG("...listen(%d) gave errno %d", mFd.get(), errno);
 #endif
       return;
     }
 
+    if (!mConnector->SetUpListenSocket(mFd)) {
+      NS_WARNING("Could not set up listen socket!");
+      nsRefPtr<OnSocketEventTask> t =
+        new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+      NS_DispatchToMainThread(t);
+      return;
+    }
+
   }
 
   SetUpIO();
 }
 
 void
 UnixSocketImpl::Connect()
 {
--- a/ipc/unixsocket/UnixSocket.h
+++ b/ipc/unixsocket/UnixSocket.h
@@ -114,25 +114,35 @@ public:
    * @return True if address is filled correctly, false otherwise
    */
   virtual bool CreateAddr(bool aIsServer,
                           socklen_t& aAddrSize,
                           sockaddr_any& aAddr,
                           const char* aAddress) = 0;
 
   /**
-   * Does any socket type specific setup that may be needed
+   * Does any socket type specific setup that may be needed, only for socket
+   * created by ConnectSocket()
    *
    * @param aFd File descriptor for opened socket
    *
    * @return true is successful, false otherwise
    */
   virtual bool SetUp(int aFd) = 0;
 
   /**
+   * Perform socket setup for socket created by ListenSocket(), after listen().
+   *
+   * @param aFd File descriptor for opened socket
+   *
+   * @return true is successful, false otherwise
+   */
+  virtual bool SetUpListenSocket(int aFd) = 0;
+
+  /**
    * Get address of socket we're currently connected to. Return null string if
    * not connected.
    *
    * @param aAddr Address struct
    * @param aAddrStr String to store address to
    */
   virtual void GetSocketAddr(const sockaddr_any& aAddr,
                              nsAString& aAddrStr) = 0;