Do not block on control socket.

This is a cherry-pick of 906e06987f66cfbd46cdd586a15b0072b2fbed19

Test: $ tools/heap_profile -i 1 --no-block-client -n system_server
      does not slow down phone
Test: $ tools/heap_profile -n system_server
      produces profile

Bug: 143934224
Change-Id: Iff8cad6f3dfbcf2f29a17b4e871996a43181dfea
Merged-In: Iff8cad6f3dfbcf2f29a17b4e871996a43181dfea
diff --git a/src/profiling/memory/client.cc b/src/profiling/memory/client.cc
index 59c7e20..37453d1 100644
--- a/src/profiling/memory/client.cc
+++ b/src/profiling/memory/client.cc
@@ -202,10 +202,7 @@
   }
 
   PERFETTO_DCHECK(client_config.interval >= 1);
-  // TODO(fmayer): Always make this nonblocking.
-  // This is so that without block_client, we get the old behaviour that rate
-  // limits using the blocking socket. We do not want to change that for Q.
-  sock.SetBlocking(!client_config.block_client);
+  sock.SetBlocking(false);
   Sampler sampler{client_config.interval};
   // note: the shared_ptr will retain a copy of the unhooked_allocator
   return std::allocate_shared<Client>(unhooked_allocator, std::move(sock),
@@ -368,10 +365,12 @@
 }
 
 bool Client::SendControlSocketByte() {
-  // TODO(fmayer): Fix the special casing that only block_client uses a
-  // nonblocking socket.
+  // If base::IsAgain(errno), the socket buffer is full, so the service will
+  // pick up the notification even without adding another byte.
+  // In other error cases (usually EPIPE) we want to disconnect, because that
+  // is how the service signals the tracing session was torn down.
   if (sock_.Send(kSingleByte, sizeof(kSingleByte)) == -1 &&
-      (!client_config_.block_client || !base::IsAgain(errno))) {
+      !base::IsAgain(errno)) {
     PERFETTO_PLOG("Failed to send control socket byte.");
     return false;
   }
diff --git a/src/profiling/memory/unwinding.cc b/src/profiling/memory/unwinding.cc
index cc79477..31b9a9c 100644
--- a/src/profiling/memory/unwinding.cc
+++ b/src/profiling/memory/unwinding.cc
@@ -314,9 +314,7 @@
     shmem.EndRead(std::move(buf));
     // Reparsing takes time, so process the rest in a new batch to avoid timing
     // out.
-    // TODO(fmayer): Do not special case blocking mode.
-    if (client_data.client_config.block_client &&
-        reparses_before < client_data.metadata.reparses) {
+    if (reparses_before < client_data.metadata.reparses) {
       repost_task = true;
       break;
     }