[IO] Dump handle when we run out of them
[mono.git] / mcs / class / corlib / System.IO / MonoIO.cs
index a15c475bbaa88aab7ec9854f900dd4bf16215afa..994358c86bec2aff6ec7373da50dcd0ee17d515a 100644 (file)
@@ -51,6 +51,8 @@ namespace System.IO
                public static readonly IntPtr
                        InvalidHandle = (IntPtr)(-1L);
 
+               static bool dump_handles = Environment.GetEnvironmentVariable ("MONO_DUMP_HANDLES_ON_ERROR_TOO_MANY_OPEN_FILES") != null;
+
                // error methods
                public static Exception GetException (MonoIOError error)
                {
@@ -89,6 +91,8 @@ namespace System.IO
                                return new FileNotFoundException (message, path);
 
                        case MonoIOError.ERROR_TOO_MANY_OPEN_FILES:
+                               if (dump_handles)
+                                       DumpHandles ();
                                return new IOException ("Too many open files", unchecked((int)0x80070000) | (int)error);
                                
                        case MonoIOError.ERROR_PATH_NOT_FOUND:
@@ -599,6 +603,9 @@ namespace System.IO
                        [MethodImplAttribute (MethodImplOptions.InternalCall)]
                        get;
                }
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               extern static void DumpHandles ();
        }
 }