Beispiel #1
0
        public void AddTimeout(Timeout timeout)
        {
            TimerWatcher t = new TimerWatcher(timeout.begin, timeout.span, evloop, HandleTimeout);

            t.UserData = timeout;
            t.Start();
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        /// <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();
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        static void Main()
        {
            var endpoint = new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 8081);

            uv_init();

            var watch = new PrepareWatcher(() => {
                //Console.WriteLine("Prepare Watcher Called");
            });

            watch.Start();
            var server = new TcpServer((socket) => {
                clientcount++;
                socket.Stream.Write(System.Text.Encoding.ASCII.GetBytes(clientcount.ToString()), 1);
                if (clientcount > 5)
                {
                    socket.Close();
                }
                Console.WriteLine("Client Connected");
                socket.Stream.OnRead += (data) => {
                    Console.WriteLine("Data Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    socket.Stream.Write(data, data.Length);
                };
                //socket.OnClose += () => {
                //	Console.WriteLine("Client Disconnected");
                //};
            });

            server.Listen(endpoint);
            var client = new TcpSocket();

            client.Connect(endpoint, () => {
                client.Stream.OnRead += (data) => {
                    Console.WriteLine("Client Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    watch.Stop();
                    watch.Dispose();
                    client.Close();
                };
                byte[] message = System.Text.Encoding.ASCII.GetBytes("Hello World\n");
                client.Stream.Write(message, message.Length);
            });
            var pipeserver = new PipeServer((socket) => {
                clientcount++;
                socket.Stream.Write(System.Text.Encoding.ASCII.GetBytes(clientcount.ToString()), 1);
                if (clientcount > 5)
                {
                    socket.Close();
                }
                Console.WriteLine("Pipe Client Connected");
                socket.Stream.OnRead += (data) => {
                    Console.WriteLine("Pipe Data Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    socket.Stream.Write(data, data.Length);
                };
                //socket.OnClose += () => {
                //	Console.WriteLine("Client Disconnected");
                //};
            });

            pipeserver.Listen("libuv-csharp");
            var pipeclient = new PipeSocket();

            pipeclient.Connect("libuv-csharp", () => {
                pipeclient.Stream.OnRead += (data) => {
                    Console.WriteLine("Pipe Client Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    watch.Stop();
                    watch.Dispose();
                    pipeclient.Close();
                };
                byte[] message = System.Text.Encoding.ASCII.GetBytes("Hello World\n");
                pipeclient.Stream.Write(message, message.Length);
            });
            var watch2 = new PrepareWatcher(() => {
                //Console.WriteLine("Prepare Watcher 2 Called");
            });

            watch2.Start();
            var check = new CheckWatcher(() => {
                //Console.WriteLine("Check Watcher Called");
            });

            check.Start();
            var idle = new IdleWatcher(() => {
                //Console.WriteLine("Idle Watcher Called");
            });

            idle.Start();
            var after = new TimerWatcher(new TimeSpan(0, 0, 5), new TimeSpan(1, 0, 0), () => {
                //Console.WriteLine("After 5 Seconds");
            });

            after.Start();
            var every = new TimerWatcher(new TimeSpan(0, 0, 5), () => {
                //Console.WriteLine("Every 5 Seconds");
                //	after.Stop();
            });

            every.Start();
            var cp = new ChildProcess("ls");

            cp.Spawn();
            uv_run();
        }