1515#include " RunInTerminal.h"
1616#include " lldb/API/SBStream.h"
1717#include " lldb/Host/Config.h"
18+ #include " lldb/Host/File.h"
1819#include " lldb/Host/MainLoop.h"
1920#include " lldb/Host/MainLoopBase.h"
2021#include " lldb/Host/Socket.h"
@@ -80,7 +81,11 @@ typedef int socklen_t;
8081#endif
8182
8283using namespace lldb_dap ;
83- using lldb_private::NativeSocket;
84+ using lldb_private::File;
85+ using lldb_private::IOObject;
86+ using lldb_private::MainLoop;
87+ using lldb_private::MainLoopBase;
88+ using lldb_private::NativeFile;
8489using lldb_private::Socket;
8590using lldb_private::Status;
8691
@@ -308,14 +313,14 @@ serveConnection(const Socket::SocketProtocol &protocol, const std::string &name,
308313 // address.
309314 llvm::outs ().flush ();
310315
311- static lldb_private:: MainLoop g_loop;
316+ static MainLoop g_loop;
312317 llvm::sys::SetInterruptFunction ([]() {
313318 g_loop.AddPendingCallback (
314- [](lldb_private:: MainLoopBase &loop) { loop.RequestTermination (); });
319+ [](MainLoopBase &loop) { loop.RequestTermination (); });
315320 });
316321 std::condition_variable dap_sessions_condition;
317322 std::mutex dap_sessions_mutex;
318- std::map<Socket *, DAP *> dap_sessions;
323+ std::map<IOObject *, DAP *> dap_sessions;
319324 unsigned int clientCount = 0 ;
320325 auto handle = listener->Accept (g_loop, [=, &dap_sessions_condition,
321326 &dap_sessions_mutex, &dap_sessions,
@@ -329,18 +334,15 @@ serveConnection(const Socket::SocketProtocol &protocol, const std::string &name,
329334 << " client connected: " << name << " \n " ;
330335 }
331336
337+ lldb::IOObjectSP io (std::move (sock));
338+
332339 // Move the client into a background thread to unblock accepting the next
333340 // client.
334341 std::thread client ([=, &dap_sessions_condition, &dap_sessions_mutex,
335- &dap_sessions, sock = std::move (sock) ]() {
342+ &dap_sessions]() {
336343 llvm::set_thread_name (name + " .runloop" );
337- StreamDescriptor input =
338- StreamDescriptor::from_socket (sock->GetNativeSocket (), false );
339- // Close the output last for the best chance at error reporting.
340- StreamDescriptor output =
341- StreamDescriptor::from_socket (sock->GetNativeSocket (), false );
342- DAP dap = DAP (name, program_path, log, std::move (input),
343- std::move (output), default_repl_mode, pre_init_commands);
344+ DAP dap = DAP (name, program_path, log, io, io, default_repl_mode,
345+ pre_init_commands);
344346
345347 if (auto Err = dap.ConfigureIO ()) {
346348 llvm::logAllUnhandledErrors (std::move (Err), llvm::errs (),
@@ -352,7 +354,7 @@ serveConnection(const Socket::SocketProtocol &protocol, const std::string &name,
352354
353355 {
354356 std::scoped_lock<std::mutex> lock (dap_sessions_mutex);
355- dap_sessions[sock .get ()] = &dap;
357+ dap_sessions[io .get ()] = &dap;
356358 }
357359
358360 if (auto Err = dap.Loop ()) {
@@ -368,7 +370,7 @@ serveConnection(const Socket::SocketProtocol &protocol, const std::string &name,
368370 }
369371
370372 std::unique_lock<std::mutex> lock (dap_sessions_mutex);
371- dap_sessions.erase (sock .get ());
373+ dap_sessions.erase (io .get ());
372374 std::notify_all_at_thread_exit (dap_sessions_condition, std::move (lock));
373375 });
374376 client.detach ();
@@ -560,8 +562,10 @@ int main(int argc, char *argv[]) {
560562 return EXIT_FAILURE;
561563 }
562564
563- StreamDescriptor input = StreamDescriptor::from_file (fileno (stdin), false );
564- StreamDescriptor output = StreamDescriptor::from_file (stdout_fd, false );
565+ lldb::IOObjectSP input = std::make_shared<NativeFile>(
566+ fileno (stdin), File::eOpenOptionReadOnly, true );
567+ lldb::IOObjectSP output = std::make_shared<NativeFile>(
568+ stdout_fd, File::eOpenOptionWriteOnly, false );
565569
566570 DAP dap = DAP (" stdin/stdout" , program_path, log.get (), std::move (input),
567571 std::move (output), default_repl_mode, pre_init_commands);
0 commit comments