================
@@ -601,15 +570,24 @@ int main_platform(int argc, char *argv[]) {
       // If not running as a server, this process will not accept
       // connections while a connection is active.
       acceptor_up.reset();
-
-      // When not running in server mode, use all available ports
-      platform.SetPortMap(std::move(gdbserver_portmap));
     }
 
     platform.SetConnection(std::unique_ptr<Connection>(conn));
     client_handle(platform, inferior_arguments);
   } while (g_server);
 
+  // FIXME: Make TCPSocket::CloseListenSockets() public and implement
+  // Acceptor::Close().
+  /*
+  if (acceptor_gdb && gdb_thread.IsJoinable()) {
+    g_listen_gdb = false;
+    static_cast<TCPSocket *>(acceptor_gdb->m_listener_socket_up.get())
+        ->CloseListenSockets();
+    lldb::thread_result_t result;
+    gdb_thread.Join(&result);
+  }
+  */
+
----------------
labath wrote:

This won't work. This is exactly the pattern from that kernel bug we were 
arguing over. It's just not possible to safely close an fd while another thread 
may be operating on it.

You need to use an out-of-band mechanism (e.g. a pipe) to notify the thread 
that it's time to terminate. However, since that will involve some form of 
multiplexing (e.g. `select(2)`). I would strongly prefer to just multiplex over 
the two sockets we are accepting. We should be able to use the `MainLoop` class 
for that -- just register the two sockets with the class, and let it call the 
right callback when needed. Basically, the code should look similar to 
[this](https://github.com/llvm/llvm-project/blob/f71b63865140cf3c286baf3a77ba3e467f929504/lldb/source/Host/common/TCPSocket.cpp#L267),
 except that it will be listening to two unrelated sockets.

https://github.com/llvm/llvm-project/pull/104238
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to