diff options
author | Pavel Labath <pavel@labath.sk> | 2024-11-27 09:50:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-27 09:50:33 +0100 |
commit | 072387042021b0f74c24c617b940fe8157f9f1a5 (patch) | |
tree | 6159ede7a610e2943ed174684be8b75aff1bc49e /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | |
parent | 4dfa0216ba7849fde270f27e2358d4327fac988d (diff) | |
download | llvm-072387042021b0f74c24c617b940fe8157f9f1a5.zip llvm-072387042021b0f74c24c617b940fe8157f9f1a5.tar.gz llvm-072387042021b0f74c24c617b940fe8157f9f1a5.tar.bz2 |
[lldb] Add timeout argument to Socket::Accept (#117691)
Allows us to stop waiting for a connection if it doesn't come in a
certain amount of time. Right now, I'm keeping the status quo (infitnite
wait) in the "production" code, but using smaller (finite) values in
tests. (A lot of these tests create "loopback" connections, where a
really short wait is sufficient: on linux at least even a poll (0s wait)
is sufficient if the other end has connect()ed already, but this doesn't
seem to be the case on Windows, so I'm using a 1s wait in these cases).
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 7eacd60..67b41b1 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -1223,10 +1223,6 @@ GDBRemoteCommunication::ConnectLocally(GDBRemoteCommunication &client, listen_socket.Listen("localhost:0", backlog).ToError()) return error; - Socket *accept_socket = nullptr; - std::future<Status> accept_status = std::async( - std::launch::async, [&] { return listen_socket.Accept(accept_socket); }); - llvm::SmallString<32> remote_addr; llvm::raw_svector_ostream(remote_addr) << "connect://localhost:" << listen_socket.GetLocalPortNumber(); @@ -1238,10 +1234,15 @@ GDBRemoteCommunication::ConnectLocally(GDBRemoteCommunication &client, return llvm::createStringError(llvm::inconvertibleErrorCode(), "Unable to connect: %s", status.AsCString()); - client.SetConnection(std::move(conn_up)); - if (llvm::Error error = accept_status.get().ToError()) - return error; + // The connection was already established above, so a short timeout is + // sufficient. + Socket *accept_socket = nullptr; + if (Status accept_status = + listen_socket.Accept(std::chrono::seconds(1), accept_socket); + accept_status.Fail()) + return accept_status.takeError(); + client.SetConnection(std::move(conn_up)); server.SetConnection( std::make_unique<ConnectionFileDescriptor>(accept_socket)); return llvm::Error::success(); |