Hi,<div><br></div><div>Mono itself has no trouble opening 1000&#39;s of files. Would you be able to create an equivalent C program and see if that works as expected? My guess would be that the equivalent C program will fail in the same way. If it does not, then it&#39;s likely to be a mono bug.</div>
<div><br></div><div>Alan<br><br><div class="gmail_quote">On 4 November 2011 07:19, Torello Querci <span dir="ltr">&lt;<a href="mailto:tquerci@gmail.com">tquerci@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi al,<br>
<br>
trying to handle more that 1024 handle file I got an exception even if<br>
I increase the max number of file limit using &quot;setrlimit&quot;. The example<br>
source code below.<br>
Of course mono have the right pcap permission.<br>
<br>
Using strace on both this code and no setrlimit version code I have<br>
some differences.<br>
On the no setrlimit version I have this syscall:<br>
<br>
open(&quot;file1021.out&quot;, O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = -1<br>
EMFILE (Too many open files)<br>
<br>
and this seems to be correct.<br>
On the setrlimit version code I have this syscalls:<br>
<br>
open(&quot;file1021.out&quot;, O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 1024<br>
close(1024)                             = 0<br>
<br>
so seems that mono close the file because open  return value is 1024.<br>
<br>
Is this a bug, a feature, or something else?<br>
<br>
==================================================================================================================<br>
using System;<br>
using System.IO;<br>
using System.Text;<br>
using System.Runtime.InteropServices;<br>
<br>
namespace TestFiles<br>
{<br>
<br>
        struct rlimit {<br>
                public IntPtr rlimit_cur;<br>
                public IntPtr rlimit_max;<br>
        }<br>
<br>
        class MainClass<br>
        {<br>
                public static unsafe void Main (string[] args)<br>
                {<br>
                        FileStream[] streams;<br>
                        string path;<br>
                        if (args.Length == 0) {<br>
                                Console.WriteLine (&quot;You need to specify the number of files that<br>
needs to be created.&quot;);<br>
                                return;<br>
                        }<br>
<br>
                        int nFiles = Int32.Parse (args[0]);<br>
<br>
                        streams = new FileStream[nFiles];<br>
<br>
                        rlimit data = new rlimit ();<br>
                        data.rlimit_cur = (IntPtr) 20000;<br>
                        data.rlimit_max = (IntPtr) 20000;<br>
<br>
                        int result = setrlimit (RLIMIT_NOFILE, &amp;data);<br>
                        if (result != 0) {<br>
                                throw new Exception (&quot;Cannot change limit on open files&quot;);<br>
                        }<br>
<br>
                        for (int i=0; i&lt;nFiles; ++i) {<br>
                                path = string.Format (&quot;file{0}.out&quot;, i);<br>
                                try {<br>
                                        streams[i] = File.Open(path, FileMode.Create, FileAccess.Write,<br>
FileShare.None);<br>
                                } catch (Exception ex) {<br>
                                        Console.WriteLine (&quot;Unable to write file {0}&quot;, path);<br>
                                        Console.WriteLine (ex.Message);<br>
                                        Console.WriteLine (ex.StackTrace);<br>
                                        return;<br>
                                }<br>
                        }<br>
                }<br>
<br>
                const int RLIMIT_NOFILE = 7;<br>
<br>
                [DllImport (&quot;libc&quot;, SetLastError = true)]<br>
                unsafe extern static int setrlimit(int resource, rlimit* rlim);<br>
<br>
        }<br>
}<br>
_______________________________________________<br>
Mono-devel-list mailing list<br>
<a href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a><br>
<a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a><br>
</blockquote></div><br></div>