コード例 #1
0
        private static void StaticCallback(IntPtr loop, IntPtr watcher, EventTypes revents)
        {
            UnmanagedTimerWatcher iow = (UnmanagedTimerWatcher)Marshal.PtrToStructure(watcher, typeof(UnmanagedTimerWatcher));

            GCHandle     gchandle = GCHandle.FromIntPtr(iow.data);
            TimerWatcher w        = (TimerWatcher)gchandle.Target;

            w.callback(w.Loop, w, revents);
        }
コード例 #2
0
ファイル: MyClass.cs プロジェクト: RobinGitHub/Node.cs
        public int Main( string[] args )
        {

            TimerWatcher tw = new TimerWatcher( TimeSpan.FromSeconds( 1 ), TimeSpan.FromSeconds( 1 ), (LibEvLoop)IOLoop.Instance.EventLoop,
                                               ( l, w, et ) => Console.WriteLine( "{0}: Beep", DateTime.Now ));
            tw.Start();


            return 0;

        }
コード例 #3
0
ファイル: Timers.cs プロジェクト: cihanozhan/Node.cs
        public int ScheduleTimer( TimeSpan after, Action<int> onTimer )
        {
            if( freeList.Count == 0 ) growWatchers( watchers.Length * 2 );

            int ret = freeList.Dequeue();

            TimerWatcher tw = new TimerWatcher( after, TimeSpan.MaxValue, (LibEvLoop)loop.EventLoop, ( l, w, et ) =>
            {
                w.Stop();
                watchers[ret] = null;
                freeList.Enqueue( ret );
                onTimer( ret );
            } );
            watchers[ret] = tw;
            tw.Start();
            return ret;
        }
コード例 #4
0
ファイル: Timers.cs プロジェクト: cihanozhan/Node.cs
        private void growWatchers( int newSize )
        {
            int currentSize;
            if( watchers == null )
            {
                watchers = new TimerWatcher[newSize];
                currentSize = 0;
            }
            else
            {
                currentSize = watchers.Length;
                var w = new TimerWatcher[newSize];
                Array.Copy( watchers, w, currentSize - 1 );
                watchers = w;
            }

            for( int i = currentSize; i < newSize; i++ ) freeList.Enqueue( i );

        }
コード例 #5
0
ファイル: IOStream.cs プロジェクト: PeteShearer/manos
 private void HandleTimeoutEvent(Loop loop, TimerWatcher watcher, EventTypes revents)
 {
     if (Expires <= DateTime.UtcNow) {
         if (TimedOut != null)
             TimedOut (this, EventArgs.Empty);
         Close ();
     }
 }
コード例 #6
0
ファイル: IOStream.cs プロジェクト: PeteShearer/manos
        public void SetHandle(IntPtr handle)
        {
            if (this.handle != IntPtr.Zero && this.handle != handle)
                Close ();

            this.handle = handle;
            read_watcher = new IOWatcher (handle, EventTypes.Read, ioloop.EventLoop, HandleIOReadEvent);
            write_watcher = new IOWatcher (handle, EventTypes.Write, ioloop.EventLoop, HandleIOWriteEvent);
            timeout_watcher = new TimerWatcher (TimeOut, TimeOut, ioloop.EventLoop, HandleTimeoutEvent);

            timeout_watcher.Start ();
        }
コード例 #7
0
ファイル: IOStream.cs プロジェクト: PeteShearer/manos
        public virtual void Close()
        {
            if (handle == IntPtr.Zero)
                return;

            DisableReading ();
            DisableWriting ();

            read_watcher.Dispose ();
            write_watcher.Dispose ();
            timeout_watcher.Dispose ();

            read_watcher = null;
            write_watcher = null;
            timeout_watcher = null;
            handle = IntPtr.Zero;

            foreach (IWriteOperation op in write_ops) {
                op.Dispose ();
            }
            write_ops.Clear ();

            if (Closed != null)
                Closed (this, EventArgs.Empty);
            Closed = null;
            read_callback = null;
        }
コード例 #8
0
ファイル: IOLoop.cs プロジェクト: koush/manos
 public void AddTimeout(Timeout timeout)
 {
     TimerWatcher t = new TimerWatcher (timeout.begin, timeout.span, evloop, HandleTimeout);
     t.UserData = timeout;
     t.Start ();
 }
コード例 #9
0
ファイル: IOLoop.cs プロジェクト: koush/manos
        private void HandleTimeout(Loop loop, TimerWatcher timeout, EventTypes revents)
        {
            Timeout t = (Timeout) timeout.UserData;

            AppHost.RunTimeout (t);
            if (!t.ShouldContinueToRepeat ())
               timeout.Stop ();
        }
コード例 #10
0
ファイル: EventedStream.cs プロジェクト: rfantozzi/manos
        public override void Close()
        {
            base.Close ();
            if (Handle != IntPtr.Zero) {
                PauseReading ();
                PauseWriting ();

                readWatcher.Dispose ();
                writeWatcher.Dispose ();

                if (readTimeoutWatcher != null)
                    readTimeoutWatcher.Dispose ();
                if (writeTimeoutWatcher != null)
                    writeTimeoutWatcher.Dispose ();

                readWatcher = null;
                writeWatcher = null;
                readTimeoutWatcher = null;
                writeTimeoutWatcher = null;

                Handle = IntPtr.Zero;
            }
        }
コード例 #11
0
ファイル: EventedStream.cs プロジェクト: rfantozzi/manos
 void HandleWriteTimeout(TimerWatcher watcher, EventTypes revents)
 {
     if (writeTimeoutContinuation != null) {
         writeTimeoutWatcher.Repeat = DateTime.Now - writeTimeoutContinuation.Value;
         writeTimeoutWatcher.Again ();
         writeTimeoutContinuation = null;
     } else {
         RaiseError (new TimeoutException ());
         PauseWriting ();
     }
 }
コード例 #12
0
ファイル: EventedStream.cs プロジェクト: restrepo/manos
 void HandleReadTimeout(Loop loop, TimerWatcher watcher, EventTypes revents)
 {
     if (readTimeoutContinuation != null) {
         readTimeoutWatcher.Repeat = DateTime.Now - readTimeoutContinuation.Value;
         readTimeoutWatcher.Again ();
         readTimeoutContinuation = null;
     } else {
         RaiseError (new TimeoutException ());
         PauseReading ();
     }
 }
コード例 #13
0
ファイル: Complete.cs プロジェクト: cihanozhan/Node.cs
        /// <summary>
        /// true if all is well, false if timed out
        /// </summary>
        public void OnComplete( Action<bool> whenComplete, TimeSpan timeOut )
        {
            if( WorkPending == 0 ) whenComplete( true );
            else
            {
                timedWhenComplete = whenComplete;

                watcher = new TimerWatcher( timeOut, TimeSpan.MaxValue, (LibEvLoop)loop.EventLoop, ( l, w, et ) =>
                {
                    w.Stop();
                    timedWhenComplete = null;
                    whenComplete( false );
                });
                watcher.Start();
            }
        }
コード例 #14
0
ファイル: Timers.cs プロジェクト: cihanozhan/Node.cs
        public int ScheduleRepeatingTimer( TimeSpan interval, Action<int> onTimer )
        {
            if( freeList.Count == 0 ) growWatchers( watchers.Length * 2 );

            int ret = freeList.Dequeue();

            TimerWatcher tw = new TimerWatcher( interval, interval, (LibEvLoop)loop.EventLoop, ( l, w, et ) => onTimer( ret ));

            watchers[ret] = tw;
            tw.Start();
            return ret;
        }