public void Writable()
        {
            var epoll     = EPoll.Create();
            var pipePair1 = PipeEnd.CreatePair(blocking: true);

            EPollEvent[] events;
            PosixResult  result;

            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(0, events.Length);

            // Register pipePair1 for writable
            result = epoll.TryControl(EPollOperation.Add, pipePair1.WriteEnd, EPollEvents.Writable, new EPollData()
            {
                Long = 0x0102030405060708L
            });
            Assert.True(result.IsSuccess);

            // Writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(1, events.Length);
            Assert.Equal(EPollEvents.Writable, events[0].Events);
            Assert.Equal(0x0102030405060708L, events[0].Data.Long);

            epoll.Dispose();
            Dispose(pipePair1);
        }
        public void Error()
        {
            var epoll     = EPoll.Create();
            var pipePair1 = PipeEnd.CreatePair(blocking: true);

            EPollEvent[] events;
            PosixResult  result;

            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(0, events.Length);

            // Close the read end
            pipePair1.ReadEnd.Dispose();

            // Register pipePair1 for readable
            result = epoll.TryControl(EPollOperation.Add, pipePair1.WriteEnd, EPollEvents.Writable, new EPollData());
            Assert.True(result.IsSuccess);

            // Poll returns Writable, Error
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(1, events.Length);
            Assert.Equal(EPollEvents.Writable | EPollEvents.Error, events[0].Events);

            epoll.Dispose();
            pipePair1.WriteEnd.Dispose();
        }
        public void Delete()
        {
            var epoll     = EPoll.Create();
            var pipePair1 = PipeEnd.CreatePair(blocking: true);

            EPollEvent[] events;
            PosixResult  result;

            // Register pipePair1 for writable
            result = epoll.TryControl(EPollOperation.Add, pipePair1.WriteEnd, EPollEvents.Writable, new EPollData());
            Assert.True(result.IsSuccess);

            // Poll indicates writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(1, events.Length);

            // Unregister
            result = epoll.TryControl(EPollOperation.Delete, pipePair1.WriteEnd, EPollEvents.None, new EPollData());

            // Flush pending
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);

            // Poll no longer returns writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(0, events.Length);

            epoll.Dispose();
            Dispose(pipePair1);
        }
        public void OneShotAndModify()
        {
            var epoll     = EPoll.Create();
            var pipePair1 = PipeEnd.CreatePair(blocking: true);

            EPollEvent[] events;
            PosixResult  result;

            // Register pipePair1 for readable with OneShot
            result = epoll.TryControl(EPollOperation.Add, pipePair1.WriteEnd, EPollEvents.Writable | EPollEvents.OneShot, new EPollData());
            Assert.True(result.IsSuccess);

            // Poll indicates writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(1, events.Length);

            // OneShot, no longer writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(0, events.Length);

            // Rearm without OneShot
            result = epoll.TryControl(EPollOperation.Modify, pipePair1.WriteEnd, EPollEvents.Writable, new EPollData());

            // Poll indicates writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(1, events.Length);

            // Event triggered (i.e. no OneShot), still writable
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(1, events.Length);

            epoll.Dispose();
            Dispose(pipePair1);
        }
        public void MaxEvents()
        {
            var epoll     = EPoll.Create();
            var pipePair1 = PipeEnd.CreatePair(blocking: true);
            var pipePair2 = PipeEnd.CreatePair(blocking: true);

            EPollEvent[] events;
            PosixResult  result;

            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(0, events.Length);

            // Register pipePair1 for writable
            result = epoll.TryControl(EPollOperation.Add, pipePair1.WriteEnd, EPollEvents.Writable, new EPollData());
            Assert.True(result.IsSuccess);

            // Add pipePair2
            result = epoll.TryControl(EPollOperation.Add, pipePair2.WriteEnd, EPollEvents.Writable, new EPollData());
            Assert.True(result.IsSuccess);

            // Poll with maxEvents 1
            events = PollEvents(epoll, maxEvents: 1, timeout: 0);
            Assert.Equal(1, events.Length);

            epoll.Dispose();
            Dispose(pipePair1);
            Dispose(pipePair2);
        }
Ejemplo n.º 6
0
        public void CreateAndDispose()
        {
            var pair     = PipeEnd.CreatePair(blocking: true);
            var readEnd  = pair.ReadEnd;
            var writeEnd = pair.WriteEnd;

            Assert.NotNull(readEnd);
            Assert.NotNull(writeEnd);
            Assert.True(!readEnd.IsInvalid);
            Assert.True(!writeEnd.IsInvalid);
            readEnd.Dispose();
            writeEnd.Dispose();
        }
Ejemplo n.º 7
0
        public void NonBlockingRead()
        {
            var pair     = PipeEnd.CreatePair(blocking: false);
            var readEnd  = pair.ReadEnd;
            var writeEnd = pair.WriteEnd;

            var receiveBytes = new byte[] { 0, 0, 0, 0, 0 };
            var readResult   = readEnd.TryRead(new ArraySegment <byte>(receiveBytes, 1, 4));

            Assert.True(readResult == PosixResult.EAGAIN);

            // Clean-up
            readEnd.Dispose();
            writeEnd.Dispose();
        }
        public void MultipleEvents()
        {
            var epoll     = EPoll.Create();
            var pipePair1 = PipeEnd.CreatePair(blocking: true);
            var pipePair2 = PipeEnd.CreatePair(blocking: true);

            EPollEvent[] events;
            PosixResult  result;

            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(0, events.Length);

            // Register pipePair1 for writable
            result = epoll.TryControl(EPollOperation.Add, pipePair1.WriteEnd, EPollEvents.Writable, new EPollData()
            {
                Long = 0x0102030405060708L
            });
            Assert.True(result.IsSuccess);

            // Add pipePair2
            result = epoll.TryControl(EPollOperation.Add, pipePair2.WriteEnd, EPollEvents.Writable, new EPollData()
            {
                Long = 0x0807060504030201L
            });
            Assert.True(result.IsSuccess);

            // Poll
            events = PollEvents(epoll, maxEvents: 10, timeout: 0);
            Assert.Equal(2, events.Length);
            Assert.Equal(EPollEvents.Writable, events[0].Events);
            Assert.Equal(EPollEvents.Writable, events[1].Events);
            var datas = new long[] { 0x0102030405060708L, 0x0807060504030201L };

            Assert.Contains(events[0].Data.Long, datas);
            Assert.Contains(events[1].Data.Long, datas);
            Assert.NotEqual(events[0].Data.Long, events[1].Data.Long);

            epoll.Dispose();
            Dispose(pipePair1);
            Dispose(pipePair2);
        }
Ejemplo n.º 9
0
        public void WriteAndRead()
        {
            var pair     = PipeEnd.CreatePair(blocking: true);
            var readEnd  = pair.ReadEnd;
            var writeEnd = pair.WriteEnd;

            // Write
            var writeBytes  = new byte[] { 1, 2, 3 };
            var writeResult = writeEnd.TryWrite(new ArraySegment <byte>(writeBytes));

            Assert.True(writeResult.IsSuccess);

            // Read
            var receiveBytes = new byte[] { 0, 0, 0, 0, 0 };
            var readResult   = readEnd.TryRead(new ArraySegment <byte>(receiveBytes, 1, 4));

            Assert.True(readResult.IsSuccess);
            Assert.Equal(3, readResult.Value);
            Assert.Equal(new byte[] { 0, 1, 2, 3, 0 }, receiveBytes);

            // Clean-up
            readEnd.Dispose();
            writeEnd.Dispose();
        }