ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd)
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
m_waiting_for_accept(false), m_child_processes_inherit(false) {
- m_write_sp =
+ m_io_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, owns_fd);
- m_read_sp = m_write_sp;
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
LIBLLDB_LOG_OBJECT));
}
bool ConnectionFileDescriptor::IsConnected() const {
- return (m_read_sp && m_read_sp->IsValid()) ||
- (m_write_sp && m_write_sp->IsValid());
+ return m_io_sp && m_io_sp->IsValid();
}
ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
return eConnectionStatusSuccess;
}
- if (m_read_sp && m_read_sp->IsValid() &&
- m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
- static_cast<Socket &>(*m_read_sp).PreDisconnect();
+ if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket)
+ static_cast<Socket &>(*m_io_sp).PreDisconnect();
// Try to get the ConnectionFileDescriptor's mutex. If we fail, that is
// quite likely because somebody is doing a blocking read on our file
// Prevents reads and writes during shutdown.
m_shutting_down = true;
- Status error = m_read_sp->Close();
- Status error2 = m_write_sp->Close();
- if (error.Fail() || error2.Fail())
+ Status error = m_io_sp->Close();
+ if (error.Fail())
status = eConnectionStatusError;
if (error_ptr)
- *error_ptr = error.Fail() ? error : error2;
+ *error_ptr = error;
// Close any pipes we were using for async interrupts
m_pipe.Close();
Status error;
size_t bytes_read = dst_len;
- error = m_read_sp->Read(dst, bytes_read);
+ error = m_io_sp->Read(dst, bytes_read);
if (log) {
LLDB_LOGF(log,
"%p ConnectionFileDescriptor::Read() fd = %" PRIu64
", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s",
static_cast<void *>(this),
- static_cast<uint64_t>(m_read_sp->GetWaitableHandle()),
+ static_cast<uint64_t>(m_io_sp->GetWaitableHandle()),
static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
static_cast<uint64_t>(bytes_read), error.AsCString());
}
switch (error_value) {
case EAGAIN: // The file was marked for non-blocking I/O, and no data were
// ready to be read.
- if (m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
+ if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket)
status = eConnectionStatusTimedOut;
else
status = eConnectionStatusSuccess;
Status error;
size_t bytes_sent = src_len;
- error = m_write_sp->Write(src, bytes_sent);
+ error = m_io_sp->Write(src, bytes_sent);
if (log) {
LLDB_LOGF(log,
"%p ConnectionFileDescriptor::Write(fd = %" PRIu64
", src = %p, src_len = %" PRIu64 ") => %" PRIu64 " (error = %s)",
static_cast<void *>(this),
- static_cast<uint64_t>(m_write_sp->GetWaitableHandle()),
+ static_cast<uint64_t>(m_io_sp->GetWaitableHandle()),
static_cast<const void *>(src), static_cast<uint64_t>(src_len),
static_cast<uint64_t>(bytes_sent), error.AsCString());
}
// Make a copy of the file descriptors to make sure we don't have another
// thread change these values out from under us and cause problems in the
// loop below where like in FS_SET()
- const IOObject::WaitableHandle handle = m_read_sp->GetWaitableHandle();
+ const IOObject::WaitableHandle handle = m_io_sp->GetWaitableHandle();
const int pipe_fd = m_pipe.GetReadFileDescriptor();
if (handle != IOObject::kInvalidHandleValue) {
if (have_pipe_fd)
select_helper.FDSetRead(pipe_fd);
- while (handle == m_read_sp->GetWaitableHandle()) {
+ while (handle == m_io_sp->GetWaitableHandle()) {
Status error = select_helper.Select();
Socket::UnixDomainAccept(socket_name, m_child_processes_inherit, socket);
if (error_ptr)
*error_ptr = error;
- m_write_sp.reset(socket);
- m_read_sp = m_write_sp;
- if (error.Fail()) {
+ m_io_sp.reset(socket);
+ if (error.Fail())
return eConnectionStatusError;
- }
m_uri.assign(std::string(socket_name));
return eConnectionStatusSuccess;
}
Socket::UnixDomainConnect(socket_name, m_child_processes_inherit, socket);
if (error_ptr)
*error_ptr = error;
- m_write_sp.reset(socket);
- m_read_sp = m_write_sp;
- if (error.Fail()) {
+ m_io_sp.reset(socket);
+ if (error.Fail())
return eConnectionStatusError;
- }
m_uri.assign(std::string(socket_name));
return eConnectionStatusSuccess;
}
m_child_processes_inherit, socket);
if (error_ptr)
*error_ptr = error;
- m_write_sp.reset(socket);
- m_read_sp = m_write_sp;
- if (error.Fail()) {
+ m_io_sp.reset(socket);
+ if (error.Fail())
return eConnectionStatusError;
- }
m_uri.assign(std::string(socket_name));
return eConnectionStatusSuccess;
}
socket.takeError(), "tcp connect failed: {0}");
return eConnectionStatusError;
}
- m_write_sp = std::move(*socket);
- m_read_sp = m_write_sp;
+ m_io_sp = std::move(*socket);
m_uri.assign(std::string(s));
return eConnectionStatusSuccess;
}
socket.takeError(), "tcp connect failed: {0}");
return eConnectionStatusError;
}
- m_write_sp = std::move(*socket);
- m_read_sp = m_write_sp;
+ m_io_sp = std::move(*socket);
m_uri.assign(std::string(s));
return eConnectionStatusSuccess;
}
if (error_ptr)
error_ptr->SetErrorStringWithFormat("stale file descriptor: %s",
s.str().c_str());
- m_read_sp.reset();
- m_write_sp.reset();
+ m_io_sp.reset();
return eConnectionStatusError;
} else {
// Don't take ownership of a file descriptor that gets passed to us
int resuse;
bool is_socket =
!!tcp_socket->GetOption(SOL_SOCKET, SO_REUSEADDR, resuse);
- if (is_socket) {
- m_read_sp = std::move(tcp_socket);
- m_write_sp = m_read_sp;
- } else {
- m_read_sp =
+ if (is_socket)
+ m_io_sp = std::move(tcp_socket);
+ else
+ m_io_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, false);
- m_write_sp = m_read_sp;
- }
m_uri = s.str();
return eConnectionStatusSuccess;
}
if (error_ptr)
error_ptr->SetErrorStringWithFormat("invalid file descriptor: \"%s\"",
s.str().c_str());
- m_read_sp.reset();
- m_write_sp.reset();
+ m_io_sp.reset();
return eConnectionStatusError;
#endif // LLDB_ENABLE_POSIX
llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
::fcntl(fd, F_SETFL, flags);
}
}
- m_read_sp =
+ m_io_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, true);
- m_write_sp = m_read_sp;
return eConnectionStatusSuccess;
#endif // LLDB_ENABLE_POSIX
llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
}
void ConnectionFileDescriptor::InitializeSocket(Socket *socket) {
- m_write_sp.reset(socket);
- m_read_sp = m_write_sp;
+ m_io_sp.reset(socket);
m_uri = socket->GetRemoteConnectionURI();
}