[Lldb-commits] [lldb] r191446 - On windows a socket and file descriptor aren't the same kind of handle, pass the type to Close so it uses the right api to close it.

Carlo Kok ck at remobjects.com
Thu Sep 26 11:49:53 PDT 2013


Author: carlokok
Date: Thu Sep 26 13:49:53 2013
New Revision: 191446

URL: http://llvm.org/viewvc/llvm-project?rev=191446&view=rev
Log:
On windows a socket and file descriptor aren't the same kind of handle, pass the type to Close so it uses the right api to close it.

Modified:
    lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h
    lldb/trunk/source/Core/ConnectionFileDescriptor.cpp

Modified: lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h?rev=191446&r1=191445&r2=191446&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h (original)
+++ lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h Thu Sep 26 13:49:53 2013
@@ -77,6 +77,13 @@ public:
     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 @@ protected:
     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;

Modified: lldb/trunk/source/Core/ConnectionFileDescriptor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConnectionFileDescriptor.cpp?rev=191446&r1=191445&r2=191446&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConnectionFileDescriptor.cpp (original)
+++ lldb/trunk/source/Core/ConnectionFileDescriptor.cpp Thu Sep 26 13:49:53 2013
@@ -398,16 +398,16 @@ ConnectionFileDescriptor::Disconnect (Er
     {
         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 @@ ConnectionFileDescriptor::BytesAvailable
 #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 @@ ConnectionFileDescriptor::Close (int& fd
             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 @@ ConnectionFileDescriptor::SocketListen (
         {
             if (error_ptr)
                 error_ptr->SetErrorToErrno();
-            Close (listen_port, NULL);
+            Close (listen_port, eFDTypeSocket, NULL);
             return eConnectionStatusError;
         }
 
@@ -1310,7 +1314,7 @@ ConnectionFileDescriptor::SocketListen (
         {
             if (error_ptr)
                 error_ptr->SetErrorToErrno();
-            Close (listen_port, NULL);
+            Close (listen_port, eFDTypeSocket, NULL);
             return eConnectionStatusError;
         }
 
@@ -1319,13 +1323,13 @@ ConnectionFileDescriptor::SocketListen (
         {
             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