Bug 835920 - UnixSocket and Ril mis-interpret read() returning 0 as failure and enter infinite reconnect loop - r=kyle.machulis
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 30 Jan 2013 15:13:10 -0500
changeset 120397 f85c0ab347382781cffb4ec3ca76bc7fcab1ad44
parent 120396 6876d078fcdc92b2adb2de93ec9213fee12764bb
child 120398 47354ad87a98bd26f5395bf61c39c52d7ad93ce9
push id24251
push userryanvm@gmail.com
push dateThu, 31 Jan 2013 20:56:22 +0000
treeherdermozilla-central@683b08dc1afd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskyle.machulis
bugs835920
milestone21.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 835920 - UnixSocket and Ril mis-interpret read() returning 0 as failure and enter infinite reconnect loop - r=kyle.machulis
ipc/unixsocket/UnixSocket.cpp
--- a/ipc/unixsocket/UnixSocket.cpp
+++ b/ipc/unixsocket/UnixSocket.cpp
@@ -649,17 +649,17 @@ UnixSocketImpl::OnFileCanReadWithoutBloc
   //
   //   - mIncoming isn't completely read, but there's no more
   //     data available on the socket
   //     If so, break;
   while (true) {
     if (!mIncoming) {
       uint8_t data[MAX_READ_SIZE];
       ssize_t ret = read(aFd, data, MAX_READ_SIZE);
-      if (ret <= 0) {
+      if (ret < 0) {
         if (ret == -1) {
           if (errno == EINTR) {
             continue; // retry system call when interrupted
           }
           else if (errno == EAGAIN || errno == EWOULDBLOCK) {
             return; // no data available: return and re-poll
           }
           // else fall through to error handling on other errno's
@@ -670,21 +670,23 @@ UnixSocketImpl::OnFileCanReadWithoutBloc
         // At this point, assume that we can't actually access
         // the socket anymore
         mReadWatcher.StopWatchingFileDescriptor();
         mWriteWatcher.StopWatchingFileDescriptor();
         nsRefPtr<SocketCloseTask> t = new SocketCloseTask(this);
         NS_DispatchToMainThread(t);
         return;
       }
-      mIncoming = new UnixSocketRawData(ret);
-      memcpy(mIncoming->mData, data, ret);
-      nsRefPtr<SocketReceiveTask> t =
-        new SocketReceiveTask(this, mIncoming.forget());
-      NS_DispatchToMainThread(t);
+      if (ret) {
+        mIncoming = new UnixSocketRawData(ret);
+        memcpy(mIncoming->mData, data, ret);
+        nsRefPtr<SocketReceiveTask> t =
+          new SocketReceiveTask(this, mIncoming.forget());
+        NS_DispatchToMainThread(t);
+      }
       if (ret < ssize_t(MAX_READ_SIZE)) {
         return;
       }
     }
   }
 }
 
 void