Ejemplo n.º 1
0
        public Task StartAsync(
            ServerAddress address,
            KestrelThread thread,
            Func <Frame, Task> application)
        {
            ServerAddress = address;
            Thread        = thread;
            Application   = application;

            var tcs = new TaskCompletionSource <int>();

            Thread.Post(_ =>
            {
                try
                {
                    ListenSocket = CreateListenSocket();
                    tcs.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }, null);
            return(tcs.Task);
        }
Ejemplo n.º 2
0
        public Task StartAsync(
            string scheme,
            string host,
            int port,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            Thread = thread;
            Application = application;

            var tcs = new TaskCompletionSource<int>();
            Thread.Post(_ =>
            {
                try
                {
                    ListenSocket = new UvTcpHandle();
                    ListenSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
                    ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port));
                    ListenSocket.Listen(10, _connectionCallback, this);
                    tcs.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }, null);
            return tcs.Task;
        }
Ejemplo n.º 3
0
        public Task StartAsync(
            string scheme,
            string host,
            int port,
            KestrelThread thread,
            Func <Frame, Task> application)
        {
            Thread      = thread;
            Application = application;

            var tcs = new TaskCompletionSource <int>();

            Thread.Post(_ =>
            {
                try
                {
                    ListenSocket = new UvTcpHandle();
                    ListenSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
                    ListenSocket.Bind(new IPEndPoint(IPAddress.Any, port));
                    ListenSocket.Listen(10, _connectionCallback, this);
                    tcs.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }, null);
            return(tcs.Task);
        }
Ejemplo n.º 4
0
        public Task StartAsync(
            string scheme,
            string host,
            int port,
            KestrelThread thread,
            Func <Frame, Task> application)
        {
            Thread      = thread;
            Application = application;

            var tcs = new TaskCompletionSource <int>();

            Thread.Post(_ =>
            {
                try
                {
                    ListenSocket = CreateListenSocket(host, port);
                    tcs.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }, null);
            return(tcs.Task);
        }
Ejemplo n.º 5
0
        public Task StartAsync(
            ServerAddress address,
            KestrelThread thread)
        {
            ServerAddress     = address;
            Thread            = thread;
            ConnectionManager = new ConnectionManager(thread);

            var tcs = new TaskCompletionSource <int>(this);

            Thread.Post(state =>
            {
                var tcs2 = (TaskCompletionSource <int>)state;
                try
                {
                    var listener          = ((Listener)tcs2.Task.AsyncState);
                    listener.ListenSocket = listener.CreateListenSocket();
                    tcs2.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs2.SetException(ex);
                }
            }, tcs);

            return(tcs.Task);
        }
Ejemplo n.º 6
0
        public Task StartAsync(
            string scheme,
            string host,
            int port,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            Thread = thread;
            Application = application;

            var tcs = new TaskCompletionSource<int>();
            Thread.Post(_ =>
            {
                try
                {
                    ListenSocket = CreateListenSocket(host, port);
                    tcs.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }, null);
            return tcs.Task;
        }
Ejemplo n.º 7
0
        public Task StartAsync(
            ServerAddress address,
            KestrelThread thread)
        {
            ServerAddress = address;
            Thread = thread;

            var tcs = new TaskCompletionSource<int>(this);

            Thread.Post(tcs2 =>
            {
                try
                {
                    var listener = ((Listener)tcs2.Task.AsyncState);
                    listener.ListenSocket = listener.CreateListenSocket();
                    tcs2.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs2.SetException(ex);
                }
            }, tcs);

            return tcs.Task;
        }
Ejemplo n.º 8
0
 public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log)
 {
     _thread = thread;
     _socket = socket;
     _connectionId = connectionId;
     _log = log;
     _callbacksPending = new Queue<CallbackContext>();
 }
Ejemplo n.º 9
0
 public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log)
 {
     _thread           = thread;
     _socket           = socket;
     _connectionId     = connectionId;
     _log              = log;
     _callbacksPending = new Queue <CallbackContext>();
 }
Ejemplo n.º 10
0
        public async Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread)
        {
            _pipeName = pipeName;

            await StartAsync(address, thread).ConfigureAwait(false);

            await Thread.PostAsync(_this => _this.PostCallback(), 
                                    this).ConfigureAwait(false);
        }
        public async Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread)
        {
            _pipeName = pipeName;

            await StartAsync(address, thread).ConfigureAwait(false);

            await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(),
                                   this).ConfigureAwait(false);
        }
Ejemplo n.º 12
0
        public async Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread)
        {
            _pipeName = pipeName;

            await StartAsync(address, thread).ConfigureAwait(false);

            await Thread.PostAsync(_this => _this.PostCallback(),
                                   this).ConfigureAwait(false);
        }
Ejemplo n.º 13
0
        public async Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread,
            Func <Frame, Task> application)
        {
            await StartAsync(address, thread, application).ConfigureAwait(false);

            await Thread.PostAsync(_ =>
            {
                ListenPipe = new UvPipeHandle(Log);
                ListenPipe.Init(Thread.Loop, false);
                ListenPipe.Bind(pipeName);
                ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null);
            }, null).ConfigureAwait(false);
        }
        public async Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            await StartAsync(address, thread, application).ConfigureAwait(false);

            await Thread.PostAsync(_ =>
            {
                ListenPipe = new UvPipeHandle(Log);
                ListenPipe.Init(Thread.Loop, false);
                ListenPipe.Bind(pipeName);
                ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null);
            }, null).ConfigureAwait(false);
        }
        public Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread)
        {
            _pipeName = pipeName;
            _buf = thread.Loop.Libuv.buf_init(_ptr, 4);

            ServerAddress = address;
            Thread = thread;

            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource<int>(this);
            Thread.Post(tcs2 => StartCallback(tcs2), tcs);
            return tcs.Task;
        }
Ejemplo n.º 16
0
        public async Task StartAsync(
            string pipeName,
            string scheme,
            string host,
            int port,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            await StartAsync(scheme, host, port, thread, application).ConfigureAwait(false);

            await Thread.PostAsync(_ =>
            {
                ListenPipe = new UvPipeHandle();
                ListenPipe.Init(Thread.Loop, false);
                ListenPipe.Bind(pipeName);
                ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null);
            }, null).ConfigureAwait(false);
        }
        public Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread)
        {
            _pipeName = pipeName;
            _buf      = thread.Loop.Libuv.buf_init(_ptr, 4);

            ServerAddress = address;
            Thread        = thread;

            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource <int>(this);

            Thread.Post(tcs2 => StartCallback(tcs2), tcs);
            return(tcs.Task);
        }
Ejemplo n.º 18
0
 public SocketOutput(
     KestrelThread thread,
     UvStreamHandle socket,
     Connection connection,
     string connectionId,
     IKestrelTrace log,
     IThreadPool threadPool)
 {
     _thread               = thread;
     _socket               = socket;
     _connection           = connection;
     _connectionId         = connectionId;
     _log                  = log;
     _threadPool           = threadPool;
     _tasksPending         = new Queue <WaitingTask>(_initialTaskQueues);
     _writeContextPool     = new Queue <WriteContext>(_maxPooledWriteContexts);
     _writeReqPool         = thread.WriteReqPool;
     _maxBytesPreCompleted = connection.ServerOptions.Limits.MaxResponseBufferSize;
 }
Ejemplo n.º 19
0
        public async Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread)
        {
            _pipeName = pipeName;

            if (_fileCompletionInfoPtr == IntPtr.Zero)
            {
                var fileCompletionInfo = new FILE_COMPLETION_INFORMATION()
                {
                    Key = IntPtr.Zero, Port = IntPtr.Zero
                };
                _fileCompletionInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(fileCompletionInfo));
                Marshal.StructureToPtr(fileCompletionInfo, _fileCompletionInfoPtr, false);
            }

            await StartAsync(address, thread).ConfigureAwait(false);

            await Thread.PostAsync(state => ((ListenerPrimary)state).PostCallback(),
                                   this).ConfigureAwait(false);
        }
        public SocketOutput(
            KestrelThread thread,
            UvStreamHandle socket,
            MemoryPool memory,
            Connection connection,
            string connectionId,
            IKestrelTrace log,
            IThreadPool threadPool,
            Queue <UvWriteReq> writeReqPool)
        {
            _thread           = thread;
            _socket           = socket;
            _connection       = connection;
            _connectionId     = connectionId;
            _log              = log;
            _threadPool       = threadPool;
            _tasksPending     = new Queue <WaitingTask>(_initialTaskQueues);
            _writeContextPool = new Queue <WriteContext>(_maxPooledWriteContexts);
            _writeReqPool     = writeReqPool;

            _head = memory.Lease();
            _tail = _head;
        }
Ejemplo n.º 21
0
        public SocketOutput(
            KestrelThread thread,
            UvStreamHandle socket,
            MemoryPool2 memory,
            Connection connection,
            long connectionId,
            IKestrelTrace log,
            IThreadPool threadPool,
            Queue<UvWriteReq> writeReqPool)
        {
            _thread = thread;
            _socket = socket;
            _connection = connection;
            _connectionId = connectionId;
            _log = log;
            _threadPool = threadPool;
            _tasksPending = new Queue<TaskCompletionSource<object>>(_initialTaskQueues);
            _tasksCompleted = new Queue<TaskCompletionSource<object>>(_initialTaskQueues);
            _writeContextPool = new Queue<WriteContext>(_maxPooledWriteContexts);
            _writeReqPool = writeReqPool;

            _head = memory.Lease();
            _tail = _head;
        }
Ejemplo n.º 22
0
        public Task StartAsync(
            ServerAddress address,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            ServerAddress = address;
            Thread = thread;
            Application = application;

            var tcs = new TaskCompletionSource<int>();
            Thread.Post(_ =>
            {
                try
                {
                    ListenSocket = CreateListenSocket();
                    tcs.SetResult(0);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }, null);
            return tcs.Task;
        }
Ejemplo n.º 23
0
 public SocketOutput(KestrelThread thread, UvStreamHandle socket)
 {
     _thread = thread;
     _socket = socket;
 }
 public ConnectionManager(KestrelThread thread)
 {
     _thread = thread;
 }
Ejemplo n.º 25
0
 public WriteReqPool(KestrelThread thread, IKestrelTrace log)
 {
     _thread = thread;
     _log    = log;
 }
Ejemplo n.º 26
0
 public SocketOutput(KestrelThread thread, UvStreamHandle socket)
 {
     _thread = thread;
     _socket = socket;
     _callbacksPending = new Queue<CallbackContext>();
 }
        public Task StartAsync(
            string pipeName,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            Thread = thread;
            Application = application;

            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource<int>();
            Thread.Post(_ =>
            {
                try
                {
                    DispatchPipe.Init(Thread.Loop, true);
                    var connect = new UvConnectRequest(Log);
                    connect.Init(Thread.Loop);
                    connect.Connect(
                        DispatchPipe,
                        pipeName,
                        (connect2, status, error, state) =>
                        {
                            connect.Dispose();
                            if (error != null)
                            {
                                tcs.SetException(error);
                                return;
                            }

                            try
                            {
                                var ptr = Marshal.AllocHGlobal(4);
                                var buf = Thread.Loop.Libuv.buf_init(ptr, 4);

                                DispatchPipe.ReadStart(
                                    (_1, _2, _3) => buf,
                                    (_1, status2, errCode, error2, state2) =>
                                    {
                                        if (status2 < 0)
                                        {
                                            if (status2 != Constants.EOF)
                                            {
                                                Exception ex;
                                                Thread.Loop.Libuv.Check(status2, out ex);
                                                Log.LogError("DispatchPipe.ReadStart", ex);
                                            }

                                            DispatchPipe.Dispose();
                                            Marshal.FreeHGlobal(ptr);
                                            return;
                                        }

                                        if (DispatchPipe.PendingCount() == 0)
                                        {
                                            return;
                                        }

                                        var acceptSocket = CreateAcceptSocket();

                                        try
                                        {
                                            DispatchPipe.Accept(acceptSocket);
                                        }
                                        catch (UvException ex)
                                        {
                                            Log.LogError("DispatchPipe.Accept", ex);
                                            acceptSocket.Dispose();
                                            return;
                                        }

                                        var connection = new Connection(this, acceptSocket);
                                        connection.Start();
                                    },
                                    null);

                                tcs.SetResult(0);
                            }
                            catch (Exception ex)
                            {
                                DispatchPipe.Dispose();
                                tcs.SetException(ex);
                            }
                        },
                        null);
                }
                catch (Exception ex)
                {
                    DispatchPipe.Dispose();
                    tcs.SetException(ex);
                }
            }, null);
            return tcs.Task;
        }
Ejemplo n.º 28
0
 public ConnectionManager(KestrelThread thread, IThreadPool threadPool)
 {
     _thread     = thread;
     _threadPool = threadPool;
 }
Ejemplo n.º 29
0
        public Task StartAsync(
            string pipeName,
            ServerAddress address,
            KestrelThread thread,
            Func <Frame, Task> application)
        {
            ServerAddress = address;
            Thread        = thread;
            Application   = application;

            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource <int>();

            Thread.Post(_ =>
            {
                try
                {
                    DispatchPipe.Init(Thread.Loop, true);
                    var connect = new UvConnectRequest(Log);
                    connect.Init(Thread.Loop);
                    connect.Connect(
                        DispatchPipe,
                        pipeName,
                        (connect2, status, error, state) =>
                    {
                        connect.Dispose();
                        if (error != null)
                        {
                            tcs.SetException(error);
                            return;
                        }

                        try
                        {
                            var ptr = Marshal.AllocHGlobal(4);
                            var buf = Thread.Loop.Libuv.buf_init(ptr, 4);

                            DispatchPipe.ReadStart(
                                (_1, _2, _3) => buf,
                                (_1, status2, state2) =>
                            {
                                if (status2 < 0)
                                {
                                    if (status2 != Constants.EOF)
                                    {
                                        Exception ex;
                                        Thread.Loop.Libuv.Check(status2, out ex);
                                        Log.LogError("DispatchPipe.ReadStart", ex);
                                    }

                                    DispatchPipe.Dispose();
                                    Marshal.FreeHGlobal(ptr);
                                    return;
                                }

                                if (DispatchPipe.PendingCount() == 0)
                                {
                                    return;
                                }

                                var acceptSocket = CreateAcceptSocket();

                                try
                                {
                                    DispatchPipe.Accept(acceptSocket);
                                }
                                catch (UvException ex)
                                {
                                    Log.LogError("DispatchPipe.Accept", ex);
                                    acceptSocket.Dispose();
                                    return;
                                }

                                var connection = new Connection(this, acceptSocket);
                                connection.Start();
                            },
                                null);

                            tcs.SetResult(0);
                        }
                        catch (Exception ex)
                        {
                            DispatchPipe.Dispose();
                            tcs.SetException(ex);
                        }
                    },
                        null);
                }
                catch (Exception ex)
                {
                    DispatchPipe.Dispose();
                    tcs.SetException(ex);
                }
            }, null);
            return(tcs.Task);
        }
Ejemplo n.º 30
0
 public SocketOutput(KestrelThread thread, UvStreamHandle socket)
 {
     _thread = thread;
     _socket = socket;
 }
Ejemplo n.º 31
0
        public Task StartAsync(
            string pipeName,
            KestrelThread thread,
            Func<Frame, Task> application)
        {
            Thread = thread;
            Application = application;

            DispatchPipe = new UvPipeHandle();

            var tcs = new TaskCompletionSource<int>();
            Thread.Post(_ =>
            {
                try
                {
                    DispatchPipe.Init(Thread.Loop, true);
                    var connect = new UvConnectRequest();
                    connect.Init(Thread.Loop);
                    connect.Connect(
                        DispatchPipe,
                        pipeName,
                        (connect2, status, error, state) =>
                        {
                            connect.Dispose();
                            if (error != null)
                            {
                                tcs.SetException(error);
                                return;
                            }

                            try
                            {
                                var ptr = Marshal.AllocHGlobal(4);
                                var buf = Thread.Loop.Libuv.buf_init(ptr, 4);

                                DispatchPipe.ReadStart(
                                    (_1, _2, _3) => buf,
                                    (_1, status2, error2, state2) =>
                                    {
                                        if (status2 == 0)
                                        {
                                            DispatchPipe.Dispose();
                                            Marshal.FreeHGlobal(ptr);
                                            return;
                                        }

                                        var acceptSocket = new UvTcpHandle();
                                        acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);

                                        try
                                        {
                                            DispatchPipe.Accept(acceptSocket);
                                        }
                                        catch (Exception ex)
                                        {
                                            Trace.WriteLine("DispatchPipe.Accept " + ex.Message);
                                            acceptSocket.Dispose();
                                            return;
                                        }

                                        var connection = new Connection(this, acceptSocket);
                                        connection.Start();
                                    },
                                    null);

                                tcs.SetResult(0);
                            }
                            catch (Exception ex)
                            {
                                DispatchPipe.Dispose();
                                tcs.SetException(ex);
                            }
                        },
                        null);
                }
                catch (Exception ex)
                {
                    DispatchPipe.Dispose();
                    tcs.SetException(ex);
                }
            }, null);
            return tcs.Task;
        }
Ejemplo n.º 32
0
 public BufferSizeControl(long maxSize, IConnectionControl connectionControl, KestrelThread connectionThread)
 {
     _maxSize           = maxSize;
     _connectionControl = connectionControl;
     _connectionThread  = connectionThread;
 }