public static unsafe void Poll(IntPtr[] reads, IntPtr[] writes, int timeout)
        {
            if (timeout == 0)
            {
                return;
            }

            PollEvent[] p;
            int         num, n, num_read_total, num_write_total;

            num_read_total = num_write_total = 0;
            foreach (IntPtr fd in reads)
            {
                if ((int)fd != -1)
                {
                    num_read_total++;
                }
            }
            foreach (IntPtr fd in writes)
            {
                if ((int)fd != -1)
                {
                    num_write_total++;
                }
            }

            num = num_read_total + num_write_total;

            p = new PollEvent[num];

            n = 0;

            foreach (IntPtr fd in reads)
            {
                if ((int)fd != -1)
                {
                    p[n].FileDescriptor = (int)fd;
                    p[n].Events         = PollEvents.POLLIN | PollEvents.POLLPRI | PollEvents.POLLERR | PollEvents.POLLHUP;
                    n++;
                }
            }

            foreach (IntPtr fd in writes)
            {
                if ((int)fd != -1)
                {
                    p[n].FileDescriptor = (int)fd;
                    p[n].Events         = PollEvents.POLLIN | PollEvents.POLLPRI | PollEvents.POLLERR | PollEvents.POLLHUP | PollEvents.POLLOUT;
                    n++;
                }
            }

            if (num == 0)
            {
                ThreadObj.Sleep(timeout);
            }
            else
            {
                //Dbg.WriteLine("Poll Begin.");

                int ret = Poll(p, timeout);

                //Dbg.WriteLine($"Poll end: ret = {ret}, reads = {reads.Length}, writes = {writes.Length}, pfds = {p.Length}");

                //for (int i = 0; i < reads.Length; i++) Dbg.WriteLine($"reads[{i}] = {reads[i]}");
                //for (int i = 0; i < writes.Length; i++) Dbg.WriteLine($"writes[{i}] = {writes[i]}");
            }
        }
示例#2
0
 // スリープ
 public static void SleepThread(int millisec)
 {
     ThreadObj.Sleep(millisec);
 }