Esempio n. 1
0
        internal Task HandleOperationAsync(LinkParameter parameter)
        {
            var packet = parameter.Packet;

            operation.SetResult(packet.PacketId, packet);
            return(Task.FromResult(0));
        }
Esempio n. 2
0
        internal async Task UdpLoopAsync()
        {
            var token = client.CancellationToken;

            while (true)
            {
                token.ThrowIfCancellationRequested();
                var result = await udpClient.ReceiveAsync();

                Task.Run(() => HandleConnectionAsync(LinkParameter.CreateUdpParameter(client, result.Buffer, result.RemoteEndPoint))).Ignore();
            }
        }
Esempio n. 3
0
        private async Task HandleClientAsync(TcpClient result)
        {
            var cancel = new CancellationTokenSource();
            var stream = default(NetworkStream);

            try
            {
                stream = result.GetStream();
                var endpoint = (IPEndPoint)result.Client.RemoteEndPoint;
                var buffer   = await stream.ReadBlockWithHeaderAsync(environment.TcpBufferLimits, cancel.Token).TimeoutAfter(environment.TcpTimeout);

                var parameter = LinkParameter.CreateTcpParameter(client, buffer, endpoint, stream, cancel.Token);
                await HandleConnectionAsync(parameter);
            }
            finally
            {
                cancel.Cancel();
                cancel.Dispose();
                stream?.Dispose();
                result?.Dispose();
            }
        }
Esempio n. 4
0
 private Task HandleConnectionAsync(LinkParameter parameter)
 {
     return(functors.TryGetValue(parameter.Packet.Path, out var functor)
         ? functor.Invoke(client, parameter)
         : Task.FromResult(-1));
 }