refactor: move IOObject::m_should_close_fd into subclasses

Summary:
m_should_close_fd doesn't need to be in IOObject.   It will be useful
for my next change to move it down into File and Socket.

Reviewers: labath, JDevlieghere, jasonmolenda

Reviewed By: JDevlieghere

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D68152

llvm-svn: 373126
This commit is contained in:
Lawrence D'Anna 2019-09-27 20:43:50 +00:00
parent 121ef04f04
commit 117512715d
5 changed files with 20 additions and 19 deletions

View File

@ -51,22 +51,23 @@ public:
static mode_t ConvertOpenOptionsForPOSIXOpen(uint32_t open_options);
File()
: IOObject(eFDTypeFile, false), m_descriptor(kInvalidDescriptor),
m_stream(kInvalidStream), m_options(0), m_own_stream(false),
m_is_interactive(eLazyBoolCalculate),
: IOObject(eFDTypeFile), m_descriptor(kInvalidDescriptor),
m_own_descriptor(false), m_stream(kInvalidStream), m_options(0),
m_own_stream(false), m_is_interactive(eLazyBoolCalculate),
m_is_real_terminal(eLazyBoolCalculate),
m_supports_colors(eLazyBoolCalculate) {}
File(FILE *fh, bool transfer_ownership)
: IOObject(eFDTypeFile, false), m_descriptor(kInvalidDescriptor),
m_stream(fh), m_options(0), m_own_stream(transfer_ownership),
m_is_interactive(eLazyBoolCalculate),
: IOObject(eFDTypeFile), m_descriptor(kInvalidDescriptor),
m_own_descriptor(false), m_stream(fh), m_options(0),
m_own_stream(transfer_ownership), m_is_interactive(eLazyBoolCalculate),
m_is_real_terminal(eLazyBoolCalculate),
m_supports_colors(eLazyBoolCalculate) {}
File(int fd, uint32_t options, bool transfer_ownership)
: IOObject(eFDTypeFile, transfer_ownership), m_descriptor(fd),
m_stream(kInvalidStream), m_options(options), m_own_stream(false),
: IOObject(eFDTypeFile), m_descriptor(fd),
m_own_descriptor(transfer_ownership), m_stream(kInvalidStream),
m_options(options), m_own_stream(false),
m_is_interactive(eLazyBoolCalculate),
m_is_real_terminal(eLazyBoolCalculate) {}
@ -339,6 +340,7 @@ protected:
// Member variables
int m_descriptor;
bool m_own_descriptor;
FILE *m_stream;
uint32_t m_options;
bool m_own_stream;

View File

@ -122,6 +122,7 @@ protected:
SocketProtocol m_protocol;
NativeSocket m_socket;
bool m_child_processes_inherit;
bool m_should_close_fd;
};
} // namespace lldb_private

View File

@ -29,8 +29,7 @@ public:
typedef int WaitableHandle;
static const WaitableHandle kInvalidHandleValue;
IOObject(FDType type, bool should_close)
: m_fd_type(type), m_should_close_fd(should_close) {}
IOObject(FDType type) : m_fd_type(type) {}
virtual ~IOObject();
virtual Status Read(void *buf, size_t &num_bytes) = 0;
@ -44,8 +43,6 @@ public:
protected:
FDType m_fd_type;
bool m_should_close_fd; // True if this class should close the file descriptor
// when it goes away.
private:
DISALLOW_COPY_AND_ASSIGN(IOObject);

View File

@ -98,7 +98,7 @@ FILE *File::GetStream() {
if (DescriptorIsValid()) {
const char *mode = GetStreamOpenModeFromOptions(m_options);
if (mode) {
if (!m_should_close_fd) {
if (!m_own_descriptor) {
// We must duplicate the file descriptor if we don't own it because when you
// call fdopen, the stream will own the fd
#ifdef _WIN32
@ -106,7 +106,7 @@ FILE *File::GetStream() {
#else
m_descriptor = dup(GetDescriptor());
#endif
m_should_close_fd = true;
m_own_descriptor = true;
}
m_stream =
@ -117,7 +117,7 @@ FILE *File::GetStream() {
if (m_stream) {
m_own_stream = true;
m_should_close_fd = false;
m_own_descriptor = false;
}
}
}
@ -148,7 +148,7 @@ Status File::Close() {
error.SetErrorToErrno();
}
if (DescriptorIsValid() && m_should_close_fd) {
if (DescriptorIsValid() && m_own_descriptor) {
if (::close(m_descriptor) != 0)
error.SetErrorToErrno();
}
@ -156,7 +156,7 @@ Status File::Close() {
m_stream = kInvalidStream;
m_options = 0;
m_own_stream = false;
m_should_close_fd = false;
m_own_descriptor = false;
m_is_interactive = eLazyBoolCalculate;
m_is_real_terminal = eLazyBoolCalculate;
return error;

View File

@ -74,9 +74,10 @@ bool IsInterrupted() {
Socket::Socket(SocketProtocol protocol, bool should_close,
bool child_processes_inherit)
: IOObject(eFDTypeSocket, should_close), m_protocol(protocol),
: IOObject(eFDTypeSocket), m_protocol(protocol),
m_socket(kInvalidSocketValue),
m_child_processes_inherit(child_processes_inherit) {}
m_child_processes_inherit(child_processes_inherit),
m_should_close_fd(should_close) {}
Socket::~Socket() { Close(); }