[Lldb-commits] [lldb] r373126 - refactor: move IOObject::m_should_close_fd into subclasses

Lawrence D'Anna via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 27 13:43:50 PDT 2019


Author: lawrence_danna
Date: Fri Sep 27 13:43:50 2019
New Revision: 373126

URL: http://llvm.org/viewvc/llvm-project?rev=373126&view=rev
Log:
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

Modified:
    lldb/trunk/include/lldb/Host/File.h
    lldb/trunk/include/lldb/Host/Socket.h
    lldb/trunk/include/lldb/Utility/IOObject.h
    lldb/trunk/source/Host/common/File.cpp
    lldb/trunk/source/Host/common/Socket.cpp

Modified: lldb/trunk/include/lldb/Host/File.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/File.h?rev=373126&r1=373125&r2=373126&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/File.h (original)
+++ lldb/trunk/include/lldb/Host/File.h Fri Sep 27 13:43:50 2019
@@ -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;

Modified: lldb/trunk/include/lldb/Host/Socket.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Socket.h?rev=373126&r1=373125&r2=373126&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Socket.h (original)
+++ lldb/trunk/include/lldb/Host/Socket.h Fri Sep 27 13:43:50 2019
@@ -122,6 +122,7 @@ protected:
   SocketProtocol m_protocol;
   NativeSocket m_socket;
   bool m_child_processes_inherit;
+  bool m_should_close_fd;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Utility/IOObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/IOObject.h?rev=373126&r1=373125&r2=373126&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/IOObject.h (original)
+++ lldb/trunk/include/lldb/Utility/IOObject.h Fri Sep 27 13:43:50 2019
@@ -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);

Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=373126&r1=373125&r2=373126&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Fri Sep 27 13:43:50 2019
@@ -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;

Modified: lldb/trunk/source/Host/common/Socket.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Socket.cpp?rev=373126&r1=373125&r2=373126&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Socket.cpp (original)
+++ lldb/trunk/source/Host/common/Socket.cpp Fri Sep 27 13:43:50 2019
@@ -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(); }
 




More information about the lldb-commits mailing list