Make sure MASQUE TCP socket events get rearmed

This isn't necessary in internal builds because those event loops support edge trigger, however the open source QUICHE build does not.

This CL also adds a few logs.

PiperOrigin-RevId: 846426663
diff --git a/quiche/BUILD.bazel b/quiche/BUILD.bazel
index 1c5a99c..55f28cc 100644
--- a/quiche/BUILD.bazel
+++ b/quiche/BUILD.bazel
@@ -622,6 +622,7 @@
         ":quiche_tool_support",
         "@boringssl//:crypto",
         "@boringssl//:ssl",
+        "@com_google_absl//absl/cleanup",
         "@com_google_absl//absl/container:flat_hash_map",
         "@com_google_absl//absl/status",
         "@com_google_absl//absl/status:statusor",
diff --git a/quiche/quic/masque/masque_connection_pool.cc b/quiche/quic/masque/masque_connection_pool.cc
index afca6b9..33a94a2 100644
--- a/quiche/quic/masque/masque_connection_pool.cc
+++ b/quiche/quic/masque/masque_connection_pool.cc
@@ -11,6 +11,7 @@
 #include <utility>
 #include <vector>
 
+#include "absl/cleanup/cleanup.h"
 #include "absl/status/status.h"
 #include "absl/status/statusor.h"
 #include "absl/strings/str_cat.h"
@@ -158,6 +159,8 @@
     if (authority_header->second != authority) {
       continue;
     }
+    QUICHE_LOG(INFO) << "Attaching connection to pending request for "
+                     << authority;
     pending_request.connection = connection;
   }
 }
@@ -170,6 +173,7 @@
       ++it;
       continue;
     }
+    QUICHE_LOG(INFO) << "Sending pending request ID " << request_id;
     int32_t stream_id = connection->SendRequest(pending_request.request.headers,
                                                 pending_request.request.body);
     if (stream_id < 0) {
@@ -179,6 +183,7 @@
       pending_requests_.erase(it++);
       continue;
     }
+    connection->AttemptToSend();
     pending_request.stream_id = stream_id;
     ++it;
   }
@@ -251,7 +256,8 @@
     QUICHE_LOG(ERROR) << "Failed to register socket with the event loop";
     return false;
   }
-  QUICHE_LOG(INFO) << "Socket connect in progress to " << socket_address;
+  QUICHE_LOG(INFO) << "Socket fd " << socket_ << " connect in progress to "
+                   << socket_address;
 
   if (disable_certificate_verification) {
     proof_verifier_ = std::make_unique<FakeProofVerifier>();
@@ -266,7 +272,16 @@
 }
 
 void MasqueConnectionPool::ConnectionState::OnSocketEvent(
-    QuicEventLoop* /*event_loop*/, SocketFd fd, QuicSocketEventMask events) {
+    QuicEventLoop* event_loop, SocketFd fd, QuicSocketEventMask events) {
+  auto cleanup = absl::MakeCleanup([event_loop, fd]() {
+    if (!event_loop->SupportsEdgeTriggered()) {
+      if (!event_loop->RearmSocket(
+              fd, kSocketEventReadable | kSocketEventWritable)) {
+        QUICHE_LOG(FATAL) << "Failed to re-arm socket " << fd;
+      }
+    }
+  });
+
   if (fd != socket_) {
     return;
   }
diff --git a/quiche/quic/masque/masque_h2_connection.cc b/quiche/quic/masque/masque_h2_connection.cc
index ac6b80c..ce3a9e7 100644
--- a/quiche/quic/masque/masque_h2_connection.cc
+++ b/quiche/quic/masque/masque_h2_connection.cc
@@ -55,6 +55,7 @@
 }
 
 void MasqueH2Connection::StartH2() {
+  QUICHE_LOG(INFO) << ENDPOINT << "Starting H2";
   http2::adapter::OgHttp2Adapter::Options options;
   std::vector<Http2Setting> settings;
   if (is_server_) {
diff --git a/quiche/quic/masque/masque_tcp_server_bin.cc b/quiche/quic/masque/masque_tcp_server_bin.cc
index 4b51846..b8c872f 100644
--- a/quiche/quic/masque/masque_tcp_server_bin.cc
+++ b/quiche/quic/masque/masque_tcp_server_bin.cc
@@ -20,6 +20,7 @@
 #include <utility>
 #include <vector>
 
+#include "absl/cleanup/cleanup.h"
 #include "absl/container/flat_hash_map.h"
 #include "absl/status/status.h"
 #include "absl/status/statusor.h"
@@ -316,8 +317,16 @@
   }
 
   // From QuicSocketEventListener.
-  void OnSocketEvent(QuicEventLoop* /*event_loop*/, SocketFd fd,
+  void OnSocketEvent(QuicEventLoop* event_loop, SocketFd fd,
                      QuicSocketEventMask events) {
+    auto cleanup = absl::MakeCleanup([event_loop, fd]() {
+      if (!event_loop->SupportsEdgeTriggered()) {
+        if (!event_loop->RearmSocket(
+                fd, kSocketEventReadable | kSocketEventWritable)) {
+          QUICHE_LOG(FATAL) << "Failed to re-arm socket " << fd;
+        }
+      }
+    });
     if (fd != socket_ || ((events & kSocketEventReadable) == 0)) {
       return;
     }