Exemplo n.º 1
0
            private int ReadSpecialFd(PollFlags revents)
            {
                PollFlags badEvents = PollFlags.POLLERR | PollFlags.POLLHUP | PollFlags.POLLNVAL;

                if ((revents & badEvents) != 0)
                {
                    return(-1);
                }
                Debug.Assert((revents & PollFlags.POLLIN) != 0);
                int pipeReadFd = _specialFds[Interop.Sys.ReadEndOfPipe];
                int bytesRead  = 0;

                unsafe
                {
                    do
                    {
                        // Read available data from the pipe
                        int   bufferLength = 1024;
                        byte *dummyBytes   = stackalloc byte[bufferLength];
                        int   numBytes     = (int)libc.read(pipeReadFd, dummyBytes, (size_t)bufferLength);
                        if (numBytes <= 0)
                        {
                            return(-1);
                        }
                        bytesRead += numBytes;

                        // Check if more data is available
                        PollFlags outFlags;
                        int       retVal = libc.poll(pipeReadFd, PollFlags.POLLIN, 0, out outFlags);
                        if (retVal < 0)
                        {
                            return(-1);
                        }
                        else if (0 == retVal)
                        {
                            break;
                        }
                    }while (true);
                }
                return(bytesRead);
            }
Exemplo n.º 2
0
            private int ReadSpecialFd(PollFlags revents)
            {
                PollFlags badEvents = PollFlags.POLLERR | PollFlags.POLLHUP | PollFlags.POLLNVAL;
                if ((revents & badEvents) != 0)
                {
                    return -1;
                }
                int pipeReadFd = _specialFds[libc.ReadEndOfPipe];
                int bytesRead = 0;
                unsafe
                {
                    do
                    {
                        // Read available data from the pipe
                        int bufferLength = 1024;
                        byte* dummyBytes = stackalloc byte[bufferLength];
                        int numBytes = (int)libc.read(pipeReadFd, dummyBytes, (size_t)bufferLength);
                        if (numBytes <= 0)
                        {
                            return -1;
                        }
                        bytesRead += numBytes;

                        // Check if more data is available
                        PollFlags outFlags;
                        int retVal = libc.poll(pipeReadFd, PollFlags.POLLIN, 0, out outFlags);
                        if (retVal < 0)
                        {
                            return -1;
                        }
                        else if (0 == retVal)
                        {
                            break;
                        }
                    }
                    while (true);
                }
                return bytesRead;
            }