Bug 1170466: Inherit |ConnectionOrientedSocketIO| from |UnixSocketWatcher|, r=kmachulis
authorThomas Zimmermann <tdz@users.sourceforge.net>
Wed, 03 Jun 2015 11:53:50 +0200
changeset 246911 ef82cdf1079f3c2626d5a3dff0faab97acc5ec3f
parent 246910 df6a088dc3c841f46c395204b0f025facc4f5435
child 246912 3bd34542b7c17a1c8361bd20a1e8dced96721e31
push id28846
push userryanvm@gmail.com
push dateWed, 03 Jun 2015 19:51:00 +0000
treeherdermozilla-central@e5ee2c56963c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmachulis
bugs1170466
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 1170466: Inherit |ConnectionOrientedSocketIO| from |UnixSocketWatcher|, r=kmachulis Inheriting |ConncetionOrientedSocketIO| from |UnixSocketWatcher| will allow for sharing common I/O code of the sub-class.
ipc/bluetooth/BluetoothDaemonConnection.cpp
ipc/unixsocket/ConnectionOrientedSocket.cpp
ipc/unixsocket/ConnectionOrientedSocket.h
ipc/unixsocket/StreamSocket.cpp
--- a/ipc/bluetooth/BluetoothDaemonConnection.cpp
+++ b/ipc/bluetooth/BluetoothDaemonConnection.cpp
@@ -8,17 +8,16 @@
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
 #include <unistd.h>
 #include "mozilla/ipc/BluetoothDaemonConnectionConsumer.h"
 #include "mozilla/ipc/DataSocket.h"
 #include "mozilla/ipc/UnixSocketConnector.h"
-#include "mozilla/ipc/UnixSocketWatcher.h"
 #include "nsTArray.h"
 #include "nsXULAppAPI.h"
 
 #ifdef CHROMIUM_LOG
 #undef CHROMIUM_LOG
 #endif
 
 #if defined(MOZ_WIDGET_GONK)
@@ -196,19 +195,17 @@ BluetoothDaemonPDUConsumer::BluetoothDae
 
 BluetoothDaemonPDUConsumer::~BluetoothDaemonPDUConsumer()
 { }
 
 //
 // BluetoothDaemonConnectionIO
 //
 
-class BluetoothDaemonConnectionIO final
-  : public UnixSocketWatcher
-  , public ConnectionOrientedSocketIO
+class BluetoothDaemonConnectionIO final : public ConnectionOrientedSocketIO
 {
 public:
   BluetoothDaemonConnectionIO(nsIThread* aConsumerThread,
                               MessageLoop* aIOLoop,
                               int aFd, ConnectionStatus aConnectionStatus,
                               BluetoothDaemonConnection* aConnection,
                               BluetoothDaemonPDUConsumer* aConsumer);
 
@@ -257,18 +254,20 @@ private:
 
 BluetoothDaemonConnectionIO::BluetoothDaemonConnectionIO(
   nsIThread* aConsumerThread,
   MessageLoop* aIOLoop,
   int aFd,
   ConnectionStatus aConnectionStatus,
   BluetoothDaemonConnection* aConnection,
   BluetoothDaemonPDUConsumer* aConsumer)
-  : UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
-  , ConnectionOrientedSocketIO(aConsumerThread)
+  : ConnectionOrientedSocketIO(aConsumerThread,
+                               aIOLoop,
+                               aFd,
+                               aConnectionStatus)
   , mConnection(aConnection)
   , mConsumer(aConsumer)
   , mShuttingDownOnIOThread(false)
 {
   MOZ_ASSERT(mConnection);
   MOZ_ASSERT(mConsumer);
 }
 
--- a/ipc/unixsocket/ConnectionOrientedSocket.cpp
+++ b/ipc/unixsocket/ConnectionOrientedSocket.cpp
@@ -9,18 +9,29 @@
 namespace mozilla {
 namespace ipc {
 
 //
 // ConnectionOrientedSocketIO
 //
 
 ConnectionOrientedSocketIO::ConnectionOrientedSocketIO(
-  nsIThread* aConsumerThread)
+  nsIThread* aConsumerThread,
+  MessageLoop* aIOLoop,
+  int aFd,
+  ConnectionStatus aConnectionStatus)
   : DataSocketIO(aConsumerThread)
+  , UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
+{ }
+
+ConnectionOrientedSocketIO::ConnectionOrientedSocketIO(
+  nsIThread* aConsumerThread,
+  MessageLoop* aIOLoop)
+  : DataSocketIO(aConsumerThread)
+  , UnixSocketWatcher(aIOLoop)
 { }
 
 ConnectionOrientedSocketIO::~ConnectionOrientedSocketIO()
 { }
 
 //
 // ConnectionOrientedSocket
 //
--- a/ipc/unixsocket/ConnectionOrientedSocket.h
+++ b/ipc/unixsocket/ConnectionOrientedSocket.h
@@ -4,39 +4,63 @@
  * 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_connectionorientedsocket_h
 #define mozilla_ipc_connectionorientedsocket_h
 
 #include <sys/socket.h>
 #include "DataSocket.h"
+#include "mozilla/ipc/UnixSocketWatcher.h"
 
 class MessageLoop;
 
 namespace mozilla {
 namespace ipc {
 
 class UnixSocketConnector;
 
 /*
  * |ConnectionOrientedSocketIO| and |ConnectionOrientedSocket| define
  * interfaces for implementing stream sockets on I/O and consumer thread.
  * |ListenSocket| uses these classes to handle accepted sockets.
  */
 
-class ConnectionOrientedSocketIO : public DataSocketIO
+class ConnectionOrientedSocketIO
+  : public DataSocketIO
+  , public UnixSocketWatcher
 {
 public:
-  ConnectionOrientedSocketIO(nsIThread* aConsumerThread);
   virtual ~ConnectionOrientedSocketIO();
 
   virtual nsresult Accept(int aFd,
                           const struct sockaddr* aAddress,
                           socklen_t aAddressLength) = 0;
+
+protected:
+  /**
+   * Constructs an instance of |ConnectionOrientedSocketIO|
+   *
+   * @param aConsumerThread The socket's consumer thread.
+   * @param aIOLoop The socket's I/O loop.
+   * @param aFd The socket file descriptor.
+   * @param aConnectionStatus The connection status for |aFd|.
+   */
+  ConnectionOrientedSocketIO(nsIThread* aConsumerThread,
+                             MessageLoop* aIOLoop,
+                             int aFd, ConnectionStatus aConnectionStatus);
+
+  /**
+   * Constructs an instance of |ConnectionOrientedSocketIO|
+   *
+   * @param aConsumerThread The socket's consumer thread.
+   * @param aIOLoop The socket's I/O loop.
+   */
+  ConnectionOrientedSocketIO(nsIThread* aConsumerThread,
+                             MessageLoop* aIOLoop);
 };
 
 class ConnectionOrientedSocket : public DataSocket
 {
 public:
   /**
    * Prepares an instance of |ConnectionOrientedSocket| in DISCONNECTED
    * state for accepting a connection. Consumer-thread only.
--- a/ipc/unixsocket/StreamSocket.cpp
+++ b/ipc/unixsocket/StreamSocket.cpp
@@ -15,19 +15,17 @@ static const size_t MAX_READ_SIZE = 1 <<
 
 namespace mozilla {
 namespace ipc {
 
 //
 // StreamSocketIO
 //
 
-class StreamSocketIO final
-  : public UnixSocketWatcher
-  , public ConnectionOrientedSocketIO
+class StreamSocketIO final : public ConnectionOrientedSocketIO
 {
 public:
   class ConnectTask;
   class DelayedConnectTask;
   class ReceiveRunnable;
 
   StreamSocketIO(nsIThread* aConsumerThread,
                  MessageLoop* mIOLoop,
@@ -135,35 +133,36 @@ private:
    */
   nsAutoPtr<UnixSocketRawData> mBuffer;
 };
 
 StreamSocketIO::StreamSocketIO(nsIThread* aConsumerThread,
                                MessageLoop* aIOLoop,
                                StreamSocket* aStreamSocket,
                                UnixSocketConnector* aConnector)
-  : UnixSocketWatcher(aIOLoop)
-  , ConnectionOrientedSocketIO(aConsumerThread)
+  : ConnectionOrientedSocketIO(aConsumerThread, aIOLoop)
   , mStreamSocket(aStreamSocket)
   , mConnector(aConnector)
   , mShuttingDownOnIOThread(false)
   , mAddressLength(0)
   , mDelayedConnectTask(nullptr)
 {
   MOZ_ASSERT(mStreamSocket);
   MOZ_ASSERT(mConnector);
 }
 
 StreamSocketIO::StreamSocketIO(nsIThread* aConsumerThread,
                                MessageLoop* aIOLoop,
                                int aFd, ConnectionStatus aConnectionStatus,
                                StreamSocket* aStreamSocket,
                                UnixSocketConnector* aConnector)
-  : UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
-  , ConnectionOrientedSocketIO(aConsumerThread)
+  : ConnectionOrientedSocketIO(aConsumerThread,
+                               aIOLoop,
+                               aFd,
+                               aConnectionStatus)
   , mStreamSocket(aStreamSocket)
   , mConnector(aConnector)
   , mShuttingDownOnIOThread(false)
   , mAddressLength(0)
   , mDelayedConnectTask(nullptr)
 {
   MOZ_ASSERT(mStreamSocket);
   MOZ_ASSERT(mConnector);