mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-19 06:31:20 +08:00
4f28a55b48
Motivation .NET Core tooling allows building for both .NET Framework and .NET Standard while easing pains of running tests and packaging. Modifications - csproj -> xproj + project.json - support for .NET Standard 1.3 - build script is now based on CAKE - using dotnet CLI for building, testing, packing - strong name by default (snk included) Result DotNetty works on .NET Core and any other platform supporting .NET Standard 1.3+.
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
namespace Factorial.Client
|
|
{
|
|
using System.Collections.Concurrent;
|
|
using System.Numerics;
|
|
using DotNetty.Transport.Channels;
|
|
|
|
public class FactorialClientHandler : SimpleChannelInboundHandler<BigInteger>
|
|
{
|
|
IChannelHandlerContext ctx;
|
|
int receivedMessages;
|
|
int next = 1;
|
|
readonly BlockingCollection<BigInteger> answer = new BlockingCollection<BigInteger>();
|
|
|
|
public BigInteger GetFactorial() => this.answer.Take();
|
|
|
|
public override void ChannelActive(IChannelHandlerContext ctx)
|
|
{
|
|
this.ctx = ctx;
|
|
this.SendNumbers();
|
|
}
|
|
|
|
protected override void ChannelRead0(IChannelHandlerContext ctx, BigInteger msg)
|
|
{
|
|
this.receivedMessages++;
|
|
if (this.receivedMessages == ClientSettings.Count)
|
|
{
|
|
ctx.CloseAsync().ContinueWith(t => this.answer.Add(msg));
|
|
}
|
|
}
|
|
|
|
void SendNumbers()
|
|
{
|
|
for (int i = 0; (i < 4096) && (this.next <= ClientSettings.Count); i++)
|
|
{
|
|
this.ctx.WriteAsync(new BigInteger(this.next));
|
|
this.next++;
|
|
}
|
|
this.ctx.Flush();
|
|
}
|
|
}
|
|
} |