コード例 #1
0
ファイル: EVEventTests.cs プロジェクト: deapsquatter/oars
        public void EventTimerDelete()
        {
            var timeout = TimeSpan.FromMilliseconds(500);
            var removeTimeout = TimeSpan.FromMilliseconds(250);
            var timeoutToBeRemoved = TimeSpan.FromMilliseconds(375);

            ev1 = Event.CreateTimer(eventBase);
            ev1.Activated = Ev1Activated;
            ev2 = Event.CreateTimer(eventBase);
            ev2.Activated = Ev2Activated;
            ev3 = Event.CreateTimer(eventBase);
            ev3.Activated = Ev3Activated;

            var dispatch = eventBase.StartDispatchOnNewThread(() => {
                ev1.Add(timeout);
                ev2.Add(removeTimeout);
                ev3.Add(timeoutToBeRemoved);
            }, () => {
                ev1.Delete();
                ev1.Dispose();
                ev2.Delete();
                ev2.Dispose();
            });

            dispatch.Join();

            Assert.IsTrue(ev1Activated, "Event 1 did not activate.");
            Assert.IsTrue(ev2Activated, "Event 2 did not activate.");
            Assert.IsFalse(ev3Activated, "Event 3 erroneously activated after being deleted.");
        }
コード例 #2
0
ファイル: EVEventTests.cs プロジェクト: deapsquatter/oars
        public void EventTimerAdd()
        {
            var intendedDuration = TimeSpan.FromMilliseconds(500);

            ev1 = Event.CreateTimer(eventBase);

            var dispatch = eventBase.StartDispatchOnNewThread(() =>
            {
                //Console.WriteLine("Setting timeout for " + intendedDuration.TotalMilliseconds);
                ev1.Add(intendedDuration);
                added = eventBase.GetTimeOfDayCached();
                //Console.WriteLine("Added event at time: " + added.Millisecond);

                ev1.Activated = EventTimerAddActivated;
            }, () => {
                ev1.Delete();
                ev1.Dispose();
            });
            
            dispatch.Join();

            Assert.IsTrue(ev1Activated, "Event was never activated.");

            var actualDuration = activated - added;
            //Console.WriteLine("Actual duration: " + actualDuration.TotalMilliseconds);
            var difference = intendedDuration - actualDuration;
            //Console.WriteLine("Difference: " + difference);
            Assert.Less(difference.TotalMilliseconds, 10, "Large discrepancy between intended and actual timeout duration.");
        }
コード例 #3
0
ファイル: OarsServer.cs プロジェクト: ruxo/kayak
        public IDisposable Listen(IPEndPoint ep)
        {
            if (listening)
                throw new InvalidOperationException("Already listening.");

            ListenEndPoint = ep;

            listener = new ConnectionListener(eventBase, ep, 1000);
            listener.Enable();
            listener.ConnectionAccepted = (fd, remoteEp) =>
            {
                connections++;
                var ev = new Event(eventBase, fd, Events.EV_WRITE | Events.EV_READ);

                //if (OnConnection != null)
                //    OnConnection(this, new ConnectionEventArgs(new OarsSocket(ev, remoteEp, this)));
            };
            listening = true;
            closed = false;

            // XXX return Disposable(() => Close());
            return null;
        }
コード例 #4
0
ファイル: OarsSocket.cs プロジェクト: ruxo/kayak
 public OarsSocket(Event ev, IPEndPoint remoteEP, OarsServer server)
 {
 }