Bug 1159709: Cleanup inherited methods of |ListenSocket|, r=kmachulis
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 30 Apr 2015 12:55:37 +0200
changeset 271527 694eac9d36bb23c604338a160e8eb77e4bb63119
parent 271526 651f34fe1c01c228dcdabf2ff887d62a4cad102e
child 271528 201ab3b6bb68d6894b6010d55ed41acfa839cc25
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmachulis
bugs1159709
milestone40.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 1159709: Cleanup inherited methods of |ListenSocket|, r=kmachulis This patch cleans up the inherited methods of |ListenSocket|. Methods of the same base class are grouped within the file, and each method is labeled with 'override'.
ipc/unixsocket/ListenSocket.cpp
ipc/unixsocket/ListenSocket.h
--- a/ipc/unixsocket/ListenSocket.cpp
+++ b/ipc/unixsocket/ListenSocket.cpp
@@ -14,40 +14,30 @@
 
 namespace mozilla {
 namespace ipc {
 
 //
 // ListenSocketIO
 //
 
-class ListenSocketIO final : public UnixSocketWatcher
-                           , public SocketIOBase
+class ListenSocketIO final
+  : public UnixSocketWatcher
+  , public SocketIOBase
 {
 public:
   class ListenTask;
 
   ListenSocketIO(MessageLoop* mIOLoop,
                  ListenSocket* aListenSocket,
                  UnixSocketConnector* aConnector,
                  const nsACString& aAddress);
   ~ListenSocketIO();
 
-  void        GetSocketAddr(nsAString& aAddrStr) const;
-  DataSocket* GetDataSocket();
-  SocketBase* GetSocketBase() override;
-
-  // Shutdown state
-  //
-
-  bool IsShutdownOnMainThread() const override;
-  void ShutdownOnMainThread() override;
-
-  bool IsShutdownOnIOThread() const override;
-  void ShutdownOnIOThread() override;
+  void GetSocketAddr(nsAString& aAddrStr) const;
 
   // Task callback methods
   //
 
   /**
    * Run bind/listen to prepare for further runs of accept()
    */
   void Listen(ConnectionOrientedSocketIO* aCOSocketIO);
@@ -56,16 +46,27 @@ public:
   //
 
   void OnAccepted(int aFd, const sockaddr_any* aAddr,
                   socklen_t aAddrLen) override;
   void OnConnected() override;
   void OnError(const char* aFunction, int aErrno) override;
   void OnListening() override;
 
+  // Methods for |SocketIOBase|
+  //
+
+  SocketBase* GetSocketBase() override;
+
+  bool IsShutdownOnMainThread() const override;
+  bool IsShutdownOnIOThread() const override;
+
+  void ShutdownOnMainThread() override;
+  void ShutdownOnIOThread() override;
+
 private:
   void FireSocketError();
 
   // Set up flags on file descriptor.
   static bool SetSocketFlags(int aFd);
 
   /**
    * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
@@ -130,63 +131,16 @@ ListenSocketIO::GetSocketAddr(nsAString&
   if (!mConnector) {
     NS_WARNING("No connector to get socket address from!");
     aAddrStr.Truncate();
     return;
   }
   mConnector->GetSocketAddr(mAddr, aAddrStr);
 }
 
-DataSocket*
-ListenSocketIO::GetDataSocket()
-{
-  MOZ_CRASH("Listen sockets cannot transfer data");
-
-  return nullptr;
-}
-
-SocketBase*
-ListenSocketIO::GetSocketBase()
-{
-  return mListenSocket.get();
-}
-
-bool
-ListenSocketIO::IsShutdownOnMainThread() const
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  return mListenSocket == nullptr;
-}
-
-void
-ListenSocketIO::ShutdownOnMainThread()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!IsShutdownOnMainThread());
-
-  mListenSocket = nullptr;
-}
-
-bool
-ListenSocketIO::IsShutdownOnIOThread() const
-{
-  return mShuttingDownOnIOThread;
-}
-
-void
-ListenSocketIO::ShutdownOnIOThread()
-{
-  MOZ_ASSERT(!NS_IsMainThread());
-  MOZ_ASSERT(!mShuttingDownOnIOThread);
-
-  Close(); // will also remove fd from I/O loop
-  mShuttingDownOnIOThread = true;
-}
-
 void
 ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO)
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(mConnector);
   MOZ_ASSERT(aCOSocketIO);
 
   if (!IsOpen()) {
@@ -314,16 +268,57 @@ ListenSocketIO::SetSocketFlags(int aFd)
   flags |= O_NONBLOCK;
   if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags))) {
     return false;
   }
 
   return true;
 }
 
+// |SocketIOBase|
+
+SocketBase*
+ListenSocketIO::GetSocketBase()
+{
+  return mListenSocket.get();
+}
+
+bool
+ListenSocketIO::IsShutdownOnMainThread() const
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  return mListenSocket == nullptr;
+}
+
+bool
+ListenSocketIO::IsShutdownOnIOThread() const
+{
+  return mShuttingDownOnIOThread;
+}
+
+void
+ListenSocketIO::ShutdownOnMainThread()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!IsShutdownOnMainThread());
+
+  mListenSocket = nullptr;
+}
+
+void
+ListenSocketIO::ShutdownOnIOThread()
+{
+  MOZ_ASSERT(!NS_IsMainThread());
+  MOZ_ASSERT(!mShuttingDownOnIOThread);
+
+  Close(); // will also remove fd from I/O loop
+  mShuttingDownOnIOThread = true;
+}
+
 //
 // Socket tasks
 //
 
 class ListenSocketIO::ListenTask final
   : public SocketIOTask<ListenSocketIO>
 {
 public:
@@ -424,10 +419,18 @@ ListenSocket::GetSocketAddr(nsAString& a
   aAddrStr.Truncate();
   if (!mIO || GetConnectionStatus() != SOCKET_CONNECTED) {
     NS_WARNING("No socket currently open!");
     return;
   }
   mIO->GetSocketAddr(aAddrStr);
 }
 
+// |SocketBase|
+
+void
+ListenSocket::CloseSocket()
+{
+  Close();
+}
+
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/unixsocket/ListenSocket.h
+++ b/ipc/unixsocket/ListenSocket.h
@@ -56,23 +56,21 @@ public:
    */
   void Close();
 
   /**
    * Get the current sockaddr for the socket
    */
   void GetSocketAddr(nsAString& aAddrStr);
 
-private:
+  // Methods for |SocketBase|
+  //
 
-  // Legacy interface from |SocketBase|; should be replaced by |Close|.
-  void CloseSocket() override
-  {
-    Close();
-  }
+  void CloseSocket() override;
 
+private:
   ListenSocketIO* mIO;
 };
 
 } // namespace ipc
 } // namepsace mozilla
 
 #endif // mozilla_ipc_listensocket_h