Exemplo n.º 1
0
        public Task StartAsync(
            string pipeName,
            byte[] pipeMessage,
            EndPoint endPoint,
            LibuvThread thread)
        {
            _pipeName    = pipeName;
            _pipeMessage = pipeMessage;
            _buf         = thread.Loop.Libuv.buf_init(_ptr, 4);

            EndPoint     = endPoint;
            Thread       = thread;
            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource <int>(this, TaskCreationOptions.RunContinuationsAsynchronously);

            Thread.Post(StartCallback, tcs);
            return(tcs.Task);
        }
Exemplo n.º 2
0
        public async Task DoesNotThrowIfOnReadCallbackCalledWithEOFButAllocCallbackNotCalled()
        {
            var mockConnectionDispatcher = new MockConnectionDispatcher();
            var mockLibuv        = new MockLibuv();
            var transportContext = new TestLibuvTransportContext()
            {
                ConnectionDispatcher = mockConnectionDispatcher
            };
            var transport = new LibuvTransport(mockLibuv, transportContext, null);
            var thread    = new LibuvThread(transport);

            try
            {
                await thread.StartAsync();

                await thread.PostAsync(_ =>
                {
                    var listenerContext = new ListenerContext(transportContext)
                    {
                        Thread = thread
                    };
                    var socket     = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log);
                    var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread, null, null);
                    listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection);
                    _ = connection.Start();

                    var ignored = new LibuvFunctions.uv_buf_t();
                    mockLibuv.ReadCallback(socket.InternalGetHandle(), TestConstants.EOF, ref ignored);
                }, (object)null);

                var readAwaitable = await mockConnectionDispatcher.Input.Reader.ReadAsync();

                Assert.True(readAwaitable.IsCompleted);
            }
            finally
            {
                await thread.StopAsync(TimeSpan.FromSeconds(5));
            }
        }