///
/// \see
/// class Connection
- void SetConnection(Connection *connection);
+ void SetConnection(std::unique_ptr<Connection> connection);
/// Starts a read thread whose sole purpose it to read bytes from the
/// current connection. This function will call connection's read function:
if (m_opaque) {
if (!m_opaque->HasConnection())
- m_opaque->SetConnection(Host::CreateDefaultConnection(url).release());
+ m_opaque->SetConnection(Host::CreateDefaultConnection(url));
return m_opaque->Connect(url, nullptr);
}
return eConnectionStatusNoConnection;
if (m_opaque->IsConnected())
m_opaque->Disconnect();
}
- m_opaque->SetConnection(new ConnectionFileDescriptor(fd, owns_fd));
+ m_opaque->SetConnection(
+ std::make_unique<ConnectionFileDescriptor>(fd, owns_fd));
if (m_opaque->IsConnected())
status = eConnectionStatusSuccess;
else
listener_sp->GetEvent(event_sp, llvm::None);
}
-void Communication::SetConnection(Connection *connection) {
+void Communication::SetConnection(std::unique_ptr<Connection> connection) {
Disconnect(nullptr);
StopReadThread(nullptr);
- m_connection_sp.reset(connection);
+ m_connection_sp = std::move(connection);
}
const char *
GetHostname());
} else {
if (args.GetArgumentCount() == 1) {
- m_gdb_client.SetConnection(new ConnectionFileDescriptor());
+ m_gdb_client.SetConnection(std::make_unique<ConnectionFileDescriptor>());
// we're going to reuse the hostname when we connect to the debugserver
int port;
std::string path;
const uint16_t reply_port = socket.GetLocalPortNumber();
if (reply_port != 0) {
- m_comm.SetConnection(conn_up.release());
+ m_comm.SetConnection(std::move(conn_up));
if (m_comm.SendRequestReattach(reply_port)) {
if (m_comm.SendRequestConnect(reply_port, reply_port,
else
snprintf(listen_url, sizeof(listen_url), "listen://%i", port);
m_listen_url = listen_url;
- SetConnection(new ConnectionFileDescriptor());
+ SetConnection(std::make_unique<ConnectionFileDescriptor>());
llvm::Expected<HostThread> listen_thread = ThreadLauncher::LaunchThread(
listen_url, GDBRemoteCommunication::ListenThread, this);
if (!listen_thread)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Unable to connect: %s", status.AsCString());
- client.SetConnection(conn_up.release());
+ client.SetConnection(std::move(conn_up));
if (llvm::Error error = accept_status.get().ToError())
return error;
- server.SetConnection(new ConnectionFileDescriptor(accept_socket));
+ server.SetConnection(
+ std::make_unique<ConnectionFileDescriptor>(accept_socket));
return llvm::Error::success();
}
}
Status GDBRemoteCommunicationServerLLGS::InitializeConnection(
- std::unique_ptr<Connection> &&connection) {
+ std::unique_ptr<Connection> connection) {
IOObjectSP read_object_sp = connection->GetReadObject();
- GDBRemoteCommunicationServer::SetConnection(connection.release());
+ GDBRemoteCommunicationServer::SetConnection(std::move(connection));
Status error;
m_network_handle_up = m_mainloop.RegisterReadObject(
}
m_stdio_communication.SetCloseOnEOF(false);
- m_stdio_communication.SetConnection(conn_up.release());
+ m_stdio_communication.SetConnection(std::move(conn_up));
if (!m_stdio_communication.IsConnected()) {
error.SetErrorString(
"failed to set connection for inferior I/O communication");
void DidExec(NativeProcessProtocol *process) override;
- Status InitializeConnection(std::unique_ptr<Connection> &&connection);
+ Status InitializeConnection(std::unique_ptr<Connection> connection);
protected:
MainLoop &m_mainloop;
uint32_t retry_count = 0;
while (!m_gdb_comm.IsConnected()) {
if (conn_up->Connect(connect_url, &error) == eConnectionStatusSuccess) {
- m_gdb_comm.SetConnection(conn_up.release());
+ m_gdb_comm.SetConnection(std::move(conn_up));
break;
} else if (error.WasInterrupted()) {
// If we were interrupted, don't keep retrying.
// Our process spawned correctly, we can now set our connection to use
// our end of the socket pair
cleanup_our.release();
- m_gdb_comm.SetConnection(new ConnectionFileDescriptor(our_socket, true));
+ m_gdb_comm.SetConnection(
+ std::make_unique<ConnectionFileDescriptor>(our_socket, true));
#endif
StartAsyncThread();
}
true));
#endif
if (conn_up->IsConnected()) {
- output_comm.SetConnection(conn_up.release());
+ output_comm.SetConnection(std::move(conn_up));
output_comm.SetReadThreadBytesReceivedCallback(
ReadThreadBytesReceived, &result->GetOutputStream());
output_comm.StartReadThread();
void Process::SetSTDIOFileDescriptor(int fd) {
// First set up the Read Thread for reading/handling process I/O
-
- std::unique_ptr<ConnectionFileDescriptor> conn_up(
- new ConnectionFileDescriptor(fd, true));
-
- if (conn_up) {
- m_stdio_communication.SetConnection(conn_up.release());
- if (m_stdio_communication.IsConnected()) {
- m_stdio_communication.SetReadThreadBytesReceivedCallback(
- STDIOReadThreadBytesReceived, this);
- m_stdio_communication.StartReadThread();
-
- // Now read thread is set up, set up input reader.
-
- if (!m_process_input_reader)
- m_process_input_reader =
- std::make_shared<IOHandlerProcessSTDIO>(this, fd);
- }
+ m_stdio_communication.SetConnection(
+ std::make_unique<ConnectionFileDescriptor>(fd, true));
+ if (m_stdio_communication.IsConnected()) {
+ m_stdio_communication.SetReadThreadBytesReceivedCallback(
+ STDIOReadThreadBytesReceived, this);
+ m_stdio_communication.StartReadThread();
+
+ // Now read thread is set up, set up input reader.
+
+ if (!m_process_input_reader)
+ m_process_input_reader =
+ std::make_shared<IOHandlerProcessSTDIO>(this, fd);
}
}
// connections while a connection is active.
acceptor_up.reset();
}
- platform.SetConnection(conn);
+ platform.SetConnection(std::unique_ptr<Connection>(conn));
if (platform.IsConnected()) {
if (inferior_arguments.GetArgumentCount() > 0) {
class MockServerWithMockConnection : public MockServer {
public:
MockServerWithMockConnection() : MockServer() {
- SetConnection(new MockConnection(m_packets));
+ SetConnection(std::make_unique<MockConnection>(m_packets));
}
llvm::ArrayRef<std::string> GetPackets() { return m_packets; };
#endif
TestClient::TestClient(std::unique_ptr<Connection> Conn) {
- SetConnection(Conn.release());
+ SetConnection(std::move(Conn));
SetPacketTimeout(std::chrono::seconds(10));
}