From c81c6692fc018de095f5c07c0ba3e621141adc5a Mon Sep 17 00:00:00 2001 From: Chuck Lee Date: Fri, 25 Oct 2013 10:00:22 +0800 Subject: [PATCH] Bug 928223 - 0001. Add function to perform setup for listen socket. r=qDot echou vicamo yoshi --- dom/bluetooth/BluetoothUnixSocketConnector.cpp | 7 +++++++ dom/bluetooth/BluetoothUnixSocketConnector.h | 1 + ipc/nfc/Nfc.cpp | 8 ++++++++ ipc/ril/Ril.cpp | 8 ++++++++ ipc/unixsocket/UnixSocket.cpp | 8 ++++++++ ipc/unixsocket/UnixSocket.h | 12 +++++++++++- 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/dom/bluetooth/BluetoothUnixSocketConnector.cpp b/dom/bluetooth/BluetoothUnixSocketConnector.cpp index 3e4c38e5f64..bb980dec314 100644 --- a/dom/bluetooth/BluetoothUnixSocketConnector.cpp +++ b/dom/bluetooth/BluetoothUnixSocketConnector.cpp @@ -166,6 +166,13 @@ BluetoothUnixSocketConnector::SetUp(int aFd) return true; } +bool +BluetoothUnixSocketConnector::SetUpListenSocket(int aFd) +{ + // Nothing to do here. + return true; +} + int BluetoothUnixSocketConnector::Create() { diff --git a/dom/bluetooth/BluetoothUnixSocketConnector.h b/dom/bluetooth/BluetoothUnixSocketConnector.h index e46a9bd78f5..abad4adf5d7 100644 --- a/dom/bluetooth/BluetoothUnixSocketConnector.h +++ b/dom/bluetooth/BluetoothUnixSocketConnector.h @@ -26,6 +26,7 @@ public: 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; diff --git a/ipc/nfc/Nfc.cpp b/ipc/nfc/Nfc.cpp index a164404e397..a0258aa6c66 100644 --- a/ipc/nfc/Nfc.cpp +++ b/ipc/nfc/Nfc.cpp @@ -77,6 +77,7 @@ public: 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); }; @@ -151,6 +152,13 @@ NfcConnector::SetUp(int aFd) return true; } +bool +NfcConnector::SetUpListenSocket(int aFd) +{ + // Nothing to do here. + return true; +} + void NfcConnector::GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) diff --git a/ipc/ril/Ril.cpp b/ipc/ril/Ril.cpp index 558a18df22e..3dc8e0a8be8 100644 --- a/ipc/ril/Ril.cpp +++ b/ipc/ril/Ril.cpp @@ -76,6 +76,7 @@ public: 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); @@ -152,6 +153,13 @@ RilConnector::SetUp(int aFd) return true; } +bool +RilConnector::SetUpListenSocket(int aFd) +{ + // Nothing to do here. + return true; +} + void RilConnector::GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) diff --git a/ipc/unixsocket/UnixSocket.cpp b/ipc/unixsocket/UnixSocket.cpp index 7f0909624db..f352c18a110 100644 --- a/ipc/unixsocket/UnixSocket.cpp +++ b/ipc/unixsocket/UnixSocket.cpp @@ -521,6 +521,14 @@ UnixSocketImpl::Accept() return; } + if (!mConnector->SetUpListenSocket(mFd)) { + NS_WARNING("Could not set up listen socket!"); + nsRefPtr t = + new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR); + NS_DispatchToMainThread(t); + return; + } + } SetUpIO(); diff --git a/ipc/unixsocket/UnixSocket.h b/ipc/unixsocket/UnixSocket.h index d1df680639c..3cbb552b6b8 100644 --- a/ipc/unixsocket/UnixSocket.h +++ b/ipc/unixsocket/UnixSocket.h @@ -119,7 +119,8 @@ public: 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 * @@ -127,6 +128,15 @@ public: */ 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.