Bug 1528352: Logging improvements in nsUDPSocket, and handle negative returns from PR_RecvFrom properly. r=mayhemer
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 28 Feb 2019 15:17:27 +0000
changeset 461964 99eceab65655f71b82886e4fbb6fa3e557e075f5
parent 461963 07903d118908485d1b6ae19befd6b424af710a20
child 461965 214aa79533cd44a15f8a45ab9a3eee05dd957047
push id79373
push userbcampen@mozilla.com
push dateFri, 01 Mar 2019 13:53:04 +0000
treeherderautoland@99eceab65655 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1528352
milestone67.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 1528352: Logging improvements in nsUDPSocket, and handle negative returns from PR_RecvFrom properly. r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D20565
netwerk/base/nsUDPSocket.cpp
--- a/netwerk/base/nsUDPSocket.cpp
+++ b/netwerk/base/nsUDPSocket.cpp
@@ -265,16 +265,19 @@ void nsUDPSocket::OnMsgAttach() {
   UDPSOCKET_LOG(("nsUDPSocket::OnMsgAttach [this=%p]\n", this));
 
   if (NS_FAILED(mCondition)) return;
 
   mCondition = TryAttach();
 
   // if we hit an error while trying to attach then bail...
   if (NS_FAILED(mCondition)) {
+    UDPSOCKET_LOG(("nsUDPSocket::OnMsgAttach: TryAttach FAILED err=0x%" PRIx32
+                   " [this=%p]\n",
+                   static_cast<uint32_t>(mCondition), this));
     NS_ASSERTION(!mAttached, "should not be attached already");
     OnSocketDetached(mFD);
   }
 }
 
 nsresult nsUDPSocket::TryAttach() {
   nsresult rv;
 
@@ -378,37 +381,46 @@ UDPMessageProxy::GetOutputStream(nsIOutp
 
 }  // anonymous namespace
 
 //-----------------------------------------------------------------------------
 // nsUDPSocket::nsASocketHandler
 //-----------------------------------------------------------------------------
 
 void nsUDPSocket::OnSocketReady(PRFileDesc* fd, int16_t outFlags) {
+  UDPSOCKET_LOG(
+      ("nsUDPSocket::OnSocketReady: flags=%d [this=%p]\n", outFlags, this));
   NS_ASSERTION(NS_SUCCEEDED(mCondition), "oops");
   NS_ASSERTION(mFD == fd, "wrong file descriptor");
   NS_ASSERTION(outFlags != -1, "unexpected timeout condition reached");
 
   if (outFlags & (PR_POLL_HUP | PR_POLL_NVAL)) {
     NS_WARNING("error polling on listening socket");
     mCondition = NS_ERROR_UNEXPECTED;
     return;
   }
 
   PRNetAddr prClientAddr;
-  uint32_t count;
+  int32_t count;
   // Bug 1252755 - use 9216 bytes to allign with nICEr and transportlayer to
   // support the maximum size of jumbo frames
   char buff[9216];
   count = PR_RecvFrom(mFD, buff, sizeof(buff), 0, &prClientAddr,
                       PR_INTERVAL_NO_WAIT);
+  if (count < 0) {
+    UDPSOCKET_LOG(
+        ("nsUDPSocket::OnSocketReady: PR_RecvFrom failed [this=%p]\n", this));
+    return;
+  }
   mByteReadCount += count;
 
   FallibleTArray<uint8_t> data;
   if (!data.AppendElements(buff, count, fallible)) {
+    UDPSOCKET_LOG((
+        "nsUDPSocket::OnSocketReady: AppendElements FAILED [this=%p]\n", this));
     mCondition = NS_ERROR_UNEXPECTED;
     return;
   }
 
   nsCOMPtr<nsIAsyncInputStream> pipeIn;
   nsCOMPtr<nsIAsyncOutputStream> pipeOut;
 
   uint32_t segsize = UDP_PACKET_CHUNK_SIZE;
@@ -432,16 +444,17 @@ void nsUDPSocket::OnSocketReady(PRFileDe
   NetAddr netAddr;
   PRNetAddrToNetAddr(&prClientAddr, &netAddr);
   nsCOMPtr<nsIUDPMessage> message =
       new UDPMessageProxy(&netAddr, pipeOut, data);
   mListener->OnPacketReceived(this, message);
 }
 
 void nsUDPSocket::OnSocketDetached(PRFileDesc* fd) {
+  UDPSOCKET_LOG(("nsUDPSocket::OnSocketDetached [this=%p]\n", this));
   // force a failure condition if none set; maybe the STS is shutting down :-/
   if (NS_SUCCEEDED(mCondition)) mCondition = NS_ERROR_ABORT;
 
   if (mFD) {
     NS_ASSERTION(mFD == fd, "wrong file descriptor");
     CloseSocket();
   }