Ejemplo n.º 1
0
 public Task WriteAsync(ServiceMessage serviceMessage)
 {
     if (RuntimeServicePingMessage.IsFin(serviceMessage))
     {
         _offline.SetResult(true);
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 2
0
        private async Task MockServiceAsync(TestServiceConnectionForCloseAsync conn)
        {
            IServiceProtocol proto = new ServiceProtocol();

            await conn.ConnectionCreated;

            // open 2 new connections (to create 2 new outgoing tasks
            proto.WriteMessage(new OpenConnectionMessage(Guid.NewGuid().ToString(), new Claim[0]), conn.Application.Output);
            proto.WriteMessage(new OpenConnectionMessage(Guid.NewGuid().ToString(), new Claim[0]), conn.Application.Output);
            await conn.Application.Output.FlushAsync();

            while (true)
            {
                var result = await conn.Application.Input.ReadAsync();

                var buffer = result.Buffer;

                try
                {
                    // write back a FinAck after receiving a Fin
                    if (proto.TryParseMessage(ref buffer, out ServiceMessage message))
                    {
                        if (RuntimeServicePingMessage.IsFin(message))
                        {
                            var pong = RuntimeServicePingMessage.GetFinAckPingMessage();
                            proto.WriteMessage(pong, conn.Application.Output);
                            await conn.Application.Output.FlushAsync();

                            break;
                        }
                    }
                }
                finally
                {
                    conn.Application.Input.AdvanceTo(buffer.Start, buffer.End);
                }
            }
        }