示例#1
0
        static void Main(string[] args)
        {
            EventLooper looper = new EventLooper(null);

            looper.Initialize();

            Libuv.TTY tty = new Libuv.TTY(
                null,
                looper,
                TTYFileDescription.StandardIn,
                true,
                null
                );

            Console.WriteLine(tty.WindowSize);
            BufferPin pin = null;

            tty.ReadStart(length =>
            {
                pin = new BufferPin((uint)length);

                return(new Libuv.Structs.Buffer(pin.Start, (uint)length));
            },
                          (buffer, length) =>
            {
                Console.Write(System.Text.Encoding.UTF8.GetString(pin.Buffer));
            });

            looper.Run();
        }
示例#2
0
 public WriteRequest(ILibuvLogger logger, EventLooper looper) : base(logger)
 {
     this.AllocateMemory(
         looper.ThreadId,
         Request.NativeMethods.uv_req_size(RequestType.WRITE)
         );
     this._buffersPointer = IntPtr.Zero;
     this._writeBuffers   = new List <BufferPin>();
 }
示例#3
0
        static void Main(string[] args)
        {
            EventLooper looper = new EventLooper(null);

            looper.Initialize();
            Libuv.Tcp server = new Libuv.Tcp(null, looper, null);

            server.Bind("127.0.0.1", 8000, 0);
            server.Listen(128, () =>
            {
                Libuv.Tcp client = server.Accept(looper, null);

                BufferPin pin = null;

                client.ReadStart(length =>
                {
                    pin = new BufferPin((uint)length);
                    return(new Libuv.Structs.Buffer(pin.Start, (uint)length));
                },
                                 (buffer, length) =>
                {
                    Console.Write(System.Text.Encoding.UTF8.GetString(pin.Buffer, 0, length));

                    client.ReadStop();

                    WriteRequest writor = new WriteRequest(null, looper);

                    writor.Write(
                        client,
                        new ArraySegment <ArraySegment <byte> >(
                            new [] {
                        new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes("HTTP/1.1 200 OK\r\n")),
                        new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes("Content-Length:11\r\nContent-Type:text/html\r\n")),
                        new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes("\r\n")),
                        new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes("Hello World"))
                    }
                            ),
                        () => {
                        client.Close();
                    }
                        );
                });
            });

            looper.Run();
        }
示例#4
0
        static void Main(string[] args)
        {
            EventLooper looper = new EventLooper(null);

            FileSystemEvent fsEvent = new FileSystemEvent(
                null,
                looper,
                null
                );

            fsEvent.Start(
                @"F:\",
                FileSystemEventFlags.WatchEntry,
                (name, eventType) =>
            {
                Console.WriteLine(name);
                Console.WriteLine(eventType);
            }
                );
            looper.Run();
        }
示例#5
0
        public ConnectRequest(ILibuvLogger logger, EventLooper looper) : base(logger)
        {
            int requestSize = Request.NativeMethods.uv_req_size(RequestType.CONNECT);

            this.AllocateMemory(looper.ThreadId, requestSize);
        }