mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-22 16:54:55 +08:00
1a80817c71
Motivation: In order to avoid buffer copies and yet perform IO efficiently, it is essential to support sending multiple byte sequences in one call. Also there should be no additional constraints on IByteBuffer implementations in order to be accepted by TcpSocketChannel for sending. Modifications: - IoBufferCount, GetIoBuffer(), GetIoBuffers() are ported to IByteBuffer and implementations. - ChannelOutboundBuffer is extended to leverage *IoBuffer* members in order to prepare buffer batches for sending. - TcpSocketChannel and its ancestors were extended to support sending (sync and async) a list of array segments. - Extra: fixes WriterIndex positioning in ByteBufferUtil.EncodeString(..). - Extra: TLS support and exception reporting in benchmark (commented out). - Extra: fixes async send path in TcpSocketChannel and AbstractSocketChannel. Result: A benchmark of single client channel writing to a single server channel runs 3 times faster at 150K op/sec (vs 53K op/sec before) with no increase in CPU consumption. CompositeByteBuffer can be used directly in IChannel.WriteAsync.
33 lines
1.1 KiB
C#
33 lines
1.1 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 DotNetty.Transport.Tests.Performance.Utilities
|
|
{
|
|
using System;
|
|
using DotNetty.Common.Utilities;
|
|
using DotNetty.Transport.Channels;
|
|
|
|
public class ReadFinishedHandler : ChannelHandlerAdapter
|
|
{
|
|
readonly int expectedReads;
|
|
readonly IReadFinishedSignal signal;
|
|
int actualReads;
|
|
|
|
public ReadFinishedHandler(IReadFinishedSignal signal, int expectedReads)
|
|
{
|
|
this.signal = signal;
|
|
this.expectedReads = expectedReads;
|
|
}
|
|
|
|
public override void ChannelRead(IChannelHandlerContext context, object message)
|
|
{
|
|
ReferenceCountUtil.Release(message);
|
|
if (++this.actualReads == this.expectedReads)
|
|
{
|
|
this.signal.Signal();
|
|
}
|
|
}
|
|
|
|
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) => Console.WriteLine(exception.ToString());
|
|
}
|
|
} |