[Lldb-commits] connectfiledescriptor close should take in account the "handle type" on Windows

Carlo Kok ck at remobjects.com
Thu Sep 26 10:26:05 PDT 2013


On windows a socket and a file have different kinds of handle. One goes 
through "Close" the other through "CloseSocket". If this one is oke I'll 
commit it with the other one.
-- 
Carlo Kok
RemObjects Software
-------------- next part --------------
Index: include/lldb/Core/ConnectionFileDescriptor.h
===================================================================
--- include/lldb/Core/ConnectionFileDescriptor.h	(revision 191382)
+++ include/lldb/Core/ConnectionFileDescriptor.h	(working copy)
@@ -77,6 +77,13 @@
     GetWritePort () const;
 
 protected:
+
+    typedef enum
+    {
+        eFDTypeFile,        // Other FD requireing read/write
+        eFDTypeSocket,      // Socket requiring send/recv
+        eFDTypeSocketUDP    // Unconnected UDP socket requiring sendto/recvfrom
+    } FDType;
     
     void
     OpenCommandPipe ();
@@ -103,14 +110,7 @@
     NamedSocketConnect (const char *socket_name, Error *error_ptr);
     
     lldb::ConnectionStatus
-    Close (int& fd, Error *error);
-
-    typedef enum
-    {
-        eFDTypeFile,        // Other FD requireing read/write
-        eFDTypeSocket,      // Socket requiring send/recv
-        eFDTypeSocketUDP    // Unconnected UDP socket requiring sendto/recvfrom
-    } FDType;
+    Close (int& fd, FDType type, Error *error);
     
     int m_fd_send;
     int m_fd_recv;
Index: source/Core/ConnectionFileDescriptor.cpp
===================================================================
--- source/Core/ConnectionFileDescriptor.cpp	(revision 191382)
+++ source/Core/ConnectionFileDescriptor.cpp	(working copy)
@@ -398,16 +398,16 @@
     {
         if (m_fd_send == m_fd_recv)
         {
-            status = Close (m_fd_send, error_ptr);
+            status = Close (m_fd_send, m_fd_send_type, error_ptr);
         }
         else
         {
             // File descriptors are the different, close both if needed
             if (m_fd_send >= 0)
-                status = Close (m_fd_send, error_ptr);
+                status = Close (m_fd_send, m_fd_send_type, error_ptr);
             if (m_fd_recv >= 0)
             {
-                ConnectionStatus recv_status = Close (m_fd_recv, error_ptr);
+                ConnectionStatus recv_status = Close (m_fd_recv, m_fd_recv_type, error_ptr);
                 if (status == eConnectionStatusSuccess)
                     status = recv_status;
             }
@@ -1146,7 +1146,7 @@
 #endif
 
 ConnectionStatus
-ConnectionFileDescriptor::Close (int& fd, Error *error_ptr)
+ConnectionFileDescriptor::Close (int& fd, FDType type, Error *error_ptr)
 {
     if (error_ptr)
         error_ptr->Clear();
@@ -1162,7 +1162,11 @@
             Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
             if (log)
                 log->Printf ("%p ConnectionFileDescriptor::Close (fd = %i)", this,fd);
-
+#if _WIN32
+            if (type != eFDTypeFile)
+              success = closesocket(fd) == 0;
+            else
+#endif
             success = ::close (fd) == 0;
             // A reference to a FD was passed in, set it to an invalid value
             fd = -1;
@@ -1301,7 +1305,7 @@
         {
             if (error_ptr)
                 error_ptr->SetErrorToErrno();
-            Close (listen_port, NULL);
+            Close (listen_port, eFDTypeSocket, NULL);
             return eConnectionStatusError;
         }
 
@@ -1310,7 +1314,7 @@
         {
             if (error_ptr)
                 error_ptr->SetErrorToErrno();
-            Close (listen_port, NULL);
+            Close (listen_port, eFDTypeSocket, NULL);
             return eConnectionStatusError;
         }
 
@@ -1319,13 +1323,13 @@
         {
             if (error_ptr)
                 error_ptr->SetErrorToErrno();
-            Close (listen_port, NULL);
+            Close (listen_port, eFDTypeSocket, NULL);
             return eConnectionStatusError;
         }
     }
 
     // We are done with the listen port
-    Close (listen_port, NULL);
+    Close (listen_port, eFDTypeSocket, NULL);
 
     m_should_close_fd = true;
 


More information about the lldb-commits mailing list