Merge m-c to b2g-inbound on a CLOSED TREE.
authorRyan VanderMeulen <ryanvm@gmail.com>
Fri, 24 Jan 2014 17:24:54 -0500
changeset 181249 d1602db7c9043d64bc633ea9bf3c0d1149e46273
parent 181248 c1c5c07399e13c12f59326facee72e50d9bf3ce9 (current diff)
parent 181169 eb8c4ec52bc0fb1446efc222a780e2dbe0693e77 (diff)
child 181250 f62f3118df8f924e9e628c9e993a65037ff8c5ee
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone29.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
Merge m-c to b2g-inbound on a CLOSED TREE.
--- a/ipc/unixsocket/UnixSocket.cpp
+++ b/ipc/unixsocket/UnixSocket.cpp
@@ -169,19 +169,16 @@ public:
   /**
    * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
    * directly from main thread. All non-main-thread accesses should happen with
    * mImpl as container.
    */
   RefPtr<UnixSocketConsumer> mConsumer;
 
 private:
-
-  void FireSocketError();
-
   /**
    * libevent triggered functions that reads data from socket when available and
    * guarenteed non-blocking. Only to be called on IO thread.
    *
    * @param aFd File descriptor to read from
    */
   virtual void OnFileCanReadWithoutBlocking(int aFd);
 
@@ -485,132 +482,126 @@ void ShutdownSocketTask::Run()
   mImpl->ShutdownOnIOThread();
 
   nsRefPtr<nsIRunnable> t(new DeleteInstanceRunnable<UnixSocketImpl>(mImpl));
   nsresult rv = NS_DispatchToMainThread(t);
   NS_ENSURE_SUCCESS_VOID(rv);
 }
 
 void
-UnixSocketImpl::FireSocketError()
+UnixSocketImpl::Accept()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
-  // Clean up watchers, statuses, fds
-  mReadWatcher.StopWatchingFileDescriptor();
-  mWriteWatcher.StopWatchingFileDescriptor();
-  mConnectionStatus = SOCKET_DISCONNECTED;
-  mFd.reset(-1);
-
-  // Tell the main thread we've errored
-  nsRefPtr<OnSocketEventTask> t =
-    new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
-  NS_DispatchToMainThread(t);
-}
-
-void
-UnixSocketImpl::Accept()
-{
-  MOZ_ASSERT(!NS_IsMainThread());
-  MOZ_ASSERT(mConnector);
+  if (!mConnector) {
+    NS_WARNING("No connector object available!");
+    return;
+  }
 
   // This will set things we don't particularly care about, but it will hand
   // back the correct structure size which is what we do care about.
   if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) {
     NS_WARNING("Cannot create socket address!");
-    FireSocketError();
     return;
   }
 
   if (mFd.get() < 0) {
     mFd = mConnector->Create();
     if (mFd.get() < 0) {
-      NS_WARNING("Cannot create socket fd!");
-      FireSocketError();
       return;
     }
 
     if (!SetSocketFlags()) {
-      NS_WARNING("Cannot set socket flags!");
-      FireSocketError();
       return;
     }
 
     if (bind(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize)) {
 #ifdef DEBUG
       CHROMIUM_LOG("...bind(%d) gave errno %d", mFd.get(), errno);
 #endif
-      FireSocketError();
       return;
     }
 
     if (listen(mFd.get(), 1)) {
 #ifdef DEBUG
       CHROMIUM_LOG("...listen(%d) gave errno %d", mFd.get(), errno);
 #endif
-      FireSocketError();
       return;
     }
 
     if (!mConnector->SetUpListenSocket(mFd)) {
       NS_WARNING("Could not set up listen socket!");
-      FireSocketError();
+      nsRefPtr<OnSocketEventTask> t =
+        new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+      NS_DispatchToMainThread(t);
+      mConnectionStatus = SOCKET_DISCONNECTED;
       return;
     }
 
   }
 
   SetUpIO();
 }
 
 void
 UnixSocketImpl::Connect()
 {
   MOZ_ASSERT(!NS_IsMainThread());
-  MOZ_ASSERT(mConnector);
+
+  if (!mConnector) {
+    NS_WARNING("No connector object available!");
+    return;
+  }
 
   if (mFd.get() < 0) {
     mFd = mConnector->Create();
     if (mFd.get() < 0) {
-      NS_WARNING("Cannot create socket fd!");
-      FireSocketError();
       return;
     }
   }
 
   int ret;
 
   if (!mConnector->CreateAddr(false, mAddrSize, mAddr, mAddress.get())) {
     NS_WARNING("Cannot create socket address!");
-    FireSocketError();
     return;
   }
 
   // Select non-blocking IO.
   if (-1 == fcntl(mFd.get(), F_SETFL, O_NONBLOCK)) {
-    NS_WARNING("Cannot set nonblock!");
-    FireSocketError();
+    nsRefPtr<OnSocketEventTask> t =
+      new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+    NS_DispatchToMainThread(t);
+    mConnectionStatus = SOCKET_DISCONNECTED;
     return;
   }
 
   ret = connect(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize);
 
   if (ret) {
     if (errno == EINPROGRESS) {
       // Select blocking IO again, since we've now at least queue'd the connect
       // as nonblock.
       int current_opts = fcntl(mFd.get(), F_GETFL, 0);
       if (-1 == current_opts) {
         NS_WARNING("Cannot get socket opts!");
-        FireSocketError();
+        mFd.reset(-1);
+        nsRefPtr<OnSocketEventTask> t =
+          new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+        NS_DispatchToMainThread(t);
+        mConnectionStatus = SOCKET_DISCONNECTED;
         return;
       }
       if (-1 == fcntl(mFd.get(), F_SETFL, current_opts & ~O_NONBLOCK)) {
         NS_WARNING("Cannot set socket opts to blocking!");
-        FireSocketError();
+        mFd.reset(-1);
+        nsRefPtr<OnSocketEventTask> t =
+          new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+        NS_DispatchToMainThread(t);
+        mConnectionStatus = SOCKET_DISCONNECTED;
         return;
       }
 
       // Set up a write watch to make sure we receive the connect signal
       MessageLoopForIO::current()->WatchFileDescriptor(
         mFd.get(),
         false,
         MessageLoopForIO::WATCH_WRITE,
@@ -620,29 +611,30 @@ UnixSocketImpl::Connect()
 #ifdef DEBUG
       CHROMIUM_LOG("UnixSocket Connection delayed!");
 #endif
       return;
     }
 #if DEBUG
     CHROMIUM_LOG("Socket connect errno=%d\n", errno);
 #endif
-    FireSocketError();
+    mFd.reset(-1);
+    nsRefPtr<OnSocketEventTask> t =
+      new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+    NS_DispatchToMainThread(t);
+    mConnectionStatus = SOCKET_DISCONNECTED;
     return;
   }
 
   if (!SetSocketFlags()) {
-    NS_WARNING("Cannot set socket flags!");
-    FireSocketError();
     return;
   }
 
   if (!mConnector->SetUp(mFd)) {
     NS_WARNING("Could not set up socket!");
-    FireSocketError();
     return;
   }
 
   nsRefPtr<OnSocketEventTask> t =
     new OnSocketEventTask(this, OnSocketEventTask::CONNECT_SUCCESS);
   NS_DispatchToMainThread(t);
   mConnectionStatus = SOCKET_CONNECTED;
 
@@ -865,29 +857,40 @@ UnixSocketImpl::OnFileCanWriteWithoutBlo
     }
   } else if (mConnectionStatus == SOCKET_CONNECTING) {
     int error, ret;
     socklen_t len = sizeof(error);
     ret = getsockopt(mFd.get(), SOL_SOCKET, SO_ERROR, &error, &len);
 
     if (ret || error) {
       NS_WARNING("getsockopt failure on async socket connect!");
-      FireSocketError();
+      mFd.reset(-1);
+      nsRefPtr<OnSocketEventTask> t =
+        new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+      NS_DispatchToMainThread(t);
+      mConnectionStatus = SOCKET_DISCONNECTED;
       return;
     }
 
     if (!SetSocketFlags()) {
-      NS_WARNING("Cannot set socket flags!");
-      FireSocketError();
+      mFd.reset(-1);
+      nsRefPtr<OnSocketEventTask> t =
+        new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+      NS_DispatchToMainThread(t);
+      mConnectionStatus = SOCKET_DISCONNECTED;
       return;
     }
 
     if (!mConnector->SetUp(mFd)) {
       NS_WARNING("Could not set up socket!");
-      FireSocketError();
+      mFd.reset(-1);
+      nsRefPtr<OnSocketEventTask> t =
+        new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
+      NS_DispatchToMainThread(t);
+      mConnectionStatus = SOCKET_DISCONNECTED;
       return;
     }
 
     nsRefPtr<OnSocketEventTask> t =
       new OnSocketEventTask(this, OnSocketEventTask::CONNECT_SUCCESS);
     NS_DispatchToMainThread(t);
     mConnectionStatus = SOCKET_CONNECTED;