зеркало из https://github.com/Azure/DotNetty.git
Merge pull request #109 from nayato/lang2
Fixing minor issues and code style throughout
This commit is contained in:
Коммит
c0d9ed22e6
|
@ -11,20 +11,15 @@ namespace Echo.Client
|
|||
public class EchoClientHandler : ChannelHandlerAdapter
|
||||
{
|
||||
readonly IByteBuffer initialMessage;
|
||||
readonly byte[] buffer;
|
||||
|
||||
public EchoClientHandler()
|
||||
{
|
||||
this.buffer = new byte[EchoClientSettings.Size];
|
||||
this.initialMessage = Unpooled.Buffer(EchoClientSettings.Size);
|
||||
byte[] messageBytes = Encoding.UTF8.GetBytes("Hello world");
|
||||
this.initialMessage.WriteBytes(messageBytes);
|
||||
}
|
||||
|
||||
public override void ChannelActive(IChannelHandlerContext context)
|
||||
{
|
||||
context.WriteAndFlushAsync(this.initialMessage);
|
||||
}
|
||||
public override void ChannelActive(IChannelHandlerContext context) => context.WriteAndFlushAsync(this.initialMessage);
|
||||
|
||||
public override void ChannelRead(IChannelHandlerContext context, object message)
|
||||
{
|
||||
|
@ -36,14 +31,8 @@ namespace Echo.Client
|
|||
context.WriteAsync(message);
|
||||
}
|
||||
|
||||
public override void ChannelReadComplete(IChannelHandlerContext context)
|
||||
{
|
||||
context.Flush();
|
||||
}
|
||||
public override void ChannelReadComplete(IChannelHandlerContext context) => context.Flush();
|
||||
|
||||
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
|
||||
{
|
||||
context.CloseAsync();
|
||||
}
|
||||
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) => context.CloseAsync();
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ namespace Echo.Client
|
|||
|
||||
class Program
|
||||
{
|
||||
static async Task RunClient()
|
||||
static async Task RunClientAsync()
|
||||
{
|
||||
var eventListener = new ObservableEventListener();
|
||||
eventListener.LogToConsole();
|
||||
|
@ -62,9 +62,6 @@ namespace Echo.Client
|
|||
}
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Task.Run(() => RunClient()).Wait();
|
||||
}
|
||||
static void Main() => RunClientAsync().Wait();
|
||||
}
|
||||
}
|
|
@ -20,10 +20,7 @@ namespace Echo.Server
|
|||
context.WriteAsync(message);
|
||||
}
|
||||
|
||||
public override void ChannelReadComplete(IChannelHandlerContext context)
|
||||
{
|
||||
context.Flush();
|
||||
}
|
||||
public override void ChannelReadComplete(IChannelHandlerContext context) => context.Flush();
|
||||
|
||||
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Echo.Server
|
|||
|
||||
class Program
|
||||
{
|
||||
static async Task RunServer()
|
||||
static async Task RunServerAsync()
|
||||
{
|
||||
var eventListener = new ObservableEventListener();
|
||||
eventListener.LogToConsole();
|
||||
|
@ -61,9 +61,6 @@ namespace Echo.Server
|
|||
}
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Task.Run(() => RunServer()).Wait();
|
||||
}
|
||||
static void Main() => RunServerAsync().Wait();
|
||||
}
|
||||
}
|
|
@ -941,7 +941,7 @@ namespace DotNetty.Buffers
|
|||
{
|
||||
if (processor == null)
|
||||
{
|
||||
throw new ArgumentNullException("processor");
|
||||
throw new ArgumentNullException(nameof(processor));
|
||||
}
|
||||
|
||||
if (length == 0)
|
||||
|
|
|
@ -49,15 +49,9 @@ namespace DotNetty.Buffers
|
|||
this.emptyBuffer = new EmptyByteBuffer(this);
|
||||
}
|
||||
|
||||
public IByteBuffer Buffer()
|
||||
{
|
||||
return this.Buffer(DefaultInitialCapacity, int.MaxValue);
|
||||
}
|
||||
public IByteBuffer Buffer() => this.Buffer(DefaultInitialCapacity, int.MaxValue);
|
||||
|
||||
public IByteBuffer Buffer(int initialCapacity)
|
||||
{
|
||||
return this.Buffer(initialCapacity, int.MaxValue);
|
||||
}
|
||||
public IByteBuffer Buffer(int initialCapacity) => this.Buffer(initialCapacity, int.MaxValue);
|
||||
|
||||
public IByteBuffer Buffer(int initialCapacity, int maxCapacity)
|
||||
{
|
||||
|
|
|
@ -222,8 +222,8 @@ namespace DotNetty.Buffers
|
|||
/// identical to each other for {@code length} bytes starting at {@code aStartIndex}
|
||||
/// index for the {@code a} buffer and {@code bStartIndex} index for the {@code b} buffer.
|
||||
/// A more compact way to express this is:
|
||||
/// <p>
|
||||
/// {@code a[aStartIndex : aStartIndex + length] == b[bStartIndex : bStartIndex + length]}
|
||||
/// <p />
|
||||
/// {@code a[aStartIndex : aStartIndex + length] == b[bStartIndex : bStartIndex + length]}
|
||||
/// </summary>
|
||||
public static bool Equals(IByteBuffer a, int aStartIndex, IByteBuffer b, int bStartIndex, int length)
|
||||
{
|
||||
|
@ -404,19 +404,44 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
//todo: port
|
||||
//static int firstIndexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value)
|
||||
//{
|
||||
// fromIndex = Math.max(fromIndex, 0);
|
||||
// if (fromIndex >= toIndex || buffer.capacity() == 0)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
/// <summary>
|
||||
/// The default implementation of <see cref="IByteBuffer.IndexOf(int, int, byte)"/>.
|
||||
/// This method is useful when implementing a new buffer type.
|
||||
/// </summary>
|
||||
public static int IndexOf(IByteBuffer buffer, int fromIndex, int toIndex, byte value)
|
||||
{
|
||||
if (fromIndex <= toIndex)
|
||||
{
|
||||
return FirstIndexOf(buffer, fromIndex, toIndex, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return LastIndexOf(buffer, fromIndex, toIndex, value);
|
||||
}
|
||||
}
|
||||
|
||||
// return buffer.ForEachByte(fromIndex, toIndex - fromIndex, new ByteProcessor.IndexOfProcessor(value));
|
||||
//}
|
||||
static int FirstIndexOf(IByteBuffer buffer, int fromIndex, int toIndex, byte value)
|
||||
{
|
||||
fromIndex = Math.Max(fromIndex, 0);
|
||||
if (fromIndex >= toIndex || buffer.Capacity == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return buffer.ForEachByte(fromIndex, toIndex - fromIndex, new ByteProcessor.IndexOfProcessor(value));
|
||||
}
|
||||
|
||||
static int LastIndexOf(IByteBuffer buffer, int fromIndex, int toIndex, byte value)
|
||||
{
|
||||
fromIndex = Math.Min(fromIndex, buffer.Capacity);
|
||||
if (fromIndex < 0 || buffer.Capacity == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return buffer.ForEachByteDesc(toIndex, fromIndex - toIndex, new ByteProcessor.IndexOfProcessor(value));
|
||||
}
|
||||
|
||||
/// todo: port
|
||||
/// <summary>
|
||||
/// Returns a multi-line hexadecimal dump of the specified {@link ByteBuf} that is easy to read by humans.
|
||||
/// </summary>
|
||||
|
@ -524,7 +549,7 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the prefix of each hex dump row. Uses the look-up table for the buffer <= 64 KiB.
|
||||
/// Appends the prefix of each hex dump row. Uses the look-up table for the buffer <= 64 KiB.
|
||||
/// </summary>
|
||||
static void AppendHexDumpRowPrefix(StringBuilder dump, int row, int rowStartIndex)
|
||||
{
|
||||
|
|
|
@ -28,11 +28,7 @@ namespace DotNetty.Buffers
|
|||
this.Length = buffer.ReadableBytes;
|
||||
}
|
||||
|
||||
public void FreeIfNecessary()
|
||||
{
|
||||
// Unwrap so that we can free slices, too.
|
||||
this.Buffer.Release(); // We should not get a NPE here. If so, it must be a bug.
|
||||
}
|
||||
public void FreeIfNecessary() => this.Buffer.Release();
|
||||
}
|
||||
|
||||
static readonly ArraySegment<byte> EmptyNioBuffer = Unpooled.Empty.GetIoBuffer();
|
||||
|
@ -665,10 +661,7 @@ namespace DotNetty.Buffers
|
|||
return this.components[cIndex].Offset;
|
||||
}
|
||||
|
||||
public override byte GetByte(int index)
|
||||
{
|
||||
return this._GetByte(index);
|
||||
}
|
||||
public override byte GetByte(int index) => this._GetByte(index);
|
||||
|
||||
protected override byte _GetByte(int index)
|
||||
{
|
||||
|
@ -805,10 +798,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetByte(int index, int value)
|
||||
{
|
||||
this.SetByte(index, value);
|
||||
}
|
||||
protected override void _SetByte(int index, int value) => this.SetByte(index, value);
|
||||
|
||||
protected override void _SetShort(int index, int value)
|
||||
{
|
||||
|
@ -1009,10 +999,7 @@ namespace DotNetty.Buffers
|
|||
/// @param offset the offset for which the {@link IByteBuffer} should be returned
|
||||
/// @return the {@link IByteBuffer} on the specified index
|
||||
/// </summary>
|
||||
public IByteBuffer ComponentAtOffset(int offset)
|
||||
{
|
||||
return this.InternalComponentAtOffset(offset).Duplicate();
|
||||
}
|
||||
public IByteBuffer ComponentAtOffset(int offset) => this.InternalComponentAtOffset(offset).Duplicate();
|
||||
|
||||
/// <summary>
|
||||
/// Return the internal {@link IByteBuffer} on the specified index. Note that updating the indexes of the returned
|
||||
|
@ -1030,10 +1017,7 @@ namespace DotNetty.Buffers
|
|||
/// buffer will lead to an undefined behavior of this buffer.
|
||||
/// @param offset the offset for which the {@link IByteBuffer} should be returned
|
||||
/// </summary>
|
||||
public IByteBuffer InternalComponentAtOffset(int offset)
|
||||
{
|
||||
return this.FindComponent(offset).Buffer;
|
||||
}
|
||||
public IByteBuffer InternalComponentAtOffset(int offset) => this.FindComponent(offset).Buffer;
|
||||
|
||||
ComponentEntry FindComponent(int offset)
|
||||
{
|
||||
|
@ -1218,10 +1202,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
IByteBuffer AllocateBuffer(int capacity)
|
||||
{
|
||||
return this.Allocator.Buffer(capacity);
|
||||
}
|
||||
IByteBuffer AllocateBuffer(int capacity) => this.Allocator.Buffer(capacity);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
@ -1232,26 +1213,17 @@ namespace DotNetty.Buffers
|
|||
|
||||
public override IReferenceCounted Touch()
|
||||
{
|
||||
if (this.leak != null)
|
||||
{
|
||||
this.leak.Record();
|
||||
}
|
||||
this.leak?.Record();
|
||||
return this;
|
||||
}
|
||||
|
||||
public override IReferenceCounted Touch(object hint)
|
||||
{
|
||||
if (this.leak != null)
|
||||
{
|
||||
this.leak.Record(hint);
|
||||
}
|
||||
this.leak?.Record(hint);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override IByteBuffer DiscardSomeReadBytes()
|
||||
{
|
||||
return this.DiscardReadComponents();
|
||||
}
|
||||
public override IByteBuffer DiscardSomeReadBytes() => this.DiscardReadComponents();
|
||||
|
||||
protected override void Deallocate()
|
||||
{
|
||||
|
@ -1269,15 +1241,9 @@ namespace DotNetty.Buffers
|
|||
this.components[i].FreeIfNecessary();
|
||||
}
|
||||
|
||||
if (this.leak != null)
|
||||
{
|
||||
this.leak.Close();
|
||||
}
|
||||
this.leak?.Close();
|
||||
}
|
||||
|
||||
public override IByteBuffer Unwrap()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override IByteBuffer Unwrap() => null;
|
||||
}
|
||||
}
|
|
@ -25,52 +25,25 @@ namespace DotNetty.Buffers
|
|||
|
||||
public override int Capacity => this.buffer.Capacity;
|
||||
|
||||
public override IByteBuffer AdjustCapacity(int newCapacity)
|
||||
{
|
||||
return this.buffer.AdjustCapacity(newCapacity);
|
||||
}
|
||||
public override IByteBuffer AdjustCapacity(int newCapacity) => this.buffer.AdjustCapacity(newCapacity);
|
||||
|
||||
public override IByteBufferAllocator Allocator => this.buffer.Allocator;
|
||||
|
||||
public override byte GetByte(int index)
|
||||
{
|
||||
return this._GetByte(index);
|
||||
}
|
||||
public override byte GetByte(int index) => this._GetByte(index);
|
||||
|
||||
protected override byte _GetByte(int index)
|
||||
{
|
||||
return this.buffer.GetByte(index);
|
||||
}
|
||||
protected override byte _GetByte(int index) => this.buffer.GetByte(index);
|
||||
|
||||
public override short GetShort(int index)
|
||||
{
|
||||
return this._GetShort(index);
|
||||
}
|
||||
public override short GetShort(int index) => this._GetShort(index);
|
||||
|
||||
protected override short _GetShort(int index)
|
||||
{
|
||||
return this.buffer.GetShort(index);
|
||||
}
|
||||
protected override short _GetShort(int index) => this.buffer.GetShort(index);
|
||||
|
||||
public override int GetInt(int index)
|
||||
{
|
||||
return this._GetInt(index);
|
||||
}
|
||||
public override int GetInt(int index) => this._GetInt(index);
|
||||
|
||||
protected override int _GetInt(int index)
|
||||
{
|
||||
return this.buffer.GetInt(index);
|
||||
}
|
||||
protected override int _GetInt(int index) => this.buffer.GetInt(index);
|
||||
|
||||
public override long GetLong(int index)
|
||||
{
|
||||
return this._GetLong(index);
|
||||
}
|
||||
public override long GetLong(int index) => this._GetLong(index);
|
||||
|
||||
protected override long _GetLong(int index)
|
||||
{
|
||||
return this.buffer.GetLong(index);
|
||||
}
|
||||
protected override long _GetLong(int index) => this.buffer.GetLong(index);
|
||||
|
||||
public override IByteBuffer GetBytes(int index, IByteBuffer destination, int dstIndex, int length)
|
||||
{
|
||||
|
@ -102,10 +75,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetByte(int index, int value)
|
||||
{
|
||||
this.buffer.SetByte(index, value);
|
||||
}
|
||||
protected override void _SetByte(int index, int value) => this.buffer.SetByte(index, value);
|
||||
|
||||
public override IByteBuffer SetShort(int index, int value)
|
||||
{
|
||||
|
@ -113,10 +83,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetShort(int index, int value)
|
||||
{
|
||||
this.buffer.SetShort(index, value);
|
||||
}
|
||||
protected override void _SetShort(int index, int value) => this.buffer.SetShort(index, value);
|
||||
|
||||
public override IByteBuffer SetInt(int index, int value)
|
||||
{
|
||||
|
@ -124,10 +91,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetInt(int index, int value)
|
||||
{
|
||||
this.buffer.SetInt(index, value);
|
||||
}
|
||||
protected override void _SetInt(int index, int value) => this.buffer.SetInt(index, value);
|
||||
|
||||
public override IByteBuffer SetLong(int index, long value)
|
||||
{
|
||||
|
@ -135,10 +99,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetLong(int index, long value)
|
||||
{
|
||||
this.buffer.SetLong(index, value);
|
||||
}
|
||||
protected override void _SetLong(int index, long value) => this.buffer.SetLong(index, value);
|
||||
|
||||
public override IByteBuffer SetBytes(int index, IByteBuffer src, int srcIndex, int length)
|
||||
{
|
||||
|
@ -152,10 +113,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public override Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
return this.buffer.SetBytesAsync(index, src, length, cancellationToken);
|
||||
}
|
||||
public override Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken) => this.buffer.SetBytesAsync(index, src, length, cancellationToken);
|
||||
|
||||
public override int IoBufferCount => this.Unwrap().IoBufferCount;
|
||||
|
||||
|
@ -165,16 +123,10 @@ namespace DotNetty.Buffers
|
|||
|
||||
public override byte[] Array => this.buffer.Array;
|
||||
|
||||
public override IByteBuffer Copy(int index, int length)
|
||||
{
|
||||
return this.buffer.Copy(index, length);
|
||||
}
|
||||
public override IByteBuffer Copy(int index, int length) => this.buffer.Copy(index, length);
|
||||
|
||||
public override int ArrayOffset => this.buffer.ArrayOffset;
|
||||
|
||||
public override IByteBuffer Unwrap()
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
public override IByteBuffer Unwrap() => this.buffer;
|
||||
}
|
||||
}
|
|
@ -20,8 +20,6 @@ namespace DotNetty.Buffers
|
|||
static readonly ArraySegment<byte> EmptyBuffer = new ArraySegment<byte>(ArrayExtensions.ZeroBytes);
|
||||
static readonly ArraySegment<byte>[] EmptyBuffers = { EmptyBuffer };
|
||||
|
||||
readonly IByteBufferAllocator allocator;
|
||||
readonly ByteOrder order;
|
||||
readonly string str;
|
||||
EmptyByteBuffer swapped;
|
||||
|
||||
|
@ -34,8 +32,8 @@ namespace DotNetty.Buffers
|
|||
{
|
||||
Contract.Requires(allocator != null);
|
||||
|
||||
this.allocator = allocator;
|
||||
this.order = order;
|
||||
this.Allocator = allocator;
|
||||
this.Order = order;
|
||||
this.str = this.GetType().Name + (order == ByteOrder.BigEndian ? "BE" : "LE");
|
||||
}
|
||||
|
||||
|
@ -48,21 +46,15 @@ namespace DotNetty.Buffers
|
|||
|
||||
public int MaxCapacity => 0;
|
||||
|
||||
public IByteBufferAllocator Allocator => this.allocator;
|
||||
public IByteBufferAllocator Allocator { get; }
|
||||
|
||||
public int ReaderIndex => 0;
|
||||
|
||||
public int WriterIndex => 0;
|
||||
|
||||
public IByteBuffer SetWriterIndex(int writerIndex)
|
||||
{
|
||||
return this.CheckIndex(writerIndex);
|
||||
}
|
||||
public IByteBuffer SetWriterIndex(int writerIndex) => this.CheckIndex(writerIndex);
|
||||
|
||||
public IByteBuffer SetReaderIndex(int readerIndex)
|
||||
{
|
||||
return this.CheckIndex(readerIndex);
|
||||
}
|
||||
public IByteBuffer SetReaderIndex(int readerIndex) => this.CheckIndex(readerIndex);
|
||||
|
||||
public IByteBuffer SetIndex(int readerIndex, int writerIndex)
|
||||
{
|
||||
|
@ -76,60 +68,27 @@ namespace DotNetty.Buffers
|
|||
|
||||
public int MaxWritableBytes => 0;
|
||||
|
||||
public bool IsReadable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool IsReadable() => false;
|
||||
|
||||
public bool IsReadable(int size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool IsReadable(int size) => false;
|
||||
|
||||
public bool IsWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool IsWritable() => false;
|
||||
|
||||
public bool IsWritable(int size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool IsWritable(int size) => false;
|
||||
|
||||
public IByteBuffer Clear()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer Clear() => this;
|
||||
|
||||
public IByteBuffer MarkReaderIndex()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer MarkReaderIndex() => this;
|
||||
|
||||
public IByteBuffer ResetReaderIndex()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer ResetReaderIndex() => this;
|
||||
|
||||
public IByteBuffer MarkWriterIndex()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer MarkWriterIndex() => this;
|
||||
|
||||
public IByteBuffer ResetWriterIndex()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer ResetWriterIndex() => this;
|
||||
|
||||
public IByteBuffer DiscardReadBytes()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer DiscardReadBytes() => this;
|
||||
|
||||
public IByteBuffer DiscardSomeReadBytes()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer DiscardSomeReadBytes() => this;
|
||||
|
||||
public IByteBuffer EnsureWritable(int minWritableBytes)
|
||||
{
|
||||
|
@ -199,35 +158,17 @@ namespace DotNetty.Buffers
|
|||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination)
|
||||
{
|
||||
return this.CheckIndex(index, destination.WritableBytes);
|
||||
}
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination) => this.CheckIndex(index, destination.WritableBytes);
|
||||
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination, int dstIndex, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination, int dstIndex, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public IByteBuffer GetBytes(int index, byte[] destination)
|
||||
{
|
||||
return this.CheckIndex(index, destination.Length);
|
||||
}
|
||||
public IByteBuffer GetBytes(int index, byte[] destination) => this.CheckIndex(index, destination.Length);
|
||||
|
||||
public IByteBuffer GetBytes(int index, byte[] destination, int dstIndex, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer GetBytes(int index, byte[] destination, int dstIndex, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public IByteBuffer GetBytes(int index, Stream destination, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer GetBytes(int index, Stream destination, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public IByteBuffer SetBoolean(int index, bool value)
|
||||
{
|
||||
|
@ -279,25 +220,13 @@ namespace DotNetty.Buffers
|
|||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
public IByteBuffer SetBytes(int index, IByteBuffer src, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer SetBytes(int index, IByteBuffer src, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public IByteBuffer SetBytes(int index, IByteBuffer src, int srcIndex, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer SetBytes(int index, IByteBuffer src, int srcIndex, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public IByteBuffer SetBytes(int index, byte[] src)
|
||||
{
|
||||
return this.CheckIndex(index, src.Length);
|
||||
}
|
||||
public IByteBuffer SetBytes(int index, byte[] src) => this.CheckIndex(index, src.Length);
|
||||
|
||||
public IByteBuffer SetBytes(int index, byte[] src, int srcIndex, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer SetBytes(int index, byte[] src, int srcIndex, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -350,45 +279,21 @@ namespace DotNetty.Buffers
|
|||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
public IByteBuffer ReadBytes(int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer ReadBytes(int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination)
|
||||
{
|
||||
return this.CheckLength(destination.WritableBytes);
|
||||
}
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination) => this.CheckLength(destination.WritableBytes);
|
||||
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination, int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination, int dstIndex, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination, int dstIndex, int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer ReadBytes(byte[] destination)
|
||||
{
|
||||
return this.CheckLength(destination.Length);
|
||||
}
|
||||
public IByteBuffer ReadBytes(byte[] destination) => this.CheckLength(destination.Length);
|
||||
|
||||
public IByteBuffer ReadBytes(byte[] destination, int dstIndex, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer ReadBytes(byte[] destination, int dstIndex, int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer ReadBytes(Stream destination, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer ReadBytes(Stream destination, int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer SkipBytes(int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer SkipBytes(int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer WriteBoolean(bool value)
|
||||
{
|
||||
|
@ -440,25 +345,13 @@ namespace DotNetty.Buffers
|
|||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
public IByteBuffer WriteBytes(IByteBuffer src, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer WriteBytes(IByteBuffer src, int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer WriteBytes(IByteBuffer src, int srcIndex, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer WriteBytes(IByteBuffer src, int srcIndex, int length) => this.CheckLength(length);
|
||||
|
||||
public IByteBuffer WriteBytes(byte[] src)
|
||||
{
|
||||
return this.CheckLength(src.Length);
|
||||
}
|
||||
public IByteBuffer WriteBytes(byte[] src) => this.CheckLength(src.Length);
|
||||
|
||||
public IByteBuffer WriteBytes(byte[] src, int srcIndex, int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer WriteBytes(byte[] src, int srcIndex, int length) => this.CheckLength(length);
|
||||
|
||||
public int IoBufferCount => 1;
|
||||
|
||||
|
@ -482,15 +375,9 @@ namespace DotNetty.Buffers
|
|||
|
||||
public byte[] Array => ArrayExtensions.ZeroBytes;
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
return ArrayExtensions.ZeroBytes;
|
||||
}
|
||||
public byte[] ToArray() => ArrayExtensions.ZeroBytes;
|
||||
|
||||
public IByteBuffer Duplicate()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer Duplicate() => this;
|
||||
|
||||
public IByteBuffer WithOrder(ByteOrder endianness)
|
||||
{
|
||||
|
@ -509,10 +396,7 @@ namespace DotNetty.Buffers
|
|||
return s;
|
||||
}
|
||||
|
||||
public IByteBuffer Copy()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer Copy() => this;
|
||||
|
||||
public IByteBuffer Copy(int index, int length)
|
||||
{
|
||||
|
@ -520,22 +404,13 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public IByteBuffer Slice()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IByteBuffer Slice() => this;
|
||||
|
||||
public IByteBuffer Slice(int index, int length)
|
||||
{
|
||||
return this.CheckIndex(index, length);
|
||||
}
|
||||
public IByteBuffer Slice(int index, int length) => this.CheckIndex(index, length);
|
||||
|
||||
public int ArrayOffset => 0;
|
||||
|
||||
public IByteBuffer ReadSlice(int length)
|
||||
{
|
||||
return this.CheckLength(length);
|
||||
}
|
||||
public IByteBuffer ReadSlice(int length) => this.CheckLength(length);
|
||||
|
||||
public Task WriteBytesAsync(Stream stream, int length)
|
||||
{
|
||||
|
@ -549,70 +424,37 @@ namespace DotNetty.Buffers
|
|||
return TaskEx.Completed;
|
||||
}
|
||||
|
||||
public IByteBuffer Unwrap()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public IByteBuffer Unwrap() => null;
|
||||
|
||||
public ByteOrder Order => this.order;
|
||||
public ByteOrder Order { get; }
|
||||
|
||||
public int ReferenceCount => 1;
|
||||
|
||||
public IReferenceCounted Retain()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IReferenceCounted Retain() => this;
|
||||
|
||||
public IReferenceCounted Retain(int increment)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IReferenceCounted Retain(int increment) => this;
|
||||
|
||||
public IReferenceCounted Touch()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IReferenceCounted Touch() => this;
|
||||
|
||||
public IReferenceCounted Touch(object hint)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IReferenceCounted Touch(object hint) => this;
|
||||
|
||||
public bool Release()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool Release() => false;
|
||||
|
||||
public bool Release(int decrement)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool Release(int decrement) => false;
|
||||
|
||||
public override int GetHashCode() => 0;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var buffer = obj as IByteBuffer;
|
||||
return this.Equals(buffer);
|
||||
}
|
||||
|
||||
public bool Equals(IByteBuffer buffer)
|
||||
{
|
||||
return buffer != null && !buffer.IsReadable();
|
||||
}
|
||||
public bool Equals(IByteBuffer buffer) => buffer != null && !buffer.IsReadable();
|
||||
|
||||
public int CompareTo(IByteBuffer buffer)
|
||||
{
|
||||
return buffer.IsReadable() ? -1 : 0;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.str;
|
||||
}
|
||||
public int CompareTo(IByteBuffer buffer) => buffer.IsReadable() ? -1 : 0;
|
||||
|
||||
public override string ToString() => this.str;
|
||||
|
||||
IByteBuffer CheckIndex(int index)
|
||||
{
|
||||
|
@ -649,10 +491,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public int ForEachByte(ByteProcessor processor)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
public int ForEachByte(ByteProcessor processor) => -1;
|
||||
|
||||
public int ForEachByte(int index, int length, ByteProcessor processor)
|
||||
{
|
||||
|
@ -660,10 +499,7 @@ namespace DotNetty.Buffers
|
|||
return -1;
|
||||
}
|
||||
|
||||
public int ForEachByteDesc(ByteProcessor processor)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
public int ForEachByteDesc(ByteProcessor processor) => -1;
|
||||
|
||||
public int ForEachByteDesc(int index, int length, ByteProcessor processor)
|
||||
{
|
||||
|
@ -671,10 +507,7 @@ namespace DotNetty.Buffers
|
|||
return -1;
|
||||
}
|
||||
|
||||
public string ToString(Encoding encoding)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
public string ToString(Encoding encoding) => string.Empty;
|
||||
|
||||
public string ToString(int index, int length, Encoding encoding)
|
||||
{
|
||||
|
|
|
@ -15,15 +15,9 @@ namespace DotNetty.Buffers
|
|||
this.leak = leak;
|
||||
}
|
||||
|
||||
public override IReferenceCounted Touch()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public override IReferenceCounted Touch() => this;
|
||||
|
||||
public override IReferenceCounted Touch(object hint)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public override IReferenceCounted Touch(object hint) => this;
|
||||
|
||||
public override bool Release()
|
||||
{
|
||||
|
@ -58,24 +52,12 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
public override IByteBuffer Slice()
|
||||
{
|
||||
return new SimpleLeakAwareByteBuffer(base.Slice(), this.leak);
|
||||
}
|
||||
public override IByteBuffer Slice() => new SimpleLeakAwareByteBuffer(base.Slice(), this.leak);
|
||||
|
||||
public override IByteBuffer Slice(int index, int length)
|
||||
{
|
||||
return new SimpleLeakAwareByteBuffer(base.Slice(index, length), this.leak);
|
||||
}
|
||||
public override IByteBuffer Slice(int index, int length) => new SimpleLeakAwareByteBuffer(base.Slice(index, length), this.leak);
|
||||
|
||||
public override IByteBuffer Duplicate()
|
||||
{
|
||||
return new SimpleLeakAwareByteBuffer(base.Duplicate(), this.leak);
|
||||
}
|
||||
public override IByteBuffer Duplicate() => new SimpleLeakAwareByteBuffer(base.Duplicate(), this.leak);
|
||||
|
||||
public override IByteBuffer ReadSlice(int length)
|
||||
{
|
||||
return new SimpleLeakAwareByteBuffer(base.ReadSlice(length), this.leak);
|
||||
}
|
||||
public override IByteBuffer ReadSlice(int length) => new SimpleLeakAwareByteBuffer(base.ReadSlice(length), this.leak);
|
||||
}
|
||||
}
|
|
@ -43,10 +43,7 @@ namespace DotNetty.Buffers
|
|||
this.SetWriterIndex(length);
|
||||
}
|
||||
|
||||
public override IByteBuffer Unwrap()
|
||||
{
|
||||
return this.buffer;
|
||||
}
|
||||
public override IByteBuffer Unwrap() => this.buffer;
|
||||
|
||||
public override IByteBufferAllocator Allocator => this.buffer.Allocator;
|
||||
|
||||
|
@ -79,25 +76,13 @@ namespace DotNetty.Buffers
|
|||
|
||||
public override int ArrayOffset => this.buffer.ArrayOffset + this.adjustment;
|
||||
|
||||
protected override byte _GetByte(int index)
|
||||
{
|
||||
return this.buffer.GetByte(index + this.adjustment);
|
||||
}
|
||||
protected override byte _GetByte(int index) => this.buffer.GetByte(index + this.adjustment);
|
||||
|
||||
protected override short _GetShort(int index)
|
||||
{
|
||||
return this.buffer.GetShort(index + this.adjustment);
|
||||
}
|
||||
protected override short _GetShort(int index) => this.buffer.GetShort(index + this.adjustment);
|
||||
|
||||
protected override int _GetInt(int index)
|
||||
{
|
||||
return this.buffer.GetInt(index + this.adjustment);
|
||||
}
|
||||
protected override int _GetInt(int index) => this.buffer.GetInt(index + this.adjustment);
|
||||
|
||||
protected override long _GetLong(int index)
|
||||
{
|
||||
return this.buffer.GetLong(index + this.adjustment);
|
||||
}
|
||||
protected override long _GetLong(int index) => this.buffer.GetLong(index + this.adjustment);
|
||||
|
||||
public override IByteBuffer Duplicate()
|
||||
{
|
||||
|
@ -149,25 +134,13 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetByte(int index, int value)
|
||||
{
|
||||
this.buffer.SetByte(index + this.adjustment, value);
|
||||
}
|
||||
protected override void _SetByte(int index, int value) => this.buffer.SetByte(index + this.adjustment, value);
|
||||
|
||||
protected override void _SetShort(int index, int value)
|
||||
{
|
||||
this.buffer.SetShort(index + this.adjustment, value);
|
||||
}
|
||||
protected override void _SetShort(int index, int value) => this.buffer.SetShort(index + this.adjustment, value);
|
||||
|
||||
protected override void _SetInt(int index, int value)
|
||||
{
|
||||
this.buffer.SetInt(index + this.adjustment, value);
|
||||
}
|
||||
protected override void _SetInt(int index, int value) => this.buffer.SetInt(index + this.adjustment, value);
|
||||
|
||||
protected override void _SetLong(int index, long value)
|
||||
{
|
||||
this.buffer.SetLong(index + this.adjustment, value);
|
||||
}
|
||||
protected override void _SetLong(int index, long value) => this.buffer.SetLong(index + this.adjustment, value);
|
||||
|
||||
public override IByteBuffer SetBytes(int index, byte[] src, int srcIndex, int length)
|
||||
{
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace DotNetty.Buffers
|
|||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -19,7 +18,6 @@ namespace DotNetty.Buffers
|
|||
public class SwappedByteBuffer : IByteBuffer
|
||||
{
|
||||
readonly IByteBuffer buf;
|
||||
readonly ByteOrder order;
|
||||
|
||||
public SwappedByteBuffer(IByteBuffer buf)
|
||||
{
|
||||
|
@ -28,11 +26,11 @@ namespace DotNetty.Buffers
|
|||
this.buf = buf;
|
||||
if (buf.Order == ByteOrder.BigEndian)
|
||||
{
|
||||
this.order = ByteOrder.LittleEndian;
|
||||
this.Order = ByteOrder.LittleEndian;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.order = ByteOrder.BigEndian;
|
||||
this.Order = ByteOrder.BigEndian;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,22 +60,13 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public bool Release()
|
||||
{
|
||||
return this.buf.Release();
|
||||
}
|
||||
public bool Release() => this.buf.Release();
|
||||
|
||||
public bool Release(int decrement)
|
||||
{
|
||||
return this.buf.Release(decrement);
|
||||
}
|
||||
public bool Release(int decrement) => this.buf.Release(decrement);
|
||||
|
||||
public int Capacity => this.buf.Capacity;
|
||||
|
||||
public IByteBuffer AdjustCapacity(int newCapacity)
|
||||
{
|
||||
return this.buf.AdjustCapacity(newCapacity);
|
||||
}
|
||||
public IByteBuffer AdjustCapacity(int newCapacity) => this.buf.AdjustCapacity(newCapacity);
|
||||
|
||||
public int MaxCapacity => this.buf.MaxCapacity;
|
||||
|
||||
|
@ -111,25 +100,13 @@ namespace DotNetty.Buffers
|
|||
|
||||
public int MaxWritableBytes => this.buf.MaxWritableBytes;
|
||||
|
||||
public bool IsReadable()
|
||||
{
|
||||
return this.buf.IsReadable();
|
||||
}
|
||||
public bool IsReadable() => this.buf.IsReadable();
|
||||
|
||||
public bool IsReadable(int size)
|
||||
{
|
||||
return this.buf.IsReadable(size);
|
||||
}
|
||||
public bool IsReadable(int size) => this.buf.IsReadable(size);
|
||||
|
||||
public bool IsWritable()
|
||||
{
|
||||
return this.buf.IsWritable();
|
||||
}
|
||||
public bool IsWritable() => this.buf.IsWritable();
|
||||
|
||||
public bool IsWritable(int size)
|
||||
{
|
||||
return this.buf.IsWritable(size);
|
||||
}
|
||||
public bool IsWritable(int size) => this.buf.IsWritable(size);
|
||||
|
||||
public IByteBuffer Clear()
|
||||
{
|
||||
|
@ -183,20 +160,11 @@ namespace DotNetty.Buffers
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool GetBoolean(int index)
|
||||
{
|
||||
return this.buf.GetBoolean(index);
|
||||
}
|
||||
public bool GetBoolean(int index) => this.buf.GetBoolean(index);
|
||||
|
||||
public byte GetByte(int index)
|
||||
{
|
||||
return this.buf.GetByte(index);
|
||||
}
|
||||
public byte GetByte(int index) => this.buf.GetByte(index);
|
||||
|
||||
public short GetShort(int index)
|
||||
{
|
||||
return ByteBufferUtil.SwapShort(this.buf.GetShort(index));
|
||||
}
|
||||
public short GetShort(int index) => ByteBufferUtil.SwapShort(this.buf.GetShort(index));
|
||||
|
||||
public ushort GetUnsignedShort(int index)
|
||||
{
|
||||
|
@ -206,10 +174,7 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
public int GetInt(int index)
|
||||
{
|
||||
return ByteBufferUtil.SwapInt(this.buf.GetInt(index));
|
||||
}
|
||||
public int GetInt(int index) => ByteBufferUtil.SwapInt(this.buf.GetInt(index));
|
||||
|
||||
public uint GetUnsignedInt(int index)
|
||||
{
|
||||
|
@ -219,20 +184,11 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
public long GetLong(int index)
|
||||
{
|
||||
return ByteBufferUtil.SwapLong(this.buf.GetLong(index));
|
||||
}
|
||||
public long GetLong(int index) => ByteBufferUtil.SwapLong(this.buf.GetLong(index));
|
||||
|
||||
public char GetChar(int index)
|
||||
{
|
||||
return (char)this.GetShort(index);
|
||||
}
|
||||
public char GetChar(int index) => (char)this.GetShort(index);
|
||||
|
||||
public double GetDouble(int index)
|
||||
{
|
||||
return BitConverter.Int64BitsToDouble(this.GetLong(index));
|
||||
}
|
||||
public double GetDouble(int index) => BitConverter.Int64BitsToDouble(this.GetLong(index));
|
||||
|
||||
public IByteBuffer GetBytes(int index, IByteBuffer destination)
|
||||
{
|
||||
|
@ -365,25 +321,13 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
return this.buf.SetBytesAsync(index, src, length, cancellationToken);
|
||||
}
|
||||
public Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken) => this.buf.SetBytesAsync(index, src, length, cancellationToken);
|
||||
|
||||
public bool ReadBoolean()
|
||||
{
|
||||
return this.buf.ReadBoolean();
|
||||
}
|
||||
public bool ReadBoolean() => this.buf.ReadBoolean();
|
||||
|
||||
public byte ReadByte()
|
||||
{
|
||||
return this.buf.ReadByte();
|
||||
}
|
||||
public byte ReadByte() => this.buf.ReadByte();
|
||||
|
||||
public short ReadShort()
|
||||
{
|
||||
return ByteBufferUtil.SwapShort(this.buf.ReadShort());
|
||||
}
|
||||
public short ReadShort() => ByteBufferUtil.SwapShort(this.buf.ReadShort());
|
||||
|
||||
public ushort ReadUnsignedShort()
|
||||
{
|
||||
|
@ -393,10 +337,7 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
public int ReadInt()
|
||||
{
|
||||
return ByteBufferUtil.SwapInt(this.buf.ReadInt());
|
||||
}
|
||||
public int ReadInt() => ByteBufferUtil.SwapInt(this.buf.ReadInt());
|
||||
|
||||
public uint ReadUnsignedInt()
|
||||
{
|
||||
|
@ -406,25 +347,13 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
}
|
||||
|
||||
public long ReadLong()
|
||||
{
|
||||
return ByteBufferUtil.SwapLong(this.buf.ReadLong());
|
||||
}
|
||||
public long ReadLong() => ByteBufferUtil.SwapLong(this.buf.ReadLong());
|
||||
|
||||
public char ReadChar()
|
||||
{
|
||||
return (char)this.ReadShort();
|
||||
}
|
||||
public char ReadChar() => (char)this.ReadShort();
|
||||
|
||||
public double ReadDouble()
|
||||
{
|
||||
return BitConverter.Int64BitsToDouble(this.ReadLong());
|
||||
}
|
||||
public double ReadDouble() => BitConverter.Int64BitsToDouble(this.ReadLong());
|
||||
|
||||
public IByteBuffer ReadBytes(int length)
|
||||
{
|
||||
return this.buf.ReadBytes(length).WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer ReadBytes(int length) => this.buf.ReadBytes(length).WithOrder(this.Order);
|
||||
|
||||
public IByteBuffer ReadBytes(IByteBuffer destination)
|
||||
{
|
||||
|
@ -577,17 +506,11 @@ namespace DotNetty.Buffers
|
|||
|
||||
public byte[] ToArray() => this.buf.ToArray();
|
||||
|
||||
public IByteBuffer Duplicate()
|
||||
{
|
||||
return this.buf.Duplicate().WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer Duplicate() => this.buf.Duplicate().WithOrder(this.Order);
|
||||
|
||||
public IByteBuffer Unwrap()
|
||||
{
|
||||
return this.buf.Unwrap();
|
||||
}
|
||||
public IByteBuffer Unwrap() => this.buf.Unwrap();
|
||||
|
||||
public ByteOrder Order => this.order;
|
||||
public ByteOrder Order { get; }
|
||||
|
||||
public IByteBuffer WithOrder(ByteOrder endianness)
|
||||
{
|
||||
|
@ -598,72 +521,33 @@ namespace DotNetty.Buffers
|
|||
return this.buf;
|
||||
}
|
||||
|
||||
public IByteBuffer Copy()
|
||||
{
|
||||
return this.buf.Copy().WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer Copy() => this.buf.Copy().WithOrder(this.Order);
|
||||
|
||||
public IByteBuffer Copy(int index, int length)
|
||||
{
|
||||
return this.buf.Copy(index, length).WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer Copy(int index, int length) => this.buf.Copy(index, length).WithOrder(this.Order);
|
||||
|
||||
public IByteBuffer Slice()
|
||||
{
|
||||
return this.buf.Slice().WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer Slice() => this.buf.Slice().WithOrder(this.Order);
|
||||
|
||||
public IByteBuffer Slice(int index, int length)
|
||||
{
|
||||
return this.buf.Slice(index, length).WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer Slice(int index, int length) => this.buf.Slice(index, length).WithOrder(this.Order);
|
||||
|
||||
public int ArrayOffset => this.buf.ArrayOffset;
|
||||
|
||||
public IByteBuffer ReadSlice(int length)
|
||||
{
|
||||
return this.buf.ReadSlice(length).WithOrder(this.Order);
|
||||
}
|
||||
public IByteBuffer ReadSlice(int length) => this.buf.ReadSlice(length).WithOrder(this.Order);
|
||||
|
||||
public Task WriteBytesAsync(Stream stream, int length)
|
||||
{
|
||||
return this.buf.WriteBytesAsync(stream, length);
|
||||
}
|
||||
public Task WriteBytesAsync(Stream stream, int length) => this.buf.WriteBytesAsync(stream, length);
|
||||
|
||||
public Task WriteBytesAsync(Stream stream, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
return this.buf.WriteBytesAsync(stream, length, cancellationToken);
|
||||
}
|
||||
public Task WriteBytesAsync(Stream stream, int length, CancellationToken cancellationToken) => this.buf.WriteBytesAsync(stream, length, cancellationToken);
|
||||
|
||||
public int ForEachByte(ByteProcessor processor)
|
||||
{
|
||||
return this.buf.ForEachByte(processor);
|
||||
}
|
||||
public int ForEachByte(ByteProcessor processor) => this.buf.ForEachByte(processor);
|
||||
|
||||
public int ForEachByte(int index, int length, ByteProcessor processor)
|
||||
{
|
||||
return this.buf.ForEachByte(index, length, processor);
|
||||
}
|
||||
public int ForEachByte(int index, int length, ByteProcessor processor) => this.buf.ForEachByte(index, length, processor);
|
||||
|
||||
public int ForEachByteDesc(ByteProcessor processor)
|
||||
{
|
||||
return this.buf.ForEachByteDesc(processor);
|
||||
}
|
||||
public int ForEachByteDesc(ByteProcessor processor) => this.buf.ForEachByteDesc(processor);
|
||||
|
||||
public int ForEachByteDesc(int index, int length, ByteProcessor processor)
|
||||
{
|
||||
return this.buf.ForEachByteDesc(index, length, processor);
|
||||
}
|
||||
public int ForEachByteDesc(int index, int length, ByteProcessor processor) => this.buf.ForEachByteDesc(index, length, processor);
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.buf.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => this.buf.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this.Equals(obj as IByteBuffer);
|
||||
}
|
||||
public override bool Equals(object obj) => this.Equals(obj as IByteBuffer);
|
||||
|
||||
public bool Equals(IByteBuffer buffer)
|
||||
{
|
||||
|
@ -678,24 +562,12 @@ namespace DotNetty.Buffers
|
|||
return false;
|
||||
}
|
||||
|
||||
public int CompareTo(IByteBuffer buffer)
|
||||
{
|
||||
return ByteBufferUtil.Compare(this, buffer);
|
||||
}
|
||||
public int CompareTo(IByteBuffer buffer) => ByteBufferUtil.Compare(this, buffer);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Swapped(" + this.buf + ")";
|
||||
}
|
||||
public override string ToString() => "Swapped(" + this.buf + ")";
|
||||
|
||||
public string ToString(Encoding encoding)
|
||||
{
|
||||
return this.buf.ToString(encoding);
|
||||
}
|
||||
public string ToString(Encoding encoding) => this.buf.ToString(encoding);
|
||||
|
||||
public string ToString(int index, int length, Encoding encoding)
|
||||
{
|
||||
return this.buf.ToString(index, length, encoding);
|
||||
}
|
||||
public string ToString(int index, int length, Encoding encoding) => this.buf.ToString(index, length, encoding);
|
||||
}
|
||||
}
|
|
@ -15,10 +15,7 @@ namespace DotNetty.Buffers
|
|||
|
||||
public static readonly IByteBuffer Empty = Allocator.Buffer(0, 0);
|
||||
|
||||
public static IByteBuffer Buffer()
|
||||
{
|
||||
return Allocator.Buffer();
|
||||
}
|
||||
public static IByteBuffer Buffer() => Allocator.Buffer();
|
||||
|
||||
public static IByteBuffer Buffer(int initialCapacity)
|
||||
{
|
||||
|
@ -105,7 +102,7 @@ namespace DotNetty.Buffers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new big-endian buffer whose content is a copy of the specified <see cref="array" />.
|
||||
/// Creates a new big-endian buffer whose content is a copy of the specified <see cref="Array" />.
|
||||
/// The new buffer's <see cref="IByteBuffer.ReaderIndex" /> and <see cref="IByteBuffer.WriterIndex" />
|
||||
/// are <c>0</c> and <see cref="IByteBuffer.Capacity" /> respectively.
|
||||
/// </summary>
|
||||
|
|
|
@ -13,9 +13,6 @@ namespace DotNetty.Buffers
|
|||
/// </summary>
|
||||
public static readonly UnpooledByteBufferAllocator Default = new UnpooledByteBufferAllocator();
|
||||
|
||||
protected override IByteBuffer NewBuffer(int initialCapacity, int maxCapacity)
|
||||
{
|
||||
return new UnpooledHeapByteBuffer(this, initialCapacity, maxCapacity);
|
||||
}
|
||||
protected override IByteBuffer NewBuffer(int initialCapacity, int maxCapacity) => new UnpooledHeapByteBuffer(this, initialCapacity, maxCapacity);
|
||||
}
|
||||
}
|
|
@ -47,10 +47,7 @@ namespace DotNetty.Buffers
|
|||
this.SetIndex(readerIndex, writerIndex);
|
||||
}
|
||||
|
||||
protected void SetArray(byte[] initialArray)
|
||||
{
|
||||
this.array = initialArray;
|
||||
}
|
||||
protected void SetArray(byte[] initialArray) => this.array = initialArray;
|
||||
|
||||
public override IByteBufferAllocator Allocator => this.allocator;
|
||||
|
||||
|
@ -191,10 +188,7 @@ namespace DotNetty.Buffers
|
|||
return this._GetByte(index);
|
||||
}
|
||||
|
||||
protected override byte _GetByte(int index)
|
||||
{
|
||||
return this.array[index];
|
||||
}
|
||||
protected override byte _GetByte(int index) => this.array[index];
|
||||
|
||||
public override short GetShort(int index)
|
||||
{
|
||||
|
@ -202,10 +196,7 @@ namespace DotNetty.Buffers
|
|||
return this._GetShort(index);
|
||||
}
|
||||
|
||||
protected override short _GetShort(int index)
|
||||
{
|
||||
return unchecked((short)(this.array[index] << 8 | this.array[index + 1]));
|
||||
}
|
||||
protected override short _GetShort(int index) => unchecked((short)(this.array[index] << 8 | this.array[index + 1]));
|
||||
|
||||
public override int GetInt(int index)
|
||||
{
|
||||
|
@ -250,10 +241,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
protected override void _SetByte(int index, int value)
|
||||
{
|
||||
this.array[index] = (byte)value;
|
||||
}
|
||||
protected override void _SetByte(int index, int value) => this.array[index] = (byte)value;
|
||||
|
||||
public override IByteBuffer SetShort(int index, int value)
|
||||
{
|
||||
|
@ -321,14 +309,8 @@ namespace DotNetty.Buffers
|
|||
return new UnpooledHeapByteBuffer(this.Allocator, copiedArray, this.MaxCapacity);
|
||||
}
|
||||
|
||||
protected override void Deallocate()
|
||||
{
|
||||
this.array = null;
|
||||
}
|
||||
protected override void Deallocate() => this.array = null;
|
||||
|
||||
public override IByteBuffer Unwrap()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public override IByteBuffer Unwrap() => null;
|
||||
}
|
||||
}
|
|
@ -37,15 +37,9 @@ namespace DotNetty.Buffers
|
|||
|
||||
public ByteOrder Order => this.Buf.Order;
|
||||
|
||||
public virtual IByteBuffer WithOrder(ByteOrder endianness)
|
||||
{
|
||||
return this.Buf.WithOrder(endianness);
|
||||
}
|
||||
public virtual IByteBuffer WithOrder(ByteOrder endianness) => this.Buf.WithOrder(endianness);
|
||||
|
||||
public IByteBuffer Unwrap()
|
||||
{
|
||||
return this.Buf;
|
||||
}
|
||||
public IByteBuffer Unwrap() => this.Buf;
|
||||
|
||||
public int ReaderIndex => this.Buf.ReaderIndex;
|
||||
|
||||
|
@ -75,15 +69,9 @@ namespace DotNetty.Buffers
|
|||
|
||||
public int MaxWritableBytes => this.Buf.MaxWritableBytes;
|
||||
|
||||
public bool IsReadable()
|
||||
{
|
||||
return this.Buf.IsReadable();
|
||||
}
|
||||
public bool IsReadable() => this.Buf.IsReadable();
|
||||
|
||||
public bool IsWritable()
|
||||
{
|
||||
return this.Buf.IsWritable();
|
||||
}
|
||||
public bool IsWritable() => this.Buf.IsWritable();
|
||||
|
||||
public IByteBuffer Clear()
|
||||
{
|
||||
|
@ -133,50 +121,23 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual int EnsureWritable(int minWritableBytes, bool force)
|
||||
{
|
||||
return this.Buf.EnsureWritable(minWritableBytes, force);
|
||||
}
|
||||
public virtual int EnsureWritable(int minWritableBytes, bool force) => this.Buf.EnsureWritable(minWritableBytes, force);
|
||||
|
||||
public virtual bool GetBoolean(int index)
|
||||
{
|
||||
return this.Buf.GetBoolean(index);
|
||||
}
|
||||
public virtual bool GetBoolean(int index) => this.Buf.GetBoolean(index);
|
||||
|
||||
public virtual byte GetByte(int index)
|
||||
{
|
||||
return this.Buf.GetByte(index);
|
||||
}
|
||||
public virtual byte GetByte(int index) => this.Buf.GetByte(index);
|
||||
|
||||
public virtual short GetShort(int index)
|
||||
{
|
||||
return this.Buf.GetShort(index);
|
||||
}
|
||||
public virtual short GetShort(int index) => this.Buf.GetShort(index);
|
||||
|
||||
public virtual ushort GetUnsignedShort(int index)
|
||||
{
|
||||
return this.Buf.GetUnsignedShort(index);
|
||||
}
|
||||
public virtual ushort GetUnsignedShort(int index) => this.Buf.GetUnsignedShort(index);
|
||||
|
||||
public virtual int GetInt(int index)
|
||||
{
|
||||
return this.Buf.GetInt(index);
|
||||
}
|
||||
public virtual int GetInt(int index) => this.Buf.GetInt(index);
|
||||
|
||||
public virtual uint GetUnsignedInt(int index)
|
||||
{
|
||||
return this.Buf.GetUnsignedInt(index);
|
||||
}
|
||||
public virtual uint GetUnsignedInt(int index) => this.Buf.GetUnsignedInt(index);
|
||||
|
||||
public virtual long GetLong(int index)
|
||||
{
|
||||
return this.Buf.GetLong(index);
|
||||
}
|
||||
public virtual long GetLong(int index) => this.Buf.GetLong(index);
|
||||
|
||||
public virtual char GetChar(int index)
|
||||
{
|
||||
return this.Buf.GetChar(index);
|
||||
}
|
||||
public virtual char GetChar(int index) => this.Buf.GetChar(index);
|
||||
|
||||
// todo: port: complete
|
||||
//public virtual float GetFloat(int index)
|
||||
|
@ -184,10 +145,7 @@ namespace DotNetty.Buffers
|
|||
// return this.buf.GetFloat(index);
|
||||
//}
|
||||
|
||||
public virtual double GetDouble(int index)
|
||||
{
|
||||
return this.Buf.GetDouble(index);
|
||||
}
|
||||
public virtual double GetDouble(int index) => this.Buf.GetDouble(index);
|
||||
|
||||
public virtual IByteBuffer GetBytes(int index, IByteBuffer dst)
|
||||
{
|
||||
|
@ -243,10 +201,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual IByteBuffer SetUnsignedShort(int index, ushort value)
|
||||
{
|
||||
return this.Buf.SetUnsignedShort(index, value);
|
||||
}
|
||||
public virtual IByteBuffer SetUnsignedShort(int index, ushort value) => this.Buf.SetUnsignedShort(index, value);
|
||||
|
||||
public virtual IByteBuffer SetInt(int index, int value)
|
||||
{
|
||||
|
@ -254,10 +209,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual IByteBuffer SetUnsignedInt(int index, uint value)
|
||||
{
|
||||
return this.Buf.SetUnsignedInt(index, value);
|
||||
}
|
||||
public virtual IByteBuffer SetUnsignedInt(int index, uint value) => this.Buf.SetUnsignedInt(index, value);
|
||||
|
||||
public virtual IByteBuffer SetLong(int index, long value)
|
||||
{
|
||||
|
@ -314,10 +266,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
return this.Buf.SetBytesAsync(index, src, length, cancellationToken);
|
||||
}
|
||||
public virtual Task<int> SetBytesAsync(int index, Stream src, int length, CancellationToken cancellationToken) => this.Buf.SetBytesAsync(index, src, length, cancellationToken);
|
||||
|
||||
// todo: port: complete
|
||||
//public virtual IByteBuffer SetZero(int index, int length)
|
||||
|
@ -326,45 +275,21 @@ namespace DotNetty.Buffers
|
|||
// return this;
|
||||
//}
|
||||
|
||||
public virtual bool ReadBoolean()
|
||||
{
|
||||
return this.Buf.ReadBoolean();
|
||||
}
|
||||
public virtual bool ReadBoolean() => this.Buf.ReadBoolean();
|
||||
|
||||
public virtual byte ReadByte()
|
||||
{
|
||||
return this.Buf.ReadByte();
|
||||
}
|
||||
public virtual byte ReadByte() => this.Buf.ReadByte();
|
||||
|
||||
public virtual short ReadShort()
|
||||
{
|
||||
return this.Buf.ReadShort();
|
||||
}
|
||||
public virtual short ReadShort() => this.Buf.ReadShort();
|
||||
|
||||
public virtual ushort ReadUnsignedShort()
|
||||
{
|
||||
return this.Buf.ReadUnsignedShort();
|
||||
}
|
||||
public virtual ushort ReadUnsignedShort() => this.Buf.ReadUnsignedShort();
|
||||
|
||||
public virtual int ReadInt()
|
||||
{
|
||||
return this.Buf.ReadInt();
|
||||
}
|
||||
public virtual int ReadInt() => this.Buf.ReadInt();
|
||||
|
||||
public virtual uint ReadUnsignedInt()
|
||||
{
|
||||
return this.Buf.ReadUnsignedInt();
|
||||
}
|
||||
public virtual uint ReadUnsignedInt() => this.Buf.ReadUnsignedInt();
|
||||
|
||||
public virtual long ReadLong()
|
||||
{
|
||||
return this.Buf.ReadLong();
|
||||
}
|
||||
public virtual long ReadLong() => this.Buf.ReadLong();
|
||||
|
||||
public virtual char ReadChar()
|
||||
{
|
||||
return this.Buf.ReadChar();
|
||||
}
|
||||
public virtual char ReadChar() => this.Buf.ReadChar();
|
||||
|
||||
// todo: port: complete
|
||||
//public virtual float ReadFloat()
|
||||
|
@ -372,25 +297,13 @@ namespace DotNetty.Buffers
|
|||
// return buf.ReadFloat();
|
||||
//}
|
||||
|
||||
public virtual double ReadDouble()
|
||||
{
|
||||
return this.Buf.ReadDouble();
|
||||
}
|
||||
public virtual double ReadDouble() => this.Buf.ReadDouble();
|
||||
|
||||
public virtual IByteBuffer ReadBytes(int length)
|
||||
{
|
||||
return this.Buf.ReadBytes(length);
|
||||
}
|
||||
public virtual IByteBuffer ReadBytes(int length) => this.Buf.ReadBytes(length);
|
||||
|
||||
public virtual IByteBuffer ReadSlice(int length)
|
||||
{
|
||||
return this.Buf.ReadSlice(length);
|
||||
}
|
||||
public virtual IByteBuffer ReadSlice(int length) => this.Buf.ReadSlice(length);
|
||||
|
||||
public virtual Task WriteBytesAsync(Stream stream, int length)
|
||||
{
|
||||
return this.Buf.WriteBytesAsync(stream, length);
|
||||
}
|
||||
public virtual Task WriteBytesAsync(Stream stream, int length) => this.Buf.WriteBytesAsync(stream, length);
|
||||
|
||||
public virtual IByteBuffer ReadBytes(IByteBuffer dst)
|
||||
{
|
||||
|
@ -452,10 +365,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual IByteBuffer WriteUnsignedShort(ushort value)
|
||||
{
|
||||
return this.Buf.WriteUnsignedShort(value);
|
||||
}
|
||||
public virtual IByteBuffer WriteUnsignedShort(ushort value) => this.Buf.WriteUnsignedShort(value);
|
||||
|
||||
public virtual IByteBuffer WriteInt(int value)
|
||||
{
|
||||
|
@ -463,10 +373,7 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public virtual IByteBuffer WriteUnsignedInt(uint value)
|
||||
{
|
||||
return this.Buf.WriteUnsignedInt(value);
|
||||
}
|
||||
public virtual IByteBuffer WriteUnsignedInt(uint value) => this.Buf.WriteUnsignedInt(value);
|
||||
|
||||
public virtual IByteBuffer WriteLong(long value)
|
||||
{
|
||||
|
@ -533,10 +440,7 @@ namespace DotNetty.Buffers
|
|||
|
||||
public ArraySegment<byte>[] GetIoBuffers(int index, int length) => this.Buf.GetIoBuffers(index, length);
|
||||
|
||||
public virtual Task WriteBytesAsync(Stream input, int length, CancellationToken cancellationToken)
|
||||
{
|
||||
return this.Buf.WriteBytesAsync(input, length, cancellationToken);
|
||||
}
|
||||
public virtual Task WriteBytesAsync(Stream input, int length, CancellationToken cancellationToken) => this.Buf.WriteBytesAsync(input, length, cancellationToken);
|
||||
|
||||
// todo: port: complete
|
||||
//public virtual IByteBuffer WriteZero(int length)
|
||||
|
@ -565,35 +469,17 @@ namespace DotNetty.Buffers
|
|||
// return this.buf.BytesBefore(index, length, value);
|
||||
//}
|
||||
|
||||
public virtual IByteBuffer Copy()
|
||||
{
|
||||
return this.Buf.Copy();
|
||||
}
|
||||
public virtual IByteBuffer Copy() => this.Buf.Copy();
|
||||
|
||||
public virtual IByteBuffer Copy(int index, int length)
|
||||
{
|
||||
return this.Buf.Copy(index, length);
|
||||
}
|
||||
public virtual IByteBuffer Copy(int index, int length) => this.Buf.Copy(index, length);
|
||||
|
||||
public virtual IByteBuffer Slice()
|
||||
{
|
||||
return this.Buf.Slice();
|
||||
}
|
||||
public virtual IByteBuffer Slice() => this.Buf.Slice();
|
||||
|
||||
public virtual IByteBuffer Slice(int index, int length)
|
||||
{
|
||||
return this.Buf.Slice(index, length);
|
||||
}
|
||||
public virtual IByteBuffer Slice(int index, int length) => this.Buf.Slice(index, length);
|
||||
|
||||
public virtual byte[] ToArray()
|
||||
{
|
||||
return this.Buf.ToArray();
|
||||
}
|
||||
public virtual byte[] ToArray() => this.Buf.ToArray();
|
||||
|
||||
public virtual IByteBuffer Duplicate()
|
||||
{
|
||||
return this.Buf.Duplicate();
|
||||
}
|
||||
public virtual IByteBuffer Duplicate() => this.Buf.Duplicate();
|
||||
|
||||
public virtual bool HasArray => this.Buf.HasArray;
|
||||
|
||||
|
@ -601,30 +487,15 @@ namespace DotNetty.Buffers
|
|||
|
||||
public virtual int ArrayOffset => this.Buf.ArrayOffset;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Buf.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => this.Buf.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this.Buf.Equals(obj);
|
||||
}
|
||||
public override bool Equals(object obj) => this.Buf.Equals(obj);
|
||||
|
||||
public bool Equals(IByteBuffer buffer)
|
||||
{
|
||||
return this.Buf.Equals(buffer);
|
||||
}
|
||||
public bool Equals(IByteBuffer buffer) => this.Buf.Equals(buffer);
|
||||
|
||||
public virtual int CompareTo(IByteBuffer buffer)
|
||||
{
|
||||
return this.Buf.CompareTo(buffer);
|
||||
}
|
||||
public virtual int CompareTo(IByteBuffer buffer) => this.Buf.CompareTo(buffer);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.GetType().Name + '(' + this.Buf + ')';
|
||||
}
|
||||
public override string ToString() => this.GetType().Name + '(' + this.Buf + ')';
|
||||
|
||||
public virtual IReferenceCounted Retain(int increment)
|
||||
{
|
||||
|
@ -650,56 +521,26 @@ namespace DotNetty.Buffers
|
|||
return this;
|
||||
}
|
||||
|
||||
public bool IsReadable(int size)
|
||||
{
|
||||
return this.Buf.IsReadable(size);
|
||||
}
|
||||
public bool IsReadable(int size) => this.Buf.IsReadable(size);
|
||||
|
||||
public bool IsWritable(int size)
|
||||
{
|
||||
return this.Buf.IsWritable(size);
|
||||
}
|
||||
public bool IsWritable(int size) => this.Buf.IsWritable(size);
|
||||
|
||||
public int ReferenceCount => this.Buf.ReferenceCount;
|
||||
|
||||
public virtual bool Release()
|
||||
{
|
||||
return this.Buf.Release();
|
||||
}
|
||||
public virtual bool Release() => this.Buf.Release();
|
||||
|
||||
public virtual bool Release(int decrement)
|
||||
{
|
||||
return this.Buf.Release(decrement);
|
||||
}
|
||||
public virtual bool Release(int decrement) => this.Buf.Release(decrement);
|
||||
|
||||
public int ForEachByte(ByteProcessor processor)
|
||||
{
|
||||
return this.Buf.ForEachByte(processor);
|
||||
}
|
||||
public int ForEachByte(ByteProcessor processor) => this.Buf.ForEachByte(processor);
|
||||
|
||||
public int ForEachByte(int index, int length, ByteProcessor processor)
|
||||
{
|
||||
return this.Buf.ForEachByte(index, length, processor);
|
||||
}
|
||||
public int ForEachByte(int index, int length, ByteProcessor processor) => this.Buf.ForEachByte(index, length, processor);
|
||||
|
||||
public int ForEachByteDesc(ByteProcessor processor)
|
||||
{
|
||||
return this.Buf.ForEachByteDesc(processor);
|
||||
}
|
||||
public int ForEachByteDesc(ByteProcessor processor) => this.Buf.ForEachByteDesc(processor);
|
||||
|
||||
public int ForEachByteDesc(int index, int length, ByteProcessor processor)
|
||||
{
|
||||
return this.Buf.ForEachByteDesc(processor);
|
||||
}
|
||||
public int ForEachByteDesc(int index, int length, ByteProcessor processor) => this.Buf.ForEachByteDesc(processor);
|
||||
|
||||
public virtual string ToString(Encoding encoding)
|
||||
{
|
||||
return this.Buf.ToString(encoding);
|
||||
}
|
||||
public virtual string ToString(Encoding encoding) => this.Buf.ToString(encoding);
|
||||
|
||||
public virtual string ToString(int index, int length, Encoding encoding)
|
||||
{
|
||||
return this.Buf.ToString(index, length, encoding);
|
||||
}
|
||||
public virtual string ToString(int index, int length, Encoding encoding) => this.Buf.ToString(index, length, encoding);
|
||||
}
|
||||
}
|
|
@ -438,15 +438,9 @@ namespace DotNetty.Codecs.Mqtt
|
|||
return buffer.ReadUnsignedShort();
|
||||
}
|
||||
|
||||
static string DecodeString(IByteBuffer buffer, ref int remainingLength)
|
||||
{
|
||||
return DecodeString(buffer, ref remainingLength, 0, int.MaxValue);
|
||||
}
|
||||
static string DecodeString(IByteBuffer buffer, ref int remainingLength) => DecodeString(buffer, ref remainingLength, 0, int.MaxValue);
|
||||
|
||||
static string DecodeString(IByteBuffer buffer, ref int remainingLength, int minBytes)
|
||||
{
|
||||
return DecodeString(buffer, ref remainingLength, minBytes, int.MaxValue);
|
||||
}
|
||||
static string DecodeString(IByteBuffer buffer, ref int remainingLength, int minBytes) => DecodeString(buffer, ref remainingLength, minBytes, int.MaxValue);
|
||||
|
||||
static string DecodeString(IByteBuffer buffer, ref int remainingLength, int minBytes, int maxBytes)
|
||||
{
|
||||
|
|
|
@ -18,10 +18,7 @@ namespace DotNetty.Codecs.Mqtt
|
|||
const int StringSizeLength = 2;
|
||||
const int MaxVariableLength = 4;
|
||||
|
||||
protected override void Encode(IChannelHandlerContext context, Packet message, List<object> output)
|
||||
{
|
||||
DoEncode(context.Allocator, message, output);
|
||||
}
|
||||
protected override void Encode(IChannelHandlerContext context, Packet message, List<object> output) => DoEncode(context.Allocator, message, output);
|
||||
|
||||
public override bool IsSharable => true;
|
||||
|
||||
|
|
|
@ -57,15 +57,9 @@ namespace DotNetty.Codecs.Mqtt.Packets
|
|||
return this;
|
||||
}
|
||||
|
||||
public bool Release()
|
||||
{
|
||||
return this.Payload.Release();
|
||||
}
|
||||
public bool Release() => this.Payload.Release();
|
||||
|
||||
public bool Release(int decrement)
|
||||
{
|
||||
return this.Payload.Release(decrement);
|
||||
}
|
||||
public bool Release(int decrement) => this.Payload.Release(decrement);
|
||||
|
||||
IByteBuffer IByteBufferHolder.Content => this.Payload;
|
||||
|
||||
|
|
|
@ -356,9 +356,6 @@ namespace DotNetty.Codecs
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual void DecodeLast(IChannelHandlerContext context, IByteBuffer input, List<object> output)
|
||||
{
|
||||
this.Decode(context, input, output);
|
||||
}
|
||||
protected virtual void DecodeLast(IChannelHandlerContext context, IByteBuffer input, List<object> output) => this.Decode(context, input, output);
|
||||
}
|
||||
}
|
|
@ -1,80 +1,86 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotNetty.Buffers;
|
||||
using DotNetty.Transport.Channels;
|
||||
|
||||
namespace DotNetty.Codecs
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotNetty.Buffers;
|
||||
using DotNetty.Transport.Channels;
|
||||
|
||||
/// <summary>
|
||||
/// A decoder that splits the received <see cref="DotNetty.Buffers.IByteBuffer"/> by one or more
|
||||
/// delimiters.It is particularly useful for decoding the frames which ends
|
||||
/// with a delimiter such as <see cref = "DotNetty.Codecs.Delimiters.NullDelimiter" /> or
|
||||
/// <see cref = "DotNetty.Codecs.Delimiters.LineDelimiter" />
|
||||
/// --- Specifying more than one delimiter </ h3 >
|
||||
/// <see cref = "DotNetty.Codecs.Delimiters.NullDelimiter" /> allows you to specify more than one
|
||||
/// delimiter. If more than one delimiter is found in the buffer, it chooses
|
||||
/// the delimiter which produces the shortest frame. For example, if you have
|
||||
/// the following data in the buffer:
|
||||
/// +--------------+
|
||||
/// | ABC\nDEF\r\n |
|
||||
/// +--------------+
|
||||
/// a <see cref = "DotNetty.Codecs.Delimiters.LineDelimiter" /> will choose '\n' as the first delimiter and produce two frames:
|
||||
/// +-----+-----+
|
||||
/// | ABC | DEF |
|
||||
/// +-----+-----+
|
||||
/// rather than incorrectly choosing '\r\n' as the first delimiter:
|
||||
/// +----------+
|
||||
/// | ABC\nDEF |
|
||||
/// +----------+
|
||||
/// A decoder that splits the received <see cref="DotNetty.Buffers.IByteBuffer" /> by one or more
|
||||
/// delimiters.It is particularly useful for decoding the frames which ends
|
||||
/// with a delimiter such as <see cref="DotNetty.Codecs.Delimiters.NullDelimiter" /> or
|
||||
/// <see cref="DotNetty.Codecs.Delimiters.LineDelimiter" />
|
||||
/// <h3>Specifying more than one delimiter </h3>
|
||||
/// <see cref="DotNetty.Codecs.Delimiters.NullDelimiter" /> allows you to specify more than one
|
||||
/// delimiter. If more than one delimiter is found in the buffer, it chooses
|
||||
/// the delimiter which produces the shortest frame. For example, if you have
|
||||
/// the following data in the buffer:
|
||||
/// +--------------+
|
||||
/// | ABC\nDEF\r\n |
|
||||
/// +--------------+
|
||||
/// a <see cref="DotNetty.Codecs.Delimiters.LineDelimiter" /> will choose '\n' as the first delimiter and produce two
|
||||
/// frames:
|
||||
/// +-----+-----+
|
||||
/// | ABC | DEF |
|
||||
/// +-----+-----+
|
||||
/// rather than incorrectly choosing '\r\n' as the first delimiter:
|
||||
/// +----------+
|
||||
/// | ABC\nDEF |
|
||||
/// +----------+
|
||||
/// </summary>
|
||||
public class DelimiterBasedFrameDecoder : ByteToMessageDecoder
|
||||
{
|
||||
IByteBuffer[] delimiters;
|
||||
int maxFrameLength;
|
||||
bool stripDelimiter;
|
||||
bool failFast;
|
||||
readonly IByteBuffer[] delimiters;
|
||||
readonly int maxFrameLength;
|
||||
readonly bool stripDelimiter;
|
||||
readonly bool failFast;
|
||||
bool discardingTooLongFrame;
|
||||
int tooLongFrameLength;
|
||||
LineBasedFrameDecoder lineBasedDecoder; // Set only when decoding with "\n" and "\r\n" as the delimiter.
|
||||
readonly LineBasedFrameDecoder lineBasedDecoder; // Set only when decoding with "\n" and "\r\n" as the delimiter.
|
||||
|
||||
/// <summary>Common constructor</summary>
|
||||
/// <param name="maxFrameLength">The maximum length of the decoded frame
|
||||
/// NOTE: A see <cref="DotNetty.Codecs.TooLongFrameException" /> is thrown if the length of the frame exceeds this value.</param>
|
||||
/// <param name="maxFrameLength">
|
||||
/// The maximum length of the decoded frame
|
||||
/// NOTE: A see <see cref="DotNetty.Codecs.TooLongFrameException" /> is thrown if the length of the frame exceeds this
|
||||
/// value.
|
||||
/// </param>
|
||||
/// <param name="stripDelimiter">whether the decoded frame should strip out the delimiter or not</param>
|
||||
/// <param name="failFast">If true, a <cref="DotNetty.Codecs.TooLongFrameException" /> is
|
||||
/// thrown as soon as the decoder notices the length of the
|
||||
/// frame will exceed<tt>maxFrameLength</tt> regardless of
|
||||
/// whether the entire frame has been read.
|
||||
/// If false, a <cref="DotNetty.Codecs.TooLongFrameException" /> is
|
||||
/// thrown after the entire frame that exceeds maxFrameLength has been read.</param>
|
||||
/// <param name="delimiter">the delimiter</param>
|
||||
/// <param name="failFast">
|
||||
/// If true, a <see cref="DotNetty.Codecs.TooLongFrameException" /> is
|
||||
/// thrown as soon as the decoder notices the length of the
|
||||
/// frame will exceed<tt>maxFrameLength</tt> regardless of
|
||||
/// whether the entire frame has been read.
|
||||
/// If false, a <see cref="DotNetty.Codecs.TooLongFrameException" /> is
|
||||
/// thrown after the entire frame that exceeds maxFrameLength has been read.
|
||||
/// </param>
|
||||
/// <param name="delimiters">delimiters</param>
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, bool stripDelimiter, bool failFast, params IByteBuffer[] delimiters)
|
||||
{
|
||||
ValidateMaxFrameLength(maxFrameLength);
|
||||
if(delimiters == null)
|
||||
if (delimiters == null)
|
||||
throw new NullReferenceException("delimiters");
|
||||
|
||||
if(delimiters.Length == 0)
|
||||
if (delimiters.Length == 0)
|
||||
throw new ArgumentException("empty delimiters");
|
||||
|
||||
if(IsLineBased(delimiters) && !IsSubclass())
|
||||
if (IsLineBased(delimiters) && !this.IsSubclass())
|
||||
{
|
||||
lineBasedDecoder = new LineBasedFrameDecoder(maxFrameLength, stripDelimiter, failFast);
|
||||
this.lineBasedDecoder = new LineBasedFrameDecoder(maxFrameLength, stripDelimiter, failFast);
|
||||
this.delimiters = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.delimiters = new IByteBuffer[delimiters.Length];
|
||||
for(int i = 0; i < delimiters.Length; i++)
|
||||
for (int i = 0; i < delimiters.Length; i++)
|
||||
{
|
||||
IByteBuffer d = delimiters[i];
|
||||
ValidateDelimiter(d);
|
||||
this.delimiters[i] = d.Slice(d.ReaderIndex, d.ReadableBytes);
|
||||
}
|
||||
lineBasedDecoder = null;
|
||||
this.lineBasedDecoder = null;
|
||||
}
|
||||
this.maxFrameLength = maxFrameLength;
|
||||
this.stripDelimiter = stripDelimiter;
|
||||
|
@ -82,22 +88,22 @@ namespace DotNetty.Codecs
|
|||
}
|
||||
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, IByteBuffer delimiter)
|
||||
: this(maxFrameLength, true, true, new IByteBuffer[] { delimiter })
|
||||
: this(maxFrameLength, true, true, new[] { delimiter })
|
||||
{
|
||||
}
|
||||
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, bool stripDelimiter, IByteBuffer delimiter)
|
||||
: this(maxFrameLength, stripDelimiter, true, new IByteBuffer[] { delimiter })
|
||||
: this(maxFrameLength, stripDelimiter, true, new[] { delimiter })
|
||||
{
|
||||
}
|
||||
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, bool stripDelimiter, bool failFast, IByteBuffer delimiter)
|
||||
: this(maxFrameLength, true, failFast, new IByteBuffer[] { delimiter })
|
||||
: this(maxFrameLength, stripDelimiter, failFast, new[] { delimiter })
|
||||
{
|
||||
}
|
||||
|
||||
public DelimiterBasedFrameDecoder(int maxFrameLength, params IByteBuffer[] delimiters)
|
||||
: this(maxFrameLength, true, true, delimiters )
|
||||
: this(maxFrameLength, true, true, delimiters)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -110,9 +116,9 @@ namespace DotNetty.Codecs
|
|||
static bool IsLineBased(IByteBuffer[] delimiters)
|
||||
{
|
||||
if (delimiters.Length != 2)
|
||||
{
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
IByteBuffer a = delimiters[0];
|
||||
IByteBuffer b = delimiters[1];
|
||||
|
@ -124,35 +130,37 @@ namespace DotNetty.Codecs
|
|||
return a.Capacity == 2 && b.Capacity == 1 && a.GetByte(0) == '\r' && a.GetByte(1) == '\n' && b.GetByte(0) == '\n';
|
||||
}
|
||||
|
||||
|
||||
/// <summary>ReturnsReturn true if the current instance is a subclass of DelimiterBasedFrameDecoder</summary>
|
||||
bool IsSubclass()
|
||||
{
|
||||
return (this is DelimiterBasedFrameDecoder);
|
||||
}
|
||||
bool IsSubclass() => this.GetType() != typeof(DelimiterBasedFrameDecoder);
|
||||
|
||||
override protected internal void Decode(IChannelHandlerContext ctx, IByteBuffer input, List<object> output)
|
||||
protected internal override void Decode(IChannelHandlerContext ctx, IByteBuffer input, List<object> output)
|
||||
{
|
||||
var decoded = Decode(ctx, input);
|
||||
object decoded = this.Decode(ctx, input);
|
||||
if (decoded != null)
|
||||
output.Add(decoded);
|
||||
}
|
||||
|
||||
/// <summary>Create a frame out of the <see cref="DotNetty.Buffers.IByteBuffer"/> and return it</summary>
|
||||
/// <param name="ctx">the <see cref="DotNetty.Transport.Channels.IChannelHandlerContext" /> which this <see cref="DotNetty.Codecs.ByteToMessageDecoder"/> belongs to</param>
|
||||
/// <summary>Create a frame out of the <see cref="DotNetty.Buffers.IByteBuffer" /> and return it</summary>
|
||||
/// <param name="ctx">
|
||||
/// the <see cref="DotNetty.Transport.Channels.IChannelHandlerContext" /> which this
|
||||
/// <see cref="DotNetty.Codecs.ByteToMessageDecoder" /> belongs to
|
||||
/// </param>
|
||||
/// <param name="buffer">the <see cref="DotNetty.Buffers.IByteBuffer" /> from which to read data</param>
|
||||
/// <returns>the <see cref="DotNetty.Buffers.IByteBuffer" /> which represent the frame or null if no frame could be created.</returns>
|
||||
/// <returns>
|
||||
/// the <see cref="DotNetty.Buffers.IByteBuffer" /> which represent the frame or null if no frame could be
|
||||
/// created.
|
||||
/// </returns>
|
||||
protected object Decode(IChannelHandlerContext ctx, IByteBuffer buffer)
|
||||
{
|
||||
if (lineBasedDecoder != null)
|
||||
{
|
||||
return lineBasedDecoder.Decode(ctx, buffer);
|
||||
}
|
||||
if (this.lineBasedDecoder != null)
|
||||
{
|
||||
return this.lineBasedDecoder.Decode(ctx, buffer);
|
||||
}
|
||||
|
||||
// Try all delimiters and choose the delimiter which yields the shortest frame.
|
||||
int minFrameLength = int.MaxValue;
|
||||
IByteBuffer minDelim = null;
|
||||
foreach (IByteBuffer delim in delimiters)
|
||||
foreach (IByteBuffer delim in this.delimiters)
|
||||
{
|
||||
int frameLength = IndexOf(buffer, delim);
|
||||
if (frameLength >= 0 && frameLength < minFrameLength)
|
||||
|
@ -167,18 +175,18 @@ namespace DotNetty.Codecs
|
|||
int minDelimLength = minDelim.Capacity;
|
||||
IByteBuffer frame;
|
||||
|
||||
if (discardingTooLongFrame)
|
||||
if (this.discardingTooLongFrame)
|
||||
{
|
||||
// We've just finished discarding a very large frame.
|
||||
// Go back to the initial state.
|
||||
discardingTooLongFrame = false;
|
||||
this.discardingTooLongFrame = false;
|
||||
buffer.SkipBytes(minFrameLength + minDelimLength);
|
||||
|
||||
int tooLongFrameLength = this.tooLongFrameLength;
|
||||
this.tooLongFrameLength = 0;
|
||||
if (!failFast)
|
||||
if (!this.failFast)
|
||||
{
|
||||
Fail(tooLongFrameLength);
|
||||
this.Fail(tooLongFrameLength);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -187,11 +195,11 @@ namespace DotNetty.Codecs
|
|||
{
|
||||
// Discard read frame.
|
||||
buffer.SkipBytes(minFrameLength + minDelimLength);
|
||||
Fail(minFrameLength);
|
||||
this.Fail(minFrameLength);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (stripDelimiter)
|
||||
if (this.stripDelimiter)
|
||||
{
|
||||
frame = buffer.ReadSlice(minFrameLength);
|
||||
buffer.SkipBytes(minDelimLength);
|
||||
|
@ -205,24 +213,24 @@ namespace DotNetty.Codecs
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!discardingTooLongFrame)
|
||||
if (!this.discardingTooLongFrame)
|
||||
{
|
||||
if (buffer.ReadableBytes > maxFrameLength)
|
||||
if (buffer.ReadableBytes > this.maxFrameLength)
|
||||
{
|
||||
// Discard the content of the buffer until a delimiter is found.
|
||||
tooLongFrameLength = buffer.ReadableBytes;
|
||||
this.tooLongFrameLength = buffer.ReadableBytes;
|
||||
buffer.SkipBytes(buffer.ReadableBytes);
|
||||
discardingTooLongFrame = true;
|
||||
if (failFast)
|
||||
this.discardingTooLongFrame = true;
|
||||
if (this.failFast)
|
||||
{
|
||||
Fail(tooLongFrameLength);
|
||||
this.Fail(this.tooLongFrameLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Still discarding the buffer since a delimiter is not found.
|
||||
tooLongFrameLength += buffer.ReadableBytes;
|
||||
this.tooLongFrameLength += buffer.ReadableBytes;
|
||||
buffer.SkipBytes(buffer.ReadableBytes);
|
||||
}
|
||||
return null;
|
||||
|
@ -232,9 +240,9 @@ namespace DotNetty.Codecs
|
|||
void Fail(long frameLength)
|
||||
{
|
||||
if (frameLength > 0)
|
||||
throw new TooLongFrameException("frame length exceeds " + maxFrameLength +": " + frameLength + " - discarded");
|
||||
throw new TooLongFrameException("frame length exceeds " + this.maxFrameLength + ": " + frameLength + " - discarded");
|
||||
else
|
||||
throw new TooLongFrameException("frame length exceeds " + maxFrameLength +" - discarding");
|
||||
throw new TooLongFrameException("frame length exceeds " + this.maxFrameLength + " - discarding");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,6 +250,7 @@ namespace DotNetty.Codecs
|
|||
* the first needle found in the haystack. -1 is returned if no needle is
|
||||
* found in the haystack.
|
||||
*/
|
||||
|
||||
static int IndexOf(IByteBuffer haystack, IByteBuffer needle)
|
||||
{
|
||||
for (int i = haystack.ReaderIndex; i < haystack.WriterIndex; i++)
|
||||
|
@ -288,4 +297,4 @@ namespace DotNetty.Codecs
|
|||
throw new ArgumentException("maxFrameLength must be a positive integer: " + maxFrameLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +1,31 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using DotNetty.Buffers;
|
||||
|
||||
namespace DotNetty.Codecs
|
||||
{
|
||||
using DotNetty.Buffers;
|
||||
|
||||
public class Delimiters
|
||||
{
|
||||
/// <summary>Returns a null (0x00) delimiter, which could be used for Flash XML socket or any similar protocols</summary>
|
||||
public static IByteBuffer[] NullDelimiter()
|
||||
{
|
||||
return new IByteBuffer[] { Unpooled.WrappedBuffer(new byte[] { 0 }) };
|
||||
}
|
||||
public static IByteBuffer[] NullDelimiter() => new[] { Unpooled.WrappedBuffer(new byte[] { 0 }) };
|
||||
|
||||
/// <summary>Returns {@code CR ('\r')} and {@code LF ('\n')} delimiters, which could
|
||||
/// be used for text-based line protocols.</summary>
|
||||
/// <summary>
|
||||
/// Returns {@code CR ('\r')} and {@code LF ('\n')} delimiters, which could
|
||||
/// be used for text-based line protocols.
|
||||
/// </summary>
|
||||
public static IByteBuffer[] LineDelimiter()
|
||||
{
|
||||
return new IByteBuffer[]
|
||||
{
|
||||
Unpooled.WrappedBuffer(new byte[] { (byte)'\r', (byte)'\n' }),
|
||||
Unpooled.WrappedBuffer(new byte[] { (byte)'\n' }),
|
||||
};
|
||||
return new[]
|
||||
{
|
||||
Unpooled.WrappedBuffer(new[] { (byte)'\r', (byte)'\n' }),
|
||||
Unpooled.WrappedBuffer(new[] { (byte)'\n' }),
|
||||
};
|
||||
}
|
||||
|
||||
private Delimiters()
|
||||
Delimiters()
|
||||
{
|
||||
// Unused
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,28 +11,28 @@ namespace DotNetty.Codecs
|
|||
/// <summary>
|
||||
/// An encoder that prepends the length of the message. The length value is
|
||||
/// prepended as a binary form.
|
||||
/// <p>
|
||||
/// For example, <tt>{@link LengthFieldPrepender}(2)</tt> will encode the
|
||||
/// following 12-bytes string:
|
||||
/// <pre>
|
||||
/// +----------------+
|
||||
/// | "HELLO, WORLD" |
|
||||
/// +----------------+
|
||||
/// </pre>
|
||||
/// into the following:
|
||||
/// <pre>
|
||||
/// +--------+----------------+
|
||||
/// + 0x000C | "HELLO, WORLD" |
|
||||
/// +--------+----------------+
|
||||
/// </pre>
|
||||
/// If you turned on the {@code lengthIncludesLengthFieldLength} flag in the
|
||||
/// constructor, the encoded data would look like the following
|
||||
/// (12 (original data) + 2 (prepended data) = 14 (0xE)):
|
||||
/// <pre>
|
||||
/// +--------+----------------+
|
||||
/// + 0x000E | "HELLO, WORLD" |
|
||||
/// +--------+----------------+
|
||||
/// </pre>
|
||||
/// <p />
|
||||
/// For example, <tt>{@link LengthFieldPrepender}(2)</tt> will encode the
|
||||
/// following 12-bytes string:
|
||||
/// <pre>
|
||||
/// +----------------+
|
||||
/// | "HELLO, WORLD" |
|
||||
/// +----------------+
|
||||
/// </pre>
|
||||
/// into the following:
|
||||
/// <pre>
|
||||
/// +--------+----------------+
|
||||
/// + 0x000C | "HELLO, WORLD" |
|
||||
/// +--------+----------------+
|
||||
/// </pre>
|
||||
/// If you turned on the {@code lengthIncludesLengthFieldLength} flag in the
|
||||
/// constructor, the encoded data would look like the following
|
||||
/// (12 (original data) + 2 (prepended data) = 14 (0xE)):
|
||||
/// <pre>
|
||||
/// +--------+----------------+
|
||||
/// + 0x000E | "HELLO, WORLD" |
|
||||
/// +--------+----------------+
|
||||
/// </pre>
|
||||
/// </summary>
|
||||
public class LengthFieldPrepender : MessageToMessageEncoder<IByteBuffer>
|
||||
{
|
||||
|
|
|
@ -149,10 +149,7 @@ namespace DotNetty.Codecs
|
|||
}
|
||||
}
|
||||
|
||||
void Fail(IChannelHandlerContext ctx, int length)
|
||||
{
|
||||
this.Fail(ctx, length.ToString());
|
||||
}
|
||||
void Fail(IChannelHandlerContext ctx, int length) => this.Fail(ctx, length.ToString());
|
||||
|
||||
void Fail(IChannelHandlerContext ctx, string length)
|
||||
{
|
||||
|
|
|
@ -14,10 +14,7 @@ namespace DotNetty.Codecs
|
|||
/// </summary>
|
||||
public abstract class MessageToMessageDecoder<T> : ChannelHandlerAdapter
|
||||
{
|
||||
public virtual bool AcceptInboundMessage(object msg)
|
||||
{
|
||||
return msg is T;
|
||||
}
|
||||
public virtual bool AcceptInboundMessage(object msg) => msg is T;
|
||||
|
||||
public override void ChannelRead(IChannelHandlerContext context, object message)
|
||||
{
|
||||
|
|
|
@ -16,10 +16,7 @@ namespace DotNetty.Codecs
|
|||
/// Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
|
||||
/// {@link ChannelHandler} in the {@link ChannelPipeline}.
|
||||
/// </summary>
|
||||
public bool AcceptOutboundMessage(object msg)
|
||||
{
|
||||
return msg is T;
|
||||
}
|
||||
public bool AcceptOutboundMessage(object msg) => msg is T;
|
||||
|
||||
public override Task WriteAsync(IChannelHandlerContext ctx, object msg)
|
||||
{
|
||||
|
|
|
@ -68,9 +68,6 @@ namespace DotNetty.Codecs
|
|||
output.Add(decoded);
|
||||
}
|
||||
|
||||
protected string Decode(IChannelHandlerContext context, IByteBuffer input)
|
||||
{
|
||||
return input.ToString(this.encoding);
|
||||
}
|
||||
protected string Decode(IChannelHandlerContext context, IByteBuffer input) => input.ToString(this.encoding);
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ namespace DotNetty.Codecs
|
|||
readonly Encoding encoding;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DotNetty.Codecs.StringEncoder" /> class with the current system
|
||||
/// Initializes a new instance of the <see cref="StringEncoder" /> class with the current system
|
||||
/// character set.
|
||||
/// </summary>
|
||||
public StringEncoder()
|
||||
|
@ -45,7 +45,7 @@ namespace DotNetty.Codecs
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DotNetty.Codecs.StringEncoder" /> class with the specified character
|
||||
/// Initializes a new instance of the <see cref="StringEncoder" /> class with the specified character
|
||||
/// set..
|
||||
/// </summary>
|
||||
/// <param name="encoding">Encoding.</param>
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace DotNetty.Codecs
|
|||
public UnsupportedMessageTypeException(
|
||||
object message, params Type[] expectedTypes)
|
||||
: base(ComposeMessage(
|
||||
message == null ? "null" : message.GetType().Name, expectedTypes))
|
||||
message?.GetType().Name ?? "null", expectedTypes))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -30,27 +30,13 @@ namespace DotNetty.Common.Concurrency
|
|||
|
||||
public abstract bool IsInEventLoop(Thread thread);
|
||||
|
||||
public virtual IEventExecutor Unwrap()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract void Execute(IRunnable task);
|
||||
|
||||
public void Execute(Action<object> action, object state)
|
||||
{
|
||||
this.Execute(new StateActionTaskQueueNode(action, state));
|
||||
}
|
||||
public void Execute(Action<object> action, object state) => this.Execute(new StateActionTaskQueueNode(action, state));
|
||||
|
||||
public void Execute(Action<object, object> action, object context, object state)
|
||||
{
|
||||
this.Execute(new StateActionWithContextTaskQueueNode(action, context, state));
|
||||
}
|
||||
public void Execute(Action<object, object> action, object context, object state) => this.Execute(new StateActionWithContextTaskQueueNode(action, context, state));
|
||||
|
||||
public void Execute(Action action)
|
||||
{
|
||||
this.Execute(new ActionTaskQueueNode(action));
|
||||
}
|
||||
public void Execute(Action action) => this.Execute(new ActionTaskQueueNode(action));
|
||||
|
||||
public virtual IScheduledTask Schedule(IRunnable action, TimeSpan delay)
|
||||
{
|
||||
|
@ -72,40 +58,28 @@ namespace DotNetty.Common.Concurrency
|
|||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public virtual Task ScheduleAsync(Action action, TimeSpan delay)
|
||||
{
|
||||
return this.ScheduleAsync(action, delay, CancellationToken.None);
|
||||
}
|
||||
public virtual Task ScheduleAsync(Action action, TimeSpan delay) => this.ScheduleAsync(action, delay, CancellationToken.None);
|
||||
|
||||
public virtual Task ScheduleAsync(Action<object> action, object state, TimeSpan delay, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public virtual Task ScheduleAsync(Action<object> action, object state, TimeSpan delay)
|
||||
{
|
||||
return this.ScheduleAsync(action, state, delay, CancellationToken.None);
|
||||
}
|
||||
public virtual Task ScheduleAsync(Action<object> action, object state, TimeSpan delay) => this.ScheduleAsync(action, state, delay, CancellationToken.None);
|
||||
|
||||
public virtual Task ScheduleAsync(Action action, TimeSpan delay, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public virtual Task ScheduleAsync(Action<object, object> action, object context, object state, TimeSpan delay)
|
||||
{
|
||||
return this.ScheduleAsync(action, context, state, delay, CancellationToken.None);
|
||||
}
|
||||
public virtual Task ScheduleAsync(Action<object, object> action, object context, object state, TimeSpan delay) => this.ScheduleAsync(action, context, state, delay, CancellationToken.None);
|
||||
|
||||
public virtual Task ScheduleAsync(Action<object, object> action, object context, object state, TimeSpan delay, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Task<T> SubmitAsync<T>(Func<T> func)
|
||||
{
|
||||
return this.SubmitAsync(func, CancellationToken.None);
|
||||
}
|
||||
public Task<T> SubmitAsync<T>(Func<T> func) => this.SubmitAsync(func, CancellationToken.None);
|
||||
|
||||
public Task<T> SubmitAsync<T>(Func<T> func, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -114,10 +88,7 @@ namespace DotNetty.Common.Concurrency
|
|||
return node.Completion;
|
||||
}
|
||||
|
||||
public Task<T> SubmitAsync<T>(Func<object, T> func, object state)
|
||||
{
|
||||
return this.SubmitAsync(func, state, CancellationToken.None);
|
||||
}
|
||||
public Task<T> SubmitAsync<T>(Func<object, T> func, object state) => this.SubmitAsync(func, state, CancellationToken.None);
|
||||
|
||||
public Task<T> SubmitAsync<T>(Func<object, T> func, object state, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -126,10 +97,7 @@ namespace DotNetty.Common.Concurrency
|
|||
return node.Completion;
|
||||
}
|
||||
|
||||
public Task<T> SubmitAsync<T>(Func<object, object, T> func, object context, object state)
|
||||
{
|
||||
return this.SubmitAsync(func, context, state, CancellationToken.None);
|
||||
}
|
||||
public Task<T> SubmitAsync<T>(Func<object, object, T> func, object context, object state) => this.SubmitAsync(func, context, state, CancellationToken.None);
|
||||
|
||||
public Task<T> SubmitAsync<T>(Func<object, object, T> func, object context, object state, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -138,10 +106,7 @@ namespace DotNetty.Common.Concurrency
|
|||
return node.Completion;
|
||||
}
|
||||
|
||||
public Task ShutdownGracefullyAsync()
|
||||
{
|
||||
return this.ShutdownGracefullyAsync(DefaultShutdownQuietPeriod, DefaultShutdownTimeout);
|
||||
}
|
||||
public Task ShutdownGracefullyAsync() => this.ShutdownGracefullyAsync(DefaultShutdownQuietPeriod, DefaultShutdownTimeout);
|
||||
|
||||
public abstract Task ShutdownGracefullyAsync(TimeSpan quietPeriod, TimeSpan timeout);
|
||||
|
||||
|
@ -163,10 +128,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.action = action;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
this.action();
|
||||
}
|
||||
public override void Run() => this.action();
|
||||
}
|
||||
|
||||
sealed class StateActionTaskQueueNode : RunnableQueueNode
|
||||
|
@ -180,10 +142,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.state = state;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
this.action(this.state);
|
||||
}
|
||||
public override void Run() => this.action(this.state);
|
||||
}
|
||||
|
||||
sealed class StateActionWithContextTaskQueueNode : RunnableQueueNode
|
||||
|
@ -199,10 +158,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.state = state;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
this.action(this.context, this.state);
|
||||
}
|
||||
public override void Run() => this.action(this.context, this.state);
|
||||
}
|
||||
|
||||
abstract class FuncQueueNodeBase<T> : RunnableQueueNode
|
||||
|
@ -251,10 +207,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.func = func;
|
||||
}
|
||||
|
||||
protected override T Call()
|
||||
{
|
||||
return this.func();
|
||||
}
|
||||
protected override T Call() => this.func();
|
||||
}
|
||||
|
||||
sealed class StateFuncSubmitQueueNode<T> : FuncQueueNodeBase<T>
|
||||
|
@ -267,10 +220,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.func = func;
|
||||
}
|
||||
|
||||
protected override T Call()
|
||||
{
|
||||
return this.func(this.Completion.AsyncState);
|
||||
}
|
||||
protected override T Call() => this.func(this.Completion.AsyncState);
|
||||
}
|
||||
|
||||
sealed class StateFuncWithContextSubmitQueueNode<T> : FuncQueueNodeBase<T>
|
||||
|
@ -285,10 +235,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
protected override T Call()
|
||||
{
|
||||
return this.func(this.context, this.Completion.AsyncState);
|
||||
}
|
||||
protected override T Call() => this.func(this.context, this.Completion.AsyncState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -19,12 +19,10 @@ namespace DotNetty.Common.Concurrency
|
|||
|
||||
// TODO: support for EventExecutorGroup
|
||||
|
||||
protected static PreciseTimeSpan GetNanos()
|
||||
{
|
||||
return PreciseTimeSpan.FromStart;
|
||||
}
|
||||
protected static PreciseTimeSpan GetNanos() => PreciseTimeSpan.FromStart;
|
||||
|
||||
protected static bool IsNullOrEmpty<T>(PriorityQueue<T> taskQueue) where T : class
|
||||
protected static bool IsNullOrEmpty<T>(PriorityQueue<T> taskQueue)
|
||||
where T : class
|
||||
{
|
||||
return taskQueue == null || taskQueue.Count == 0;
|
||||
}
|
||||
|
@ -51,10 +49,7 @@ namespace DotNetty.Common.Concurrency
|
|||
this.ScheduledTaskQueue.Clear();
|
||||
}
|
||||
|
||||
protected IScheduledRunnable PollScheduledTask()
|
||||
{
|
||||
return this.PollScheduledTask(GetNanos());
|
||||
}
|
||||
protected IScheduledRunnable PollScheduledTask() => this.PollScheduledTask(GetNanos());
|
||||
|
||||
protected IScheduledRunnable PollScheduledTask(PreciseTimeSpan nanoTime)
|
||||
{
|
||||
|
|
|
@ -16,9 +16,6 @@ namespace DotNetty.Common.Concurrency
|
|||
this.action = action;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
this.action();
|
||||
}
|
||||
protected override void Execute() => this.action();
|
||||
}
|
||||
}
|
|
@ -15,9 +15,6 @@ namespace DotNetty.Common.Concurrency
|
|||
this.action = action;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
this.action();
|
||||
}
|
||||
protected override void Execute() => this.action();
|
||||
}
|
||||
}
|
|
@ -42,15 +42,9 @@ namespace DotNetty.Common.Concurrency
|
|||
return this.TryExecuteTask(task);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Task> GetScheduledTasks()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
protected override IEnumerable<Task> GetScheduledTasks() => null;
|
||||
|
||||
protected override bool TryDequeue(Task task)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
protected override bool TryDequeue(Task task) => false;
|
||||
|
||||
sealed class TaskQueueNode : MpscLinkedQueueNode<IRunnable>, IRunnable
|
||||
{
|
||||
|
@ -65,10 +59,7 @@ namespace DotNetty.Common.Concurrency
|
|||
|
||||
public override IRunnable Value => this;
|
||||
|
||||
public void Run()
|
||||
{
|
||||
this.scheduler.TryExecuteTask(this.task);
|
||||
}
|
||||
public void Run() => this.scheduler.TryExecuteTask(this.task);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,10 +45,7 @@ namespace DotNetty.Common.Concurrency
|
|||
|
||||
public Task Completion => this.Promise.Task;
|
||||
|
||||
public TaskAwaiter GetAwaiter()
|
||||
{
|
||||
return this.Completion.GetAwaiter();
|
||||
}
|
||||
public TaskAwaiter GetAwaiter() => this.Completion.GetAwaiter();
|
||||
|
||||
int IComparable<IScheduledRunnable>.CompareTo(IScheduledRunnable other)
|
||||
{
|
||||
|
@ -78,10 +75,7 @@ namespace DotNetty.Common.Concurrency
|
|||
|
||||
protected abstract void Execute();
|
||||
|
||||
bool TrySetUncancelable()
|
||||
{
|
||||
return this.AtomicCancellationStateUpdate(CancellationProhibited, CancellationRequested);
|
||||
}
|
||||
bool TrySetUncancelable() => this.AtomicCancellationStateUpdate(CancellationProhibited, CancellationRequested);
|
||||
|
||||
bool AtomicCancellationStateUpdate(int newBits, int illegalBits)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace DotNetty.Common.Concurrency
|
|||
readonly TaskScheduler scheduler;
|
||||
readonly TaskCompletionSource terminationCompletionSource;
|
||||
PreciseTimeSpan gracefulShutdownStartTime;
|
||||
bool disposed;
|
||||
PreciseTimeSpan gracefulShutdownQuietPeriod;
|
||||
PreciseTimeSpan gracefulShutdownTimeout;
|
||||
|
||||
|
@ -89,10 +88,7 @@ namespace DotNetty.Common.Concurrency
|
|||
|
||||
public override bool IsTerminated => this.executionState == ST_TERMINATED;
|
||||
|
||||
public override bool IsInEventLoop(Thread t)
|
||||
{
|
||||
return this.thread == t;
|
||||
}
|
||||
public override bool IsInEventLoop(Thread t) => this.thread == t;
|
||||
|
||||
public override void Execute(IRunnable task)
|
||||
{
|
||||
|
|
|
@ -17,9 +17,6 @@ namespace DotNetty.Common.Concurrency
|
|||
this.action = action;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
this.action(this.Completion.AsyncState);
|
||||
}
|
||||
protected override void Execute() => this.action(this.Completion.AsyncState);
|
||||
}
|
||||
}
|
|
@ -15,9 +15,6 @@ namespace DotNetty.Common.Concurrency
|
|||
this.action = action;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
this.action(this.Completion.AsyncState);
|
||||
}
|
||||
protected override void Execute() => this.action(this.Completion.AsyncState);
|
||||
}
|
||||
}
|
|
@ -19,9 +19,6 @@ namespace DotNetty.Common.Concurrency
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
this.action(this.context, this.Completion.AsyncState);
|
||||
}
|
||||
protected override void Execute() => this.action(this.context, this.Completion.AsyncState);
|
||||
}
|
||||
}
|
|
@ -18,9 +18,6 @@ namespace DotNetty.Common.Concurrency
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
this.action(this.context, this.Completion.AsyncState);
|
||||
}
|
||||
protected override void Execute() => this.action(this.context, this.Completion.AsyncState);
|
||||
}
|
||||
}
|
|
@ -18,26 +18,14 @@ namespace DotNetty.Common.Concurrency
|
|||
{
|
||||
}
|
||||
|
||||
public bool TryComplete()
|
||||
{
|
||||
return this.TrySetResult(0);
|
||||
}
|
||||
public bool TryComplete() => this.TrySetResult(0);
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
this.SetResult(0);
|
||||
}
|
||||
public void Complete() => this.SetResult(0);
|
||||
|
||||
public bool setUncancellable()
|
||||
{
|
||||
// todo: support cancellation token where used
|
||||
return true;
|
||||
}
|
||||
// todo: support cancellation token where used
|
||||
public bool SetUncancellable() => true;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "TaskCompletionSource[status: " + this.Task.Status.ToString() + "]";
|
||||
}
|
||||
public override string ToString() => "TaskCompletionSource[status: " + this.Task.Status.ToString() + "]";
|
||||
|
||||
static TaskCompletionSource CreateVoidTcs()
|
||||
{
|
||||
|
|
|
@ -45,10 +45,7 @@ namespace DotNetty.Common
|
|||
/// non-{@link FastThreadLocalThread}s. This operation is useful when you are in a container environment, and you
|
||||
/// do not want to leave the thread local variables in the threads you do not manage. Call this method when your
|
||||
/// application is being unloaded from the container.
|
||||
public static void Destroy()
|
||||
{
|
||||
InternalThreadLocalMap.Destroy();
|
||||
}
|
||||
public static void Destroy() => InternalThreadLocalMap.Destroy();
|
||||
|
||||
protected static void AddToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal variable)
|
||||
{
|
||||
|
@ -152,33 +149,21 @@ namespace DotNetty.Common
|
|||
/// <summary>
|
||||
/// Returns {@code true} if and only if this thread-local variable is set.
|
||||
/// </summary>
|
||||
public bool IsSet()
|
||||
{
|
||||
return this.IsSet(InternalThreadLocalMap.GetIfSet());
|
||||
}
|
||||
public bool IsSet() => this.IsSet(InternalThreadLocalMap.GetIfSet());
|
||||
|
||||
/// <summary>
|
||||
/// Returns {@code true} if and only if this thread-local variable is set.
|
||||
/// The specified thread local map must be for the current thread.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsSet(InternalThreadLocalMap threadLocalMap)
|
||||
{
|
||||
return threadLocalMap != null && threadLocalMap.IsIndexedVariableSet(this.index);
|
||||
}
|
||||
public bool IsSet(InternalThreadLocalMap threadLocalMap) => threadLocalMap != null && threadLocalMap.IsIndexedVariableSet(this.index);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the initial value for this thread-local variable.
|
||||
/// </summary>
|
||||
protected virtual T GetInitialValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
protected virtual T GetInitialValue() => null;
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
this.Remove(InternalThreadLocalMap.GetIfSet());
|
||||
}
|
||||
public void Remove() => this.Remove(InternalThreadLocalMap.GetIfSet());
|
||||
|
||||
/// Sets the value to uninitialized for the specified thread local map;
|
||||
/// a proceeding call to get() will trigger a call to GetInitialValue().
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace DotNetty.Common
|
|||
/// <summary>
|
||||
/// Records the current access location of this object for debugging purposes.
|
||||
/// If this object is determined to be leaked, the information recorded by this operation will be provided to you
|
||||
/// via <see cref="ResourceLeakDetector{T}" />. This method is a shortcut to <see cref="Touch(object)" /> with null as
|
||||
/// via <see cref="ResourceLeakDetector" />. This method is a shortcut to <see cref="Touch(object)" /> with null as
|
||||
/// an argument.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
@ -35,7 +35,7 @@ namespace DotNetty.Common
|
|||
/// <summary>
|
||||
/// Records the current access location of this object with an additonal arbitrary information for debugging
|
||||
/// purposes. If this object is determined to be leaked, the information recorded by this operation will be
|
||||
/// provided to you via <see cref="ResourceLeakDetector{T}" />.
|
||||
/// provided to you via <see cref="ResourceLeakDetector" />.
|
||||
/// </summary>
|
||||
IReferenceCounted Touch(object hint);
|
||||
|
||||
|
|
|
@ -41,26 +41,17 @@ namespace DotNetty.Common.Internal
|
|||
|
||||
/// @param index desirable element index
|
||||
/// @return the offset in bytes within the array for a given index.
|
||||
protected long CalcElementOffset(long index)
|
||||
{
|
||||
return CalcElementOffset(index, this.Mask);
|
||||
}
|
||||
protected long CalcElementOffset(long index) => CalcElementOffset(index, this.Mask);
|
||||
|
||||
/// @param index desirable element index
|
||||
/// @param mask
|
||||
/// @return the offset in bytes within the array for a given index.
|
||||
protected static long CalcElementOffset(long index, long mask)
|
||||
{
|
||||
return RefBufferPad + (index & mask);
|
||||
}
|
||||
protected static long CalcElementOffset(long index, long mask) => RefBufferPad + (index & mask);
|
||||
|
||||
/// A plain store (no ordering/fences) of an element to a given offset
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @param e a kitty
|
||||
protected void SpElement(long offset, T e)
|
||||
{
|
||||
SpElement(this.Buffer, offset, e);
|
||||
}
|
||||
protected void SpElement(long offset, T e) => SpElement(this.Buffer, offset, e);
|
||||
|
||||
/// A plain store (no ordering/fences) of an element to a given offset
|
||||
/// @param buffer this.buffer
|
||||
|
@ -74,53 +65,35 @@ namespace DotNetty.Common.Internal
|
|||
/// An ordered store(store + StoreStore barrier) of an element to a given offset
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @param e an orderly kitty
|
||||
protected void SoElement(long offset, T e)
|
||||
{
|
||||
SoElement(this.Buffer, offset, e);
|
||||
}
|
||||
protected void SoElement(long offset, T e) => SoElement(this.Buffer, offset, e);
|
||||
|
||||
/// An ordered store(store + StoreStore barrier) of an element to a given offset
|
||||
/// @param buffer this.buffer
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @param e an orderly kitty
|
||||
protected static void SoElement(T[] buffer, long offset, T e)
|
||||
{
|
||||
Volatile.Write(ref buffer[offset], e);
|
||||
}
|
||||
protected static void SoElement(T[] buffer, long offset, T e) => Volatile.Write(ref buffer[offset], e);
|
||||
|
||||
/// A plain load (no ordering/fences) of an element from a given offset.
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @return the element at the offset
|
||||
protected T LpElement(long offset)
|
||||
{
|
||||
return LpElement(this.Buffer, offset);
|
||||
}
|
||||
protected T LpElement(long offset) => LpElement(this.Buffer, offset);
|
||||
|
||||
/// A plain load (no ordering/fences) of an element from a given offset.
|
||||
/// @param buffer this.buffer
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @return the element at the offset
|
||||
protected static T LpElement(T[] buffer, long offset)
|
||||
{
|
||||
return buffer[offset];
|
||||
}
|
||||
protected static T LpElement(T[] buffer, long offset) => buffer[offset];
|
||||
|
||||
/// A volatile load (load + LoadLoad barrier) of an element from a given offset.
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @return the element at the offset
|
||||
protected T LvElement(long offset)
|
||||
{
|
||||
return LvElement(this.Buffer, offset);
|
||||
}
|
||||
protected T LvElement(long offset) => LvElement(this.Buffer, offset);
|
||||
|
||||
/// A volatile load (load + LoadLoad barrier) of an element from a given offset.
|
||||
/// @param buffer this.buffer
|
||||
/// @param offset computed via {@link ConcurrentCircularArrayQueue#calcElementOffset(long)}
|
||||
/// @return the element at the offset
|
||||
protected static T LvElement(T[] buffer, long offset)
|
||||
{
|
||||
return Volatile.Read(ref buffer[offset]);
|
||||
}
|
||||
protected static T LvElement(T[] buffer, long offset) => Volatile.Read(ref buffer[offset]);
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
|
@ -130,10 +103,7 @@ namespace DotNetty.Common.Internal
|
|||
}
|
||||
}
|
||||
|
||||
public int Capacity()
|
||||
{
|
||||
return (int)(this.Mask + 1);
|
||||
}
|
||||
public int Capacity() => (int)(this.Mask + 1);
|
||||
}
|
||||
|
||||
abstract class ConcurrentCircularArrayQueueL0Pad<T> : AbstractQueue<T>
|
||||
|
|
|
@ -15,8 +15,6 @@ namespace DotNetty.Common.Internal.Logging
|
|||
{
|
||||
static readonly string EXCEPTION_MESSAGE = "Unexpected exception:";
|
||||
|
||||
readonly string name;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance.
|
||||
/// </summary>
|
||||
|
@ -25,10 +23,10 @@ namespace DotNetty.Common.Internal.Logging
|
|||
{
|
||||
Contract.Requires(name != null);
|
||||
|
||||
this.name = name;
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public string Name => this.name;
|
||||
public string Name { get; }
|
||||
|
||||
public bool IsEnabled(InternalLogLevel level)
|
||||
{
|
||||
|
@ -61,10 +59,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
|
||||
public abstract void Trace(string msg, Exception t);
|
||||
|
||||
public void Trace(Exception t)
|
||||
{
|
||||
this.Trace(EXCEPTION_MESSAGE, t);
|
||||
}
|
||||
public void Trace(Exception t) => this.Trace(EXCEPTION_MESSAGE, t);
|
||||
|
||||
public abstract bool DebugEnabled { get; }
|
||||
|
||||
|
@ -78,10 +73,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
|
||||
public abstract void Debug(string msg, Exception t);
|
||||
|
||||
public void Debug(Exception t)
|
||||
{
|
||||
this.Debug(EXCEPTION_MESSAGE, t);
|
||||
}
|
||||
public void Debug(Exception t) => this.Debug(EXCEPTION_MESSAGE, t);
|
||||
|
||||
public abstract bool InfoEnabled { get; }
|
||||
|
||||
|
@ -95,10 +87,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
|
||||
public abstract void Info(string msg, Exception t);
|
||||
|
||||
public void Info(Exception t)
|
||||
{
|
||||
this.Info(EXCEPTION_MESSAGE, t);
|
||||
}
|
||||
public void Info(Exception t) => this.Info(EXCEPTION_MESSAGE, t);
|
||||
|
||||
public abstract bool WarnEnabled { get; }
|
||||
|
||||
|
@ -112,10 +101,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
|
||||
public abstract void Warn(string msg, Exception t);
|
||||
|
||||
public void Warn(Exception t)
|
||||
{
|
||||
this.Warn(EXCEPTION_MESSAGE, t);
|
||||
}
|
||||
public void Warn(Exception t) => this.Warn(EXCEPTION_MESSAGE, t);
|
||||
|
||||
public abstract bool ErrorEnabled { get; }
|
||||
|
||||
|
@ -129,10 +115,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
|
||||
public abstract void Error(string msg, Exception t);
|
||||
|
||||
public void Error(Exception t)
|
||||
{
|
||||
this.Error(EXCEPTION_MESSAGE, t);
|
||||
}
|
||||
public void Error(Exception t) => this.Error(EXCEPTION_MESSAGE, t);
|
||||
|
||||
public void Log(InternalLogLevel level, string msg, Exception cause)
|
||||
{
|
||||
|
@ -278,9 +261,6 @@ namespace DotNetty.Common.Internal.Logging
|
|||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.GetType().Name + '(' + this.Name + ')'; // todo: port: revert: StringUtil.simpleClassName(this) + '(' + name() + ')';
|
||||
}
|
||||
public override string ToString() => this.GetType().Name + '(' + this.Name + ')';
|
||||
}
|
||||
}
|
|
@ -40,17 +40,14 @@ namespace DotNetty.Common.Internal.Logging
|
|||
public bool IsErrorEnabled => this.IsEnabled(EventLevel.Error, EventKeywords.None);
|
||||
|
||||
[NonEvent]
|
||||
public void Trace(string source, string message)
|
||||
{
|
||||
this.Trace(source, message, string.Empty);
|
||||
}
|
||||
public void Trace(string source, string message) => this.Trace(source, message, string.Empty);
|
||||
|
||||
[NonEvent]
|
||||
public void Trace(string source, string message, Exception exception)
|
||||
{
|
||||
if (this.IsTraceEnabled)
|
||||
{
|
||||
this.Trace(source, message, exception == null ? string.Empty : exception.ToString());
|
||||
this.Trace(source, message, exception?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,17 +61,14 @@ namespace DotNetty.Common.Internal.Logging
|
|||
}
|
||||
|
||||
[NonEvent]
|
||||
public void Debug(string source, string message)
|
||||
{
|
||||
this.Debug(source, message, string.Empty);
|
||||
}
|
||||
public void Debug(string source, string message) => this.Debug(source, message, string.Empty);
|
||||
|
||||
[NonEvent]
|
||||
public void Debug(string source, string message, Exception exception)
|
||||
{
|
||||
if (this.IsDebugEnabled)
|
||||
{
|
||||
this.Debug(source, message, exception == null ? string.Empty : exception.ToString());
|
||||
this.Debug(source, message, exception?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,17 +82,14 @@ namespace DotNetty.Common.Internal.Logging
|
|||
}
|
||||
|
||||
[NonEvent]
|
||||
public void Info(string source, string message)
|
||||
{
|
||||
this.Info(source, message, string.Empty);
|
||||
}
|
||||
public void Info(string source, string message) => this.Info(source, message, string.Empty);
|
||||
|
||||
[NonEvent]
|
||||
public void Info(string source, string message, Exception exception)
|
||||
{
|
||||
if (this.IsInfoEnabled)
|
||||
{
|
||||
this.Info(source, message, exception == null ? string.Empty : exception.ToString());
|
||||
this.Info(source, message, exception?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,17 +103,14 @@ namespace DotNetty.Common.Internal.Logging
|
|||
}
|
||||
|
||||
[NonEvent]
|
||||
public void Warning(string source, string message)
|
||||
{
|
||||
this.Warning(source, message, string.Empty);
|
||||
}
|
||||
public void Warning(string source, string message) => this.Warning(source, message, string.Empty);
|
||||
|
||||
[NonEvent]
|
||||
public void Warning(string source, string message, Exception exception)
|
||||
{
|
||||
if (this.IsWarningEnabled)
|
||||
{
|
||||
this.Warning(source, message, exception == null ? string.Empty : exception.ToString());
|
||||
this.Warning(source, message, exception?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,17 +124,14 @@ namespace DotNetty.Common.Internal.Logging
|
|||
}
|
||||
|
||||
[NonEvent]
|
||||
public void Error(string source, string message)
|
||||
{
|
||||
this.Error(source, message, string.Empty);
|
||||
}
|
||||
public void Error(string source, string message) => this.Error(source, message, string.Empty);
|
||||
|
||||
[NonEvent]
|
||||
public void Error(string source, string message, Exception exception)
|
||||
{
|
||||
if (this.IsErrorEnabled)
|
||||
{
|
||||
this.Error(source, message, exception == null ? string.Empty : exception.ToString());
|
||||
this.Error(source, message, exception?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// Log a message object at level TRACE.
|
||||
/// </summary>
|
||||
/// <param name="msg">the message object to be logged</param>
|
||||
public override void Trace(string msg)
|
||||
{
|
||||
DefaultEventSource.Log.Trace(this.Name, msg);
|
||||
}
|
||||
public override void Trace(string msg) => DefaultEventSource.Log.Trace(this.Name, msg);
|
||||
|
||||
/// <summary>
|
||||
/// Log a message at level TRACE according to the specified format and
|
||||
|
@ -90,10 +87,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// </summary>
|
||||
/// <param name="msg">the message accompanying the exception</param>
|
||||
/// <param name="t">the exception to log</param>
|
||||
public override void Trace(string msg, Exception t)
|
||||
{
|
||||
DefaultEventSource.Log.Trace(this.Name, msg, t);
|
||||
}
|
||||
public override void Trace(string msg, Exception t) => DefaultEventSource.Log.Trace(this.Name, msg, t);
|
||||
|
||||
/// <summary>
|
||||
/// Is this logger instance enabled for the DEBUG level?
|
||||
|
@ -105,10 +99,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// Log a message object at level DEBUG.
|
||||
/// </summary>
|
||||
/// <param name="msg">the message object to be logged</param>
|
||||
public override void Debug(string msg)
|
||||
{
|
||||
DefaultEventSource.Log.Debug(this.Name, msg);
|
||||
}
|
||||
public override void Debug(string msg) => DefaultEventSource.Log.Debug(this.Name, msg);
|
||||
|
||||
/// <summary>
|
||||
/// Log a message at level DEBUG according to the specified format and
|
||||
|
@ -173,10 +164,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// </summary>
|
||||
/// <param name="msg">the message accompanying the exception</param>
|
||||
/// <param name="t">the exception to log</param>
|
||||
public override void Debug(string msg, Exception t)
|
||||
{
|
||||
DefaultEventSource.Log.Debug(this.Name, msg, t);
|
||||
}
|
||||
public override void Debug(string msg, Exception t) => DefaultEventSource.Log.Debug(this.Name, msg, t);
|
||||
|
||||
/// <summary>
|
||||
/// Is this logger instance enabled for the INFO level?
|
||||
|
@ -188,10 +176,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// Log a message object at level INFO.
|
||||
/// </summary>
|
||||
/// <param name="msg">the message object to be logged</param>
|
||||
public override void Info(string msg)
|
||||
{
|
||||
DefaultEventSource.Log.Info(this.Name, msg);
|
||||
}
|
||||
public override void Info(string msg) => DefaultEventSource.Log.Info(this.Name, msg);
|
||||
|
||||
/// <summary>
|
||||
/// Log a message at level INFO according to the specified format and
|
||||
|
@ -256,10 +241,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// </summary>
|
||||
/// <param name="msg">the message accompanying the exception</param>
|
||||
/// <param name="t">the exception to log</param>
|
||||
public override void Info(string msg, Exception t)
|
||||
{
|
||||
DefaultEventSource.Log.Info(this.Name, msg, t);
|
||||
}
|
||||
public override void Info(string msg, Exception t) => DefaultEventSource.Log.Info(this.Name, msg, t);
|
||||
|
||||
/// <summary>
|
||||
/// Is this logger instance enabled for the WARN level?
|
||||
|
@ -271,10 +253,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// Log a message object at level WARN.
|
||||
/// </summary>
|
||||
/// <param name="msg">the message object to be logged</param>
|
||||
public override void Warn(string msg)
|
||||
{
|
||||
DefaultEventSource.Log.Warning(this.Name, msg);
|
||||
}
|
||||
public override void Warn(string msg) => DefaultEventSource.Log.Warning(this.Name, msg);
|
||||
|
||||
/// <summary>
|
||||
/// Log a message at level WARN according to the specified format and
|
||||
|
@ -339,10 +318,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// </summary>
|
||||
/// <param name="msg">the message accompanying the exception</param>
|
||||
/// <param name="t">the exception to log</param>
|
||||
public override void Warn(string msg, Exception t)
|
||||
{
|
||||
DefaultEventSource.Log.Warning(this.Name, msg, t);
|
||||
}
|
||||
public override void Warn(string msg, Exception t) => DefaultEventSource.Log.Warning(this.Name, msg, t);
|
||||
|
||||
/// <summary>
|
||||
/// Is this logger instance enabled for the ERROR level?
|
||||
|
@ -354,10 +330,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// Log a message object at level ERROR.
|
||||
/// </summary>
|
||||
/// <param name="msg">the message object to be logged</param>
|
||||
public override void Error(string msg)
|
||||
{
|
||||
DefaultEventSource.Log.Error(this.Name, msg);
|
||||
}
|
||||
public override void Error(string msg) => DefaultEventSource.Log.Error(this.Name, msg);
|
||||
|
||||
/// <summary>
|
||||
/// Log a message at level ERROR according to the specified format and
|
||||
|
@ -422,9 +395,6 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// </summary>
|
||||
/// <param name="msg">the message accompanying the exception</param>
|
||||
/// <param name="t">the exception to log</param>
|
||||
public override void Error(string msg, Exception t)
|
||||
{
|
||||
DefaultEventSource.Log.Error(this.Name, msg, t);
|
||||
}
|
||||
public override void Error(string msg, Exception t) => DefaultEventSource.Log.Error(this.Name, msg, t);
|
||||
}
|
||||
}
|
|
@ -5,9 +5,6 @@ namespace DotNetty.Common.Internal.Logging
|
|||
{
|
||||
class EventSourceLoggerFactory : InternalLoggerFactory
|
||||
{
|
||||
protected internal override IInternalLogger NewInstance(string name)
|
||||
{
|
||||
return new EventSourceLogger(name);
|
||||
}
|
||||
protected internal override IInternalLogger NewInstance(string name) => new EventSourceLogger(name);
|
||||
}
|
||||
}
|
|
@ -24,17 +24,18 @@ namespace DotNetty.Common.Internal.Logging
|
|||
{
|
||||
static InternalLoggerFactory defaultFactory;
|
||||
|
||||
static InternalLoggerFactory()
|
||||
{
|
||||
// todo: port: revisit
|
||||
// Initiate some time-consuming background jobs here,
|
||||
// because this class is often initialized at the earliest time.
|
||||
//try {
|
||||
// Class.forName(ThreadLocalRandom.class.getName(), true, InternalLoggerFactory.class.getClassLoader());
|
||||
//} catch (Exception ignored) {
|
||||
// // Should not fail, but it does not harm to fail.
|
||||
//}
|
||||
}
|
||||
// todo: port: revisit
|
||||
//static InternalLoggerFactory()
|
||||
//{
|
||||
// // Initiate some time-consuming background jobs here,
|
||||
// // because this class is often initialized at the earliest time.
|
||||
// try
|
||||
// {
|
||||
// Class.forName(ThreadLocalRandom.class.getName(), true, InternalLoggerFactory.class.getClassLoader());
|
||||
// } catch (Exception ignored) {
|
||||
// // Should not fail, but it does not harm to fail.
|
||||
// }
|
||||
//}
|
||||
|
||||
static InternalLoggerFactory NewDefaultFactory(string name)
|
||||
{
|
||||
|
@ -75,30 +76,21 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// </summary>
|
||||
/// <typeparam name="T">type where logger is used</typeparam>
|
||||
/// <returns>logger instance</returns>
|
||||
public static IInternalLogger GetInstance<T>()
|
||||
{
|
||||
return GetInstance(typeof(T));
|
||||
}
|
||||
public static IInternalLogger GetInstance<T>() => GetInstance(typeof(T));
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new logger instance with the name of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">type where logger is used</param>
|
||||
/// <returns>logger instance</returns>
|
||||
public static IInternalLogger GetInstance(Type type)
|
||||
{
|
||||
return GetInstance(type.FullName);
|
||||
}
|
||||
public static IInternalLogger GetInstance(Type type) => GetInstance(type.FullName);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new logger instance with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="name">logger name</param>
|
||||
/// <returns>logger instance</returns>
|
||||
public static IInternalLogger GetInstance(string name)
|
||||
{
|
||||
return DefaultFactory.NewInstance(name);
|
||||
}
|
||||
public static IInternalLogger GetInstance(string name) => DefaultFactory.NewInstance(name);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new logger instance with the specified name.
|
||||
|
|
|
@ -91,10 +91,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// <param name="messagePattern">The message pattern which will be parsed and formatted</param>
|
||||
/// <param name="arg">The argument to be substituted in place of the formatting anchor</param>
|
||||
/// <returns>The formatted message</returns>
|
||||
public static FormattingTuple Format(string messagePattern, object arg)
|
||||
{
|
||||
return ArrayFormat(messagePattern, new[] { arg });
|
||||
}
|
||||
public static FormattingTuple Format(string messagePattern, object arg) => ArrayFormat(messagePattern, new[] { arg });
|
||||
|
||||
/// <summary>
|
||||
/// Performs a two argument substitution for the 'messagePattern' passed as
|
||||
|
@ -112,11 +109,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
/// <param name="argA">The argument to be substituted in place of the first formatting anchor</param>
|
||||
/// <param name="argB">The argument to be substituted in place of the second formatting anchor</param>
|
||||
/// <returns>The formatted message</returns>
|
||||
public static FormattingTuple Format(string messagePattern,
|
||||
object argA, object argB)
|
||||
{
|
||||
return ArrayFormat(messagePattern, new object[] { argA, argB });
|
||||
}
|
||||
public static FormattingTuple Format(string messagePattern, object argA, object argB) => ArrayFormat(messagePattern, new[] { argA, argB });
|
||||
|
||||
public static Exception GetThrowableCandidate(object[] argArray)
|
||||
{
|
||||
|
@ -125,12 +118,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
return null;
|
||||
}
|
||||
|
||||
object lastEntry = argArray[argArray.Length - 1];
|
||||
if (lastEntry is Exception)
|
||||
{
|
||||
return (Exception)lastEntry;
|
||||
}
|
||||
return null;
|
||||
return argArray[argArray.Length - 1] as Exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -157,13 +145,12 @@ namespace DotNetty.Common.Internal.Logging
|
|||
}
|
||||
|
||||
int i = 0;
|
||||
int j;
|
||||
var sbuf = new StringBuilder(messagePattern.Length + 50);
|
||||
|
||||
int l;
|
||||
for (l = 0; l < argArray.Length; l++)
|
||||
{
|
||||
j = messagePattern.IndexOf(DELIM_STR, i, StringComparison.Ordinal);
|
||||
int j = messagePattern.IndexOf(DELIM_STR, i, StringComparison.Ordinal);
|
||||
|
||||
if (j == -1)
|
||||
{
|
||||
|
@ -235,11 +222,7 @@ namespace DotNetty.Common.Internal.Logging
|
|||
return messagePattern[delimeterStartIndex - 1] == ESCAPE_CHAR;
|
||||
}
|
||||
|
||||
public static bool IsDoubleEscaped(string messagePattern,
|
||||
int delimeterStartIndex)
|
||||
{
|
||||
return delimeterStartIndex >= 2 && messagePattern[delimeterStartIndex - 2] == ESCAPE_CHAR;
|
||||
}
|
||||
public static bool IsDoubleEscaped(string messagePattern, int delimeterStartIndex) => delimeterStartIndex >= 2 && messagePattern[delimeterStartIndex - 2] == ESCAPE_CHAR;
|
||||
|
||||
// special treatment of array values was suggested by 'lizongbo'
|
||||
static void DeeplyAppendParameter(StringBuilder sbuf, object o,
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace DotNetty.Common.Internal
|
|||
/// method for polling from the queue (with minor change to correctly publish the index) and an extension of
|
||||
/// the Leslie Lamport concurrent queue algorithm (originated by Martin Thompson) on the producer side.
|
||||
/// <br />
|
||||
/// @param <E>
|
||||
sealed class MpscArrayQueue<T> : MpscArrayQueueConsumerField<T>
|
||||
where T : class
|
||||
{
|
||||
|
@ -256,15 +255,9 @@ namespace DotNetty.Common.Internal
|
|||
{
|
||||
}
|
||||
|
||||
protected long ProducerIndex
|
||||
{
|
||||
get { return Volatile.Read(ref this.producerIndex); }
|
||||
}
|
||||
protected long ProducerIndex => Volatile.Read(ref this.producerIndex);
|
||||
|
||||
protected bool TrySetProducerIndex(long expect, long newValue)
|
||||
{
|
||||
return Interlocked.CompareExchange(ref this.producerIndex, newValue, expect) == expect;
|
||||
}
|
||||
protected bool TrySetProducerIndex(long expect, long newValue) => Interlocked.CompareExchange(ref this.producerIndex, newValue, expect) == expect;
|
||||
}
|
||||
|
||||
abstract class MpscArrayQueueMidPad<T> : MpscArrayQueueTailField<T>
|
||||
|
|
|
@ -19,20 +19,14 @@ namespace DotNetty.Common.Internal
|
|||
/// Returns <c>true</c> if and only if the system property with the specified <c>key</c>
|
||||
/// exists.
|
||||
/// </summary>
|
||||
public static bool Contains(string key)
|
||||
{
|
||||
return Get(key) != null;
|
||||
}
|
||||
public static bool Contains(string key) => Get(key) != null;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value of the system property with the specified
|
||||
/// <c>key</c>, while falling back to <c>null</c> if the property access fails.
|
||||
/// </summary>
|
||||
/// <returns>the property value or <c>null</c></returns>
|
||||
public static string Get(string key)
|
||||
{
|
||||
return Get(key, null);
|
||||
}
|
||||
public static string Get(string key) => Get(key, null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value of the system property with the specified
|
||||
|
@ -167,14 +161,8 @@ namespace DotNetty.Common.Internal
|
|||
return result;
|
||||
}
|
||||
|
||||
static void Log(string msg)
|
||||
{
|
||||
Logger.Warn(msg);
|
||||
}
|
||||
static void Log(string msg) => Logger.Warn(msg);
|
||||
|
||||
static void Log(string msg, Exception e)
|
||||
{
|
||||
Logger.Warn(msg, e);
|
||||
}
|
||||
static void Log(string msg, Exception e) => Logger.Warn(msg, e);
|
||||
}
|
||||
}
|
|
@ -45,10 +45,7 @@ namespace DotNetty.Common
|
|||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static InternalThreadLocalMap GetIfSet()
|
||||
{
|
||||
return slowThreadLocalMap;
|
||||
}
|
||||
public static InternalThreadLocalMap GetIfSet() => slowThreadLocalMap;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static InternalThreadLocalMap Get()
|
||||
|
@ -62,15 +59,9 @@ namespace DotNetty.Common
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static void Remove()
|
||||
{
|
||||
slowThreadLocalMap = null;
|
||||
}
|
||||
public static void Remove() => slowThreadLocalMap = null;
|
||||
|
||||
public static void Destroy()
|
||||
{
|
||||
slowThreadLocalMap = null;
|
||||
}
|
||||
public static void Destroy() => slowThreadLocalMap = null;
|
||||
|
||||
// Cache line padding (must be public)
|
||||
// With CompressedOops enabled, an instance of this class should occupy at least 128 bytes.
|
||||
|
|
|
@ -28,40 +28,19 @@ namespace DotNetty.Common
|
|||
|
||||
public static PreciseTimeSpan FromStart => new PreciseTimeSpan(GetTimeChangeSinceStart());
|
||||
|
||||
public static PreciseTimeSpan FromTimeSpan(TimeSpan timeSpan)
|
||||
{
|
||||
return new PreciseTimeSpan(TicksToPreciseTicks(timeSpan.Ticks));
|
||||
}
|
||||
public static PreciseTimeSpan FromTimeSpan(TimeSpan timeSpan) => new PreciseTimeSpan(TicksToPreciseTicks(timeSpan.Ticks));
|
||||
|
||||
public static PreciseTimeSpan Deadline(TimeSpan deadline)
|
||||
{
|
||||
return new PreciseTimeSpan(GetTimeChangeSinceStart() + TicksToPreciseTicks(deadline.Ticks));
|
||||
}
|
||||
public static PreciseTimeSpan Deadline(TimeSpan deadline) => new PreciseTimeSpan(GetTimeChangeSinceStart() + TicksToPreciseTicks(deadline.Ticks));
|
||||
|
||||
public static PreciseTimeSpan Deadline(PreciseTimeSpan deadline)
|
||||
{
|
||||
return new PreciseTimeSpan(GetTimeChangeSinceStart() + deadline.ticks);
|
||||
}
|
||||
public static PreciseTimeSpan Deadline(PreciseTimeSpan deadline) => new PreciseTimeSpan(GetTimeChangeSinceStart() + deadline.ticks);
|
||||
|
||||
static long TicksToPreciseTicks(long ticks)
|
||||
{
|
||||
return Stopwatch.IsHighResolution ? (long)(ticks * PrecisionRatio) : ticks;
|
||||
}
|
||||
static long TicksToPreciseTicks(long ticks) => Stopwatch.IsHighResolution ? (long)(ticks * PrecisionRatio) : ticks;
|
||||
|
||||
public TimeSpan ToTimeSpan()
|
||||
{
|
||||
return TimeSpan.FromTicks((long)(this.ticks * ReversePrecisionRatio));
|
||||
}
|
||||
public TimeSpan ToTimeSpan() => TimeSpan.FromTicks((long)(this.ticks * ReversePrecisionRatio));
|
||||
|
||||
static long GetTimeChangeSinceStart()
|
||||
{
|
||||
return Stopwatch.GetTimestamp() - StartTime;
|
||||
}
|
||||
static long GetTimeChangeSinceStart() => Stopwatch.GetTimestamp() - StartTime;
|
||||
|
||||
public bool Equals(PreciseTimeSpan other)
|
||||
{
|
||||
return this.ticks == other.ticks;
|
||||
}
|
||||
public bool Equals(PreciseTimeSpan other) => this.ticks == other.ticks;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
@ -73,45 +52,21 @@ namespace DotNetty.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.ticks.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => this.ticks.GetHashCode();
|
||||
|
||||
public int CompareTo(PreciseTimeSpan other)
|
||||
{
|
||||
return this.ticks.CompareTo(other.ticks);
|
||||
}
|
||||
public int CompareTo(PreciseTimeSpan other) => this.ticks.CompareTo(other.ticks);
|
||||
|
||||
public static bool operator ==(PreciseTimeSpan t1, PreciseTimeSpan t2)
|
||||
{
|
||||
return t1.ticks == t2.ticks;
|
||||
}
|
||||
public static bool operator ==(PreciseTimeSpan t1, PreciseTimeSpan t2) => t1.ticks == t2.ticks;
|
||||
|
||||
public static bool operator !=(PreciseTimeSpan t1, PreciseTimeSpan t2)
|
||||
{
|
||||
return t1.ticks != t2.ticks;
|
||||
}
|
||||
public static bool operator !=(PreciseTimeSpan t1, PreciseTimeSpan t2) => t1.ticks != t2.ticks;
|
||||
|
||||
public static bool operator >(PreciseTimeSpan t1, PreciseTimeSpan t2)
|
||||
{
|
||||
return t1.ticks > t2.ticks;
|
||||
}
|
||||
public static bool operator >(PreciseTimeSpan t1, PreciseTimeSpan t2) => t1.ticks > t2.ticks;
|
||||
|
||||
public static bool operator <(PreciseTimeSpan t1, PreciseTimeSpan t2)
|
||||
{
|
||||
return t1.ticks < t2.ticks;
|
||||
}
|
||||
public static bool operator <(PreciseTimeSpan t1, PreciseTimeSpan t2) => t1.ticks < t2.ticks;
|
||||
|
||||
public static bool operator >=(PreciseTimeSpan t1, PreciseTimeSpan t2)
|
||||
{
|
||||
return t1.ticks >= t2.ticks;
|
||||
}
|
||||
public static bool operator >=(PreciseTimeSpan t1, PreciseTimeSpan t2) => t1.ticks >= t2.ticks;
|
||||
|
||||
public static bool operator <=(PreciseTimeSpan t1, PreciseTimeSpan t2)
|
||||
{
|
||||
return t1.ticks <= t2.ticks;
|
||||
}
|
||||
public static bool operator <=(PreciseTimeSpan t1, PreciseTimeSpan t2) => t1.ticks <= t2.ticks;
|
||||
|
||||
public static PreciseTimeSpan operator +(PreciseTimeSpan t, TimeSpan duration)
|
||||
{
|
||||
|
|
|
@ -115,15 +115,9 @@ namespace DotNetty.Common
|
|||
this.maxActive = maxActive;
|
||||
}
|
||||
|
||||
public static ResourceLeakDetector Create<T>()
|
||||
{
|
||||
return new ResourceLeakDetector(StringUtil.SimpleClassName<T>());
|
||||
}
|
||||
public static ResourceLeakDetector Create<T>() => new ResourceLeakDetector(StringUtil.SimpleClassName<T>());
|
||||
|
||||
public static ResourceLeakDetector Create<T>(int samplingInterval, long maxActive)
|
||||
{
|
||||
return new ResourceLeakDetector(StringUtil.SimpleClassName<T>(), samplingInterval, maxActive);
|
||||
}
|
||||
public static ResourceLeakDetector Create<T>(int samplingInterval, long maxActive) => new ResourceLeakDetector(StringUtil.SimpleClassName<T>(), samplingInterval, maxActive);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IResourceLeak" /> which is expected to be closed via <see cref="IResourceLeak.Close()" />
|
||||
|
@ -232,15 +226,9 @@ namespace DotNetty.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void Record()
|
||||
{
|
||||
this.RecordInternal(null, 3);
|
||||
}
|
||||
public void Record() => this.RecordInternal(null, 3);
|
||||
|
||||
public void Record(object hint)
|
||||
{
|
||||
this.RecordInternal(hint, 3);
|
||||
}
|
||||
public void Record(object hint) => this.RecordInternal(hint, 3);
|
||||
|
||||
void RecordInternal(object hint, int recordsToSkip)
|
||||
{
|
||||
|
|
|
@ -31,15 +31,12 @@ namespace DotNetty.Common
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the specified {@code task} to run when the specified {@code thread} dies.
|
||||
*
|
||||
* @param thread the {@link Thread} to watch
|
||||
* @param task the {@link Runnable} to run when the {@code thread} dies
|
||||
*
|
||||
* @throws IllegalArgumentException if the specified {@code thread} is not alive
|
||||
*/
|
||||
|
||||
/// Schedules the specified {@code task} to run when the specified {@code thread} dies.
|
||||
///
|
||||
/// @param thread the {@link Thread} to watch
|
||||
/// @param task the {@link Runnable} to run when the {@code thread} dies
|
||||
///
|
||||
/// @throws IllegalArgumentException if the specified {@code thread} is not alive
|
||||
public static void Watch(Thread thread, Action task)
|
||||
{
|
||||
Contract.Requires(thread != null);
|
||||
|
@ -49,10 +46,7 @@ namespace DotNetty.Common
|
|||
Schedule(thread, task, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the task scheduled via {@link #watch(Thread, Runnable)}.
|
||||
*/
|
||||
|
||||
/// Cancels the task scheduled via {@link #watch(Thread, Runnable)}.
|
||||
public static void Unwatch(Thread thread, Action task)
|
||||
{
|
||||
Contract.Requires(thread != null);
|
||||
|
@ -67,22 +61,20 @@ namespace DotNetty.Common
|
|||
|
||||
if (Interlocked.CompareExchange(ref started, 1, 0) == 0)
|
||||
{
|
||||
Thread watcherThread = new Thread(s => ((IRunnable)s).Run());
|
||||
var watcherThread = new Thread(s => ((IRunnable)s).Run());
|
||||
watcherThread.Start(watcher);
|
||||
ThreadDeathWatcher.watcherThread = watcherThread;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until the thread of this watcher has no threads to watch and terminates itself.
|
||||
* Because a new watcher thread will be started again on {@link #watch(Thread, Runnable)},
|
||||
* this operation is only useful when you want to ensure that the watcher thread is terminated
|
||||
* <strong>after</strong> your application is shut down and there's no chance of calling
|
||||
* {@link #watch(Thread, Runnable)} afterwards.
|
||||
*
|
||||
* @return {@code true} if and only if the watcher thread has been terminated
|
||||
*/
|
||||
|
||||
/// Waits until the thread of this watcher has no threads to watch and terminates itself.
|
||||
/// Because a new watcher thread will be started again on {@link #watch(Thread, Runnable)},
|
||||
/// this operation is only useful when you want to ensure that the watcher thread is terminated
|
||||
/// <strong>after</strong>
|
||||
/// your application is shut down and there's no chance of calling
|
||||
/// {@link #watch(Thread, Runnable)} afterwards.
|
||||
///
|
||||
/// @return {@code true} if and only if the watcher thread has been terminated
|
||||
public static bool AwaitInactivity(TimeSpan timeout)
|
||||
{
|
||||
Thread watcherThread = ThreadDeathWatcher.watcherThread;
|
||||
|
@ -207,15 +199,9 @@ namespace DotNetty.Common
|
|||
this.IsWatch = isWatch;
|
||||
}
|
||||
|
||||
public override Entry Value
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
public override Entry Value => this;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Thread.GetHashCode() ^ this.Task.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => this.Thread.GetHashCode() ^ this.Task.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
|
|
@ -16,10 +16,7 @@ namespace DotNetty.Common
|
|||
this.returnHandle = returnHandle;
|
||||
}
|
||||
|
||||
public static ThreadLocalObjectList Take()
|
||||
{
|
||||
return Pool.Take();
|
||||
}
|
||||
public static ThreadLocalObjectList Take() => Pool.Take();
|
||||
|
||||
public void Return()
|
||||
{
|
||||
|
|
|
@ -54,17 +54,12 @@ namespace DotNetty.Common
|
|||
|
||||
sealed class Link
|
||||
{
|
||||
int readIndex;
|
||||
int writeIndex;
|
||||
|
||||
internal readonly Handle[] elements;
|
||||
internal Link next;
|
||||
|
||||
internal int ReadIndex
|
||||
{
|
||||
get { return this.readIndex; }
|
||||
set { this.readIndex = value; }
|
||||
}
|
||||
internal int ReadIndex { get; set; }
|
||||
|
||||
internal int WriteIndex
|
||||
{
|
||||
|
@ -377,10 +372,7 @@ namespace DotNetty.Common
|
|||
|
||||
internal sealed class DelayedThreadLocal : FastThreadLocal<ConditionalWeakTable<Stack, WeakOrderQueue>>
|
||||
{
|
||||
protected override ConditionalWeakTable<Stack, WeakOrderQueue> GetInitialValue()
|
||||
{
|
||||
return new ConditionalWeakTable<Stack, WeakOrderQueue>();
|
||||
}
|
||||
protected override ConditionalWeakTable<Stack, WeakOrderQueue> GetInitialValue() => new ConditionalWeakTable<Stack, WeakOrderQueue>();
|
||||
}
|
||||
|
||||
public ThreadLocalPool(int maxCapacity)
|
||||
|
|
|
@ -37,10 +37,7 @@ namespace DotNetty.Common.Utilities
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void SetRange<T>(this T[] array, int index, T[] src)
|
||||
{
|
||||
SetRange(array, index, src, 0, src.Length);
|
||||
}
|
||||
public static void SetRange<T>(this T[] array, int index, T[] src) => SetRange(array, index, src, 0, src.Length);
|
||||
|
||||
public static void SetRange<T>(this T[] array, int index, T[] src, int srcIndex, int srcLength)
|
||||
{
|
||||
|
|
|
@ -43,10 +43,7 @@ namespace DotNetty.Common.Utilities
|
|||
/// <see cref="newValue" />.
|
||||
/// Returns true if <see cref="newValue" /> was set, false otherwise.
|
||||
/// </summary>
|
||||
public T CompareAndSet(T expected, T newValue)
|
||||
{
|
||||
return Interlocked.CompareExchange(ref this.atomicValue, expected, newValue);
|
||||
}
|
||||
public T CompareAndSet(T expected, T newValue) => Interlocked.CompareExchange(ref this.atomicValue, expected, newValue);
|
||||
|
||||
#region Conversion operators
|
||||
|
||||
|
@ -54,10 +51,7 @@ namespace DotNetty.Common.Utilities
|
|||
/// Implicit conversion operator = automatically casts the <see cref="AtomicReference{T}" /> to an instance of
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// </summary>
|
||||
public static implicit operator T(AtomicReference<T> aRef)
|
||||
{
|
||||
return aRef.Value;
|
||||
}
|
||||
public static implicit operator T(AtomicReference<T> aRef) => aRef.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Implicit conversion operator = allows us to cast any type directly into a <see cref="AtomicReference{T}" />
|
||||
|
@ -65,10 +59,7 @@ namespace DotNetty.Common.Utilities
|
|||
/// </summary>
|
||||
/// <param name="newValue"></param>
|
||||
/// <returns></returns>
|
||||
public static implicit operator AtomicReference<T>(T newValue)
|
||||
{
|
||||
return new AtomicReference<T>(newValue);
|
||||
}
|
||||
public static implicit operator AtomicReference<T>(T newValue) => new AtomicReference<T>(newValue);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -8,15 +8,9 @@ namespace DotNetty.Common.Utilities
|
|||
public static class BitOps
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int RightUShift(this int value, int bits)
|
||||
{
|
||||
return unchecked((int)((uint)value >> bits));
|
||||
}
|
||||
public static int RightUShift(this int value, int bits) => unchecked((int)((uint)value >> bits));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long RightUShift(this long value, int bits)
|
||||
{
|
||||
return unchecked((long)((ulong)value >> bits));
|
||||
}
|
||||
public static long RightUShift(this long value, int bits) => unchecked((long)((ulong)value >> bits));
|
||||
}
|
||||
}
|
|
@ -23,10 +23,7 @@ namespace DotNetty.Common.Utilities
|
|||
this.byteToFind = byteToFind;
|
||||
}
|
||||
|
||||
public override bool Process(byte value)
|
||||
{
|
||||
return value != this.byteToFind;
|
||||
}
|
||||
public override bool Process(byte value) => value != this.byteToFind;
|
||||
}
|
||||
|
||||
public sealed class IndexNotOfProcessor : ByteProcessor
|
||||
|
@ -38,10 +35,7 @@ namespace DotNetty.Common.Utilities
|
|||
this.byteToNotFind = byteToNotFind;
|
||||
}
|
||||
|
||||
public override bool Process(byte value)
|
||||
{
|
||||
return value == this.byteToNotFind;
|
||||
}
|
||||
public override bool Process(byte value) => value == this.byteToNotFind;
|
||||
}
|
||||
|
||||
public sealed class CustomProcessor : ByteProcessor
|
||||
|
@ -54,21 +48,18 @@ namespace DotNetty.Common.Utilities
|
|||
this.customHandler = customHandler;
|
||||
}
|
||||
|
||||
public override bool Process(byte value)
|
||||
{
|
||||
return this.customHandler(value);
|
||||
}
|
||||
public override bool Process(byte value) => this.customHandler(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aborts on a <c>NUL (0x00)</c>.
|
||||
/// </summary>
|
||||
public static ByteProcessor FIND_NUL = new IndexOfProcessor((byte)0);
|
||||
public static ByteProcessor FIND_NUL = new IndexOfProcessor(0);
|
||||
|
||||
/// <summary>
|
||||
/// Aborts on a non-{@code NUL (0x00)}.
|
||||
/// </summary>
|
||||
public static ByteProcessor FIND_NON_NUL = new IndexNotOfProcessor((byte)0);
|
||||
public static ByteProcessor FIND_NON_NUL = new IndexNotOfProcessor(0);
|
||||
|
||||
/// <summary>
|
||||
/// Aborts on a {@code CR ('\r')}.
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace DotNetty.Common.Utilities
|
|||
public T Peek()
|
||||
{
|
||||
MpscLinkedQueueNode<T> next = this.PeekNode();
|
||||
return next == null ? null : next.Value;
|
||||
return next?.Value;
|
||||
}
|
||||
|
||||
public int Count
|
||||
|
@ -137,10 +137,7 @@ namespace DotNetty.Common.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
@ -169,7 +166,7 @@ namespace DotNetty.Common.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
abstract class MpscLinkedQueueHeadRef<T> : MpscLinkedQueuePad0<T>
|
||||
abstract class MpscLinkedQueueHeadRef<T> : MpscLinkedQueuePad0
|
||||
{
|
||||
MpscLinkedQueueNode<T> headRef;
|
||||
|
||||
|
@ -196,21 +193,15 @@ namespace DotNetty.Common.Utilities
|
|||
/// Sets the element this node contains to <code>null</code> so that the node can be used as a tombstone.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected internal virtual T ClearMaybe()
|
||||
{
|
||||
return this.Value;
|
||||
}
|
||||
protected internal virtual T ClearMaybe() => this.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Unlink to allow GC
|
||||
/// </summary>
|
||||
internal virtual void Unlink()
|
||||
{
|
||||
this.Next = null;
|
||||
}
|
||||
internal virtual void Unlink() => this.Next = null;
|
||||
}
|
||||
|
||||
abstract class MpscLinkedQueuePad0<T>
|
||||
abstract class MpscLinkedQueuePad0
|
||||
{
|
||||
#pragma warning disable 169 // padded reference
|
||||
long p00, p01, p02, p03, p04, p05, p06, p07;
|
||||
|
|
|
@ -51,10 +51,7 @@ namespace DotNetty.Common.Utilities
|
|||
return result;
|
||||
}
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
return this.count == 0 ? null : this.items[0];
|
||||
}
|
||||
public T Peek() => this.count == 0 ? null : this.items[0];
|
||||
|
||||
public void Enqueue(T item)
|
||||
{
|
||||
|
@ -152,10 +149,7 @@ namespace DotNetty.Common.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
|
|
@ -7,9 +7,6 @@ namespace DotNetty.Common.Utilities
|
|||
|
||||
public static class RandomExtensions
|
||||
{
|
||||
public static long NextLong(this Random random)
|
||||
{
|
||||
return random.Next() << 32 & unchecked((uint)random.Next());
|
||||
}
|
||||
public static long NextLong(this Random random) => random.Next() << 32 & unchecked((uint)random.Next());
|
||||
}
|
||||
}
|
|
@ -143,10 +143,7 @@ namespace DotNetty.Common.Utilities
|
|||
/// intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the
|
||||
/// intended use case.
|
||||
/// </summary>
|
||||
public static T ReleaseLater<T>(T msg)
|
||||
{
|
||||
return ReleaseLater(msg, 1);
|
||||
}
|
||||
public static T ReleaseLater<T>(T msg) => ReleaseLater(msg, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Schedules the specified object to be released when the caller thread terminates. Note that this operation is
|
||||
|
@ -182,7 +179,8 @@ namespace DotNetty.Common.Utilities
|
|||
|
||||
static string FormatReleaseString(IReferenceCounted referenceCounted, int decrement)
|
||||
{
|
||||
return referenceCounted.GetType().Name + ".Release(" + decrement + ") refCnt: " + referenceCounted.ReferenceCount;
|
||||
return referenceCounted.GetType().Name + ".Release(" + decrement.ToString() + ") refCnt: "
|
||||
+ referenceCounted.ReferenceCount.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -145,10 +145,7 @@ namespace DotNetty.Common.Utilities
|
|||
/// <summary>
|
||||
/// Converts the specified byte value into a 2-digit hexadecimal integer.
|
||||
/// </summary>
|
||||
public static string ByteToHexStringPadded(int value)
|
||||
{
|
||||
return Byte2HexPad[value & 0xff];
|
||||
}
|
||||
public static string ByteToHexStringPadded(int value) => Byte2HexPad[value & 0xff];
|
||||
|
||||
//todo: port
|
||||
// /**
|
||||
|
@ -166,10 +163,7 @@ namespace DotNetty.Common.Utilities
|
|||
/// <summary>
|
||||
/// Converts the specified byte array into a hexadecimal value.
|
||||
/// </summary>
|
||||
public static string ToHexStringPadded(byte[] src)
|
||||
{
|
||||
return ToHexStringPadded(src, 0, src.Length);
|
||||
}
|
||||
public static string ToHexStringPadded(byte[] src) => ToHexStringPadded(src, 0, src.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the specified byte array into a hexadecimal value.
|
||||
|
@ -199,30 +193,15 @@ namespace DotNetty.Common.Utilities
|
|||
/// <summary>
|
||||
/// Converts the specified byte value into a hexadecimal integer.
|
||||
/// </summary>
|
||||
public static string ByteToHexString(byte value)
|
||||
{
|
||||
return Byte2HexNopad[value & 0xff];
|
||||
}
|
||||
public static string ByteToHexString(byte value) => Byte2HexNopad[value & 0xff];
|
||||
|
||||
public static StringBuilder ByteToHexString(StringBuilder buf, byte value)
|
||||
{
|
||||
return buf.Append(ByteToHexString(value));
|
||||
}
|
||||
public static StringBuilder ByteToHexString(StringBuilder buf, byte value) => buf.Append(ByteToHexString(value));
|
||||
|
||||
public static string ToHexString(byte[] src)
|
||||
{
|
||||
return ToHexString(src, 0, src.Length);
|
||||
}
|
||||
public static string ToHexString(byte[] src) => ToHexString(src, 0, src.Length);
|
||||
|
||||
public static string ToHexString(byte[] src, int offset, int length)
|
||||
{
|
||||
return ToHexString(new StringBuilder(length << 1), src, offset, length).ToString();
|
||||
}
|
||||
public static string ToHexString(byte[] src, int offset, int length) => ToHexString(new StringBuilder(length << 1), src, offset, length).ToString();
|
||||
|
||||
public static StringBuilder ToHexString(StringBuilder dst, byte[] src)
|
||||
{
|
||||
return ToHexString(dst, src, 0, src.Length);
|
||||
}
|
||||
public static StringBuilder ToHexString(StringBuilder dst, byte[] src) => ToHexString(dst, src, 0, src.Length);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.
|
||||
|
@ -314,35 +293,23 @@ namespace DotNetty.Common.Utilities
|
|||
escaped.Append(DoubleQuote).ToString() : value;
|
||||
}
|
||||
|
||||
static bool IsDoubleQuote(char c)
|
||||
{
|
||||
return c == DoubleQuote;
|
||||
}
|
||||
static bool IsDoubleQuote(char c) => c == DoubleQuote;
|
||||
|
||||
/// <summary>
|
||||
/// The shortcut to <see cref="SimpleClassName(Type)">SimpleClassName(o.GetType())</see>.
|
||||
/// </summary>
|
||||
public static string SimpleClassName(object o)
|
||||
{
|
||||
return o == null ? "null_object" : o.GetType().Name;
|
||||
}
|
||||
public static string SimpleClassName(object o) => o?.GetType().Name ?? "null_object";
|
||||
|
||||
/// <summary>
|
||||
/// The shortcut to <see cref="SimpleClassName(Type)">SimpleClassName(o.GetType())</see>.
|
||||
/// </summary>
|
||||
public static string SimpleClassName<T>()
|
||||
{
|
||||
return typeof(T).Name;
|
||||
}
|
||||
public static string SimpleClassName<T>() => typeof(T).Name;
|
||||
|
||||
/// <summary>
|
||||
/// Generates a simplified name from a <see cref="Type" />. Similar to {@link Class#getSimpleName()}, but it works
|
||||
/// fine
|
||||
/// with anonymous classes.
|
||||
/// </summary>
|
||||
public static string SimpleClassName(Type type)
|
||||
{
|
||||
return type.Name;
|
||||
}
|
||||
public static string SimpleClassName(Type type) => type.Name;
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ namespace DotNetty.Common.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
class LinkOutcomeActionHost<T>
|
||||
static class LinkOutcomeActionHost<T>
|
||||
{
|
||||
public static readonly Action<Task<T>, object> Action =
|
||||
(t, tcs) =>
|
||||
|
|
|
@ -7,9 +7,6 @@ namespace DotNetty.Handlers.Logging
|
|||
|
||||
public static class LogLevelExtensions
|
||||
{
|
||||
public static InternalLogLevel ToInternalLevel(this LogLevel level)
|
||||
{
|
||||
return (InternalLogLevel)level;
|
||||
}
|
||||
public static InternalLogLevel ToInternalLevel(this LogLevel level) => (InternalLogLevel)level;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ namespace DotNetty.Handlers.Logging
|
|||
|
||||
protected readonly InternalLogLevel InternalLevel;
|
||||
protected readonly IInternalLogger Logger;
|
||||
readonly LogLevel level;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance whose logger name is the fully qualified class
|
||||
|
@ -65,7 +64,7 @@ namespace DotNetty.Handlers.Logging
|
|||
}
|
||||
|
||||
this.Logger = InternalLoggerFactory.GetInstance(type);
|
||||
this.level = level;
|
||||
this.Level = level;
|
||||
this.InternalLevel = level.ToInternalLevel();
|
||||
}
|
||||
|
||||
|
@ -91,14 +90,14 @@ namespace DotNetty.Handlers.Logging
|
|||
}
|
||||
|
||||
this.Logger = InternalLoggerFactory.GetInstance(name);
|
||||
this.level = level;
|
||||
this.Level = level;
|
||||
this.InternalLevel = level.ToInternalLevel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="LogLevel" /> that this handler uses to log
|
||||
/// </summary>
|
||||
public LogLevel Level => this.level;
|
||||
public LogLevel Level { get; }
|
||||
|
||||
public override void ChannelRegistered(IChannelHandlerContext ctx)
|
||||
{
|
||||
|
|
|
@ -53,37 +53,19 @@ namespace DotNetty.Handlers.Tls
|
|||
this.sslStream = new SslStream(this.mediationStream, true, certificateValidationCallback);
|
||||
}
|
||||
|
||||
public static TlsHandler Client(string targetHost)
|
||||
{
|
||||
return new TlsHandler(false, null, targetHost, null);
|
||||
}
|
||||
public static TlsHandler Client(string targetHost) => new TlsHandler(false, null, targetHost, null);
|
||||
|
||||
public static TlsHandler Client(string targetHost, X509Certificate2 certificate)
|
||||
{
|
||||
return new TlsHandler(false, certificate, targetHost, null);
|
||||
}
|
||||
public static TlsHandler Client(string targetHost, X509Certificate2 certificate) => new TlsHandler(false, certificate, targetHost, null);
|
||||
|
||||
public static TlsHandler Client(string targetHost, X509Certificate2 certificate, RemoteCertificateValidationCallback certificateValidationCallback)
|
||||
{
|
||||
return new TlsHandler(false, certificate, targetHost, certificateValidationCallback);
|
||||
}
|
||||
public static TlsHandler Client(string targetHost, X509Certificate2 certificate, RemoteCertificateValidationCallback certificateValidationCallback) => new TlsHandler(false, certificate, targetHost, certificateValidationCallback);
|
||||
|
||||
public static TlsHandler Server(X509Certificate2 certificate)
|
||||
{
|
||||
return new TlsHandler(true, certificate, null, null);
|
||||
}
|
||||
public static TlsHandler Server(X509Certificate2 certificate) => new TlsHandler(true, certificate, null, null);
|
||||
|
||||
public X509Certificate LocalCertificate => this.sslStream.LocalCertificate;
|
||||
|
||||
public X509Certificate RemoteCertificate => this.sslStream.RemoteCertificate;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.sslStream != null)
|
||||
{
|
||||
this.sslStream.Dispose();
|
||||
}
|
||||
}
|
||||
public void Dispose() => this.sslStream?.Dispose();
|
||||
|
||||
public override void ChannelActive(IChannelHandlerContext context)
|
||||
{
|
||||
|
@ -448,11 +430,7 @@ namespace DotNetty.Handlers.Tls
|
|||
this.pendingReadBuffer = input;
|
||||
}
|
||||
|
||||
AsyncCallback callback = this.readCallback;
|
||||
if (callback != null)
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
this.readCallback?.Invoke(tcs.Task);
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
|
@ -506,10 +484,7 @@ namespace DotNetty.Handlers.Tls
|
|||
}
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
this.owner.FinishWrap(buffer, offset, count);
|
||||
}
|
||||
public override void Write(byte[] buffer, int offset, int count) => this.owner.FinishWrap(buffer, offset, count);
|
||||
|
||||
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
|
@ -549,10 +524,7 @@ namespace DotNetty.Handlers.Tls
|
|||
throw new ArgumentOutOfRangeException("Unexpected task status: " + writeTask.Status);
|
||||
}
|
||||
|
||||
if (self.writeCallback != null)
|
||||
{
|
||||
self.writeCallback(self.writeCompletion.Task);
|
||||
}
|
||||
self.writeCallback?.Invoke(self.writeCompletion.Task);
|
||||
}
|
||||
|
||||
public override void EndWrite(IAsyncResult asyncResult)
|
||||
|
|
|
@ -75,10 +75,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
/// {@link Channel} implementation has no no-args constructor.
|
||||
/// </summary>
|
||||
public TBootstrap Channel<T>()
|
||||
where T : TChannel, new()
|
||||
{
|
||||
return this.ChannelFactory(() => new T());
|
||||
}
|
||||
where T : TChannel, new() => this.ChannelFactory(() => new T());
|
||||
|
||||
public TBootstrap ChannelFactory(Func<TChannel> channelFactory)
|
||||
{
|
||||
|
@ -99,26 +96,17 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
/// <summary>
|
||||
/// @see {@link #localAddress(SocketAddress)}
|
||||
/// </summary>
|
||||
public TBootstrap LocalAddress(int inetPort)
|
||||
{
|
||||
return this.LocalAddress(new IPEndPoint(IPAddress.Any, inetPort));
|
||||
}
|
||||
public TBootstrap LocalAddress(int inetPort) => this.LocalAddress(new IPEndPoint(IPAddress.Any, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// @see {@link #localAddress(SocketAddress)}
|
||||
/// </summary>
|
||||
public TBootstrap LocalAddress(string inetHost, int inetPort)
|
||||
{
|
||||
return this.LocalAddress(new DnsEndPoint(inetHost, inetPort));
|
||||
}
|
||||
public TBootstrap LocalAddress(string inetHost, int inetPort) => this.LocalAddress(new DnsEndPoint(inetHost, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// @see {@link #localAddress(SocketAddress)}
|
||||
/// </summary>
|
||||
public TBootstrap LocalAddress(IPAddress inetHost, int inetPort)
|
||||
{
|
||||
return this.LocalAddress(new IPEndPoint(inetHost, inetPort));
|
||||
}
|
||||
public TBootstrap LocalAddress(IPAddress inetHost, int inetPort) => this.LocalAddress(new IPEndPoint(inetHost, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// Allow to specify a {@link ChannelOption} which is used for the {@link Channel} instances once they got
|
||||
|
@ -170,7 +158,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
/// <summary>
|
||||
/// Create a new {@link Channel} and register it with an {@link EventLoop}.
|
||||
/// </summary>
|
||||
public Task Register()
|
||||
public Task RegisterAsync()
|
||||
{
|
||||
this.Validate();
|
||||
return this.InitAndRegisterAsync();
|
||||
|
@ -187,32 +175,23 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
{
|
||||
throw new InvalidOperationException("localAddress must be set beforehand.");
|
||||
}
|
||||
return this.DoBind(address);
|
||||
return this.DoBindAsync(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new {@link Channel} and bind it.
|
||||
/// </summary>
|
||||
public Task<IChannel> BindAsync(int inetPort)
|
||||
{
|
||||
return this.BindAsync(new IPEndPoint(IPAddress.Any, inetPort));
|
||||
}
|
||||
public Task<IChannel> BindAsync(int inetPort) => this.BindAsync(new IPEndPoint(IPAddress.Any, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// Create a new {@link Channel} and bind it.
|
||||
/// </summary>
|
||||
public Task<IChannel> BindAsync(string inetHost, int inetPort)
|
||||
{
|
||||
return this.BindAsync(new DnsEndPoint(inetHost, inetPort));
|
||||
}
|
||||
public Task<IChannel> BindAsync(string inetHost, int inetPort) => this.BindAsync(new DnsEndPoint(inetHost, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// Create a new {@link Channel} and bind it.
|
||||
/// </summary>
|
||||
public Task<IChannel> BindAsync(IPAddress inetHost, int inetPort)
|
||||
{
|
||||
return this.BindAsync(new IPEndPoint(inetHost, inetPort));
|
||||
}
|
||||
public Task<IChannel> BindAsync(IPAddress inetHost, int inetPort) => this.BindAsync(new IPEndPoint(inetHost, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// Create a new {@link Channel} and bind it.
|
||||
|
@ -222,13 +201,13 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
this.Validate();
|
||||
Contract.Requires(localAddress != null);
|
||||
|
||||
return this.DoBind(localAddress);
|
||||
return this.DoBindAsync(localAddress);
|
||||
}
|
||||
|
||||
async Task<IChannel> DoBind(EndPoint localAddress)
|
||||
async Task<IChannel> DoBindAsync(EndPoint localAddress)
|
||||
{
|
||||
IChannel channel = await this.InitAndRegisterAsync();
|
||||
await DoBind0(channel, localAddress);
|
||||
await DoBind0Async(channel, localAddress);
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
@ -276,7 +255,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
return channel;
|
||||
}
|
||||
|
||||
static Task DoBind0(IChannel channel, EndPoint localAddress)
|
||||
static Task DoBind0Async(IChannel channel, EndPoint localAddress)
|
||||
{
|
||||
// This method is invoked before channelRegistered() is triggered. Give user handlers a chance to set up
|
||||
// the pipeline in its channelRegistered() implementation.
|
||||
|
@ -308,28 +287,16 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
return (TBootstrap)this;
|
||||
}
|
||||
|
||||
protected EndPoint LocalAddress()
|
||||
{
|
||||
return this.localAddress;
|
||||
}
|
||||
protected EndPoint LocalAddress() => this.localAddress;
|
||||
|
||||
protected IChannelHandler Handler()
|
||||
{
|
||||
return this.handler;
|
||||
}
|
||||
protected IChannelHandler Handler() => this.handler;
|
||||
|
||||
/// <summary>
|
||||
/// Return the configured {@link EventLoopGroup} or {@code null} if non is configured yet.
|
||||
/// </summary>
|
||||
public IEventLoopGroup Group()
|
||||
{
|
||||
return this.group;
|
||||
}
|
||||
public IEventLoopGroup Group() => this.group;
|
||||
|
||||
protected IDictionary<ChannelOption, object> Options()
|
||||
{
|
||||
return this.options;
|
||||
}
|
||||
protected IDictionary<ChannelOption, object> Options() => this.options;
|
||||
|
||||
// todo: attr
|
||||
//Dictionary<AttributeKey, object> attrs()
|
||||
|
|
|
@ -92,24 +92,18 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
throw new InvalidOperationException("remoteAddress not set");
|
||||
}
|
||||
|
||||
return this.DoResolveAndConnect(remoteAddress, this.LocalAddress());
|
||||
return this.DoResolveAndConnectAsync(remoteAddress, this.LocalAddress());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect a {@link Channel} to the remote peer.
|
||||
/// </summary>
|
||||
public Task<IChannel> ConnectAsync(string inetHost, int inetPort)
|
||||
{
|
||||
return this.ConnectAsync(new DnsEndPoint(inetHost, inetPort));
|
||||
}
|
||||
public Task<IChannel> ConnectAsync(string inetHost, int inetPort) => this.ConnectAsync(new DnsEndPoint(inetHost, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// Connect a {@link Channel} to the remote peer.
|
||||
/// </summary>
|
||||
public Task<IChannel> ConnectAsync(IPAddress inetHost, int inetPort)
|
||||
{
|
||||
return this.ConnectAsync(new IPEndPoint(inetHost, inetPort));
|
||||
}
|
||||
public Task<IChannel> ConnectAsync(IPAddress inetHost, int inetPort) => this.ConnectAsync(new IPEndPoint(inetHost, inetPort));
|
||||
|
||||
/// <summary>
|
||||
/// Connect a {@link Channel} to the remote peer.
|
||||
|
@ -119,7 +113,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
Contract.Requires(remoteAddress != null);
|
||||
|
||||
this.Validate();
|
||||
return this.DoResolveAndConnect(remoteAddress, this.LocalAddress());
|
||||
return this.DoResolveAndConnectAsync(remoteAddress, this.LocalAddress());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -130,20 +124,20 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
Contract.Requires(remoteAddress != null);
|
||||
|
||||
this.Validate();
|
||||
return this.DoResolveAndConnect(remoteAddress, localAddress);
|
||||
return this.DoResolveAndConnectAsync(remoteAddress, localAddress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @see {@link #connect()}
|
||||
/// </summary>
|
||||
async Task<IChannel> DoResolveAndConnect(EndPoint remoteAddress, EndPoint localAddress)
|
||||
async Task<IChannel> DoResolveAndConnectAsync(EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
IChannel channel = await this.InitAndRegisterAsync();
|
||||
|
||||
if (this.resolver.IsResolved(remoteAddress))
|
||||
{
|
||||
// Resolver has no idea about what to do with the specified remote address or it's resolved already.
|
||||
await DoConnect(channel, remoteAddress, localAddress);
|
||||
await DoConnectAsync(channel, remoteAddress, localAddress);
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
@ -158,11 +152,11 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
throw;
|
||||
}
|
||||
|
||||
await DoConnect(channel, resolvedAddress, localAddress);
|
||||
await DoConnectAsync(channel, resolvedAddress, localAddress);
|
||||
return channel;
|
||||
}
|
||||
|
||||
static Task DoConnect(IChannel channel,
|
||||
static Task DoConnectAsync(IChannel channel,
|
||||
EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
// This method is invoked before channelRegistered() is triggered. Give user handlers a chance to set up
|
||||
|
@ -232,10 +226,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
return this;
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new Bootstrap(this);
|
||||
}
|
||||
public override object Clone() => new Bootstrap(this);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a deep clone of this bootstrap which has the identical configuration except that it uses
|
||||
|
|
|
@ -8,10 +8,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
|
||||
public class DefaultNameResolver : INameResolver
|
||||
{
|
||||
public bool IsResolved(EndPoint address)
|
||||
{
|
||||
return !(address is DnsEndPoint);
|
||||
}
|
||||
public bool IsResolved(EndPoint address) => !(address is DnsEndPoint);
|
||||
|
||||
public async Task<EndPoint> ResolveAsync(EndPoint address)
|
||||
{
|
||||
|
|
|
@ -49,10 +49,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
/// <summary>
|
||||
/// Specify the {@link EventLoopGroup} which is used for the parent (acceptor) and the child (client).
|
||||
/// </summary>
|
||||
public override ServerBootstrap Group(IEventLoopGroup group)
|
||||
{
|
||||
return this.Group(group, group);
|
||||
}
|
||||
public override ServerBootstrap Group(IEventLoopGroup group) => this.Group(@group, @group);
|
||||
|
||||
/// <summary>
|
||||
/// Set the {@link EventLoopGroup} for the parent (acceptor) and the child (client). These
|
||||
|
@ -124,10 +121,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
/// Return the configured {@link EventLoopGroup} which will be used for the child channels or {@code null}
|
||||
/// if non is configured yet.
|
||||
/// </summary>
|
||||
public IEventLoopGroup ChildGroup()
|
||||
{
|
||||
return this.childGroup;
|
||||
}
|
||||
public IEventLoopGroup ChildGroup() => this.childGroup;
|
||||
|
||||
protected override void Init(IChannel channel)
|
||||
{
|
||||
|
@ -306,10 +300,7 @@ namespace DotNetty.Transport.Bootstrapping
|
|||
}
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new ServerBootstrap(this);
|
||||
}
|
||||
public override object Clone() => new ServerBootstrap(this);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
|
@ -168,35 +168,17 @@ namespace DotNetty.Transport.Channels
|
|||
/// <see cref="IChannelId"/>s to <see cref="IChannel"/>s that use the <see cref="AbstractChannel"/> constructor.
|
||||
protected IChannelId NewId() => DefaultChannelId.NewInstance();
|
||||
|
||||
public virtual Task BindAsync(EndPoint localAddress)
|
||||
{
|
||||
return this.pipeline.BindAsync(localAddress);
|
||||
}
|
||||
public virtual Task BindAsync(EndPoint localAddress) => this.pipeline.BindAsync(localAddress);
|
||||
|
||||
public virtual Task ConnectAsync(EndPoint remoteAddress)
|
||||
{
|
||||
return this.pipeline.ConnectAsync(remoteAddress);
|
||||
}
|
||||
public virtual Task ConnectAsync(EndPoint remoteAddress) => this.pipeline.ConnectAsync(remoteAddress);
|
||||
|
||||
public virtual Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
return this.pipeline.ConnectAsync(remoteAddress, localAddress);
|
||||
}
|
||||
public virtual Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress) => this.pipeline.ConnectAsync(remoteAddress, localAddress);
|
||||
|
||||
public virtual Task DisconnectAsync()
|
||||
{
|
||||
return this.pipeline.DisconnectAsync();
|
||||
}
|
||||
public virtual Task DisconnectAsync() => this.pipeline.DisconnectAsync();
|
||||
|
||||
public virtual Task CloseAsync()
|
||||
{
|
||||
return this.pipeline.CloseAsync();
|
||||
}
|
||||
public virtual Task CloseAsync() => this.pipeline.CloseAsync();
|
||||
|
||||
public Task DeregisterAsync()
|
||||
{
|
||||
return this.pipeline.DeregisterAsync();
|
||||
}
|
||||
public Task DeregisterAsync() => this.pipeline.DeregisterAsync();
|
||||
|
||||
public IChannel Flush()
|
||||
{
|
||||
|
@ -210,15 +192,9 @@ namespace DotNetty.Transport.Channels
|
|||
return this;
|
||||
}
|
||||
|
||||
public Task WriteAsync(object msg)
|
||||
{
|
||||
return this.pipeline.WriteAsync(msg);
|
||||
}
|
||||
public Task WriteAsync(object msg) => this.pipeline.WriteAsync(msg);
|
||||
|
||||
public Task WriteAndFlushAsync(object message)
|
||||
{
|
||||
return this.pipeline.WriteAndFlushAsync(message);
|
||||
}
|
||||
public Task WriteAndFlushAsync(object message) => this.pipeline.WriteAndFlushAsync(message);
|
||||
|
||||
public Task CloseCompletion => this.closeFuture.Task;
|
||||
|
||||
|
@ -387,7 +363,7 @@ namespace DotNetty.Transport.Channels
|
|||
{
|
||||
// check if the channel is still open as it could be closed input the mean time when the register
|
||||
// call was outside of the eventLoop
|
||||
if (!promise.setUncancellable() || !this.EnsureOpen(promise))
|
||||
if (!promise.SetUncancellable() || !this.EnsureOpen(promise))
|
||||
{
|
||||
Util.SafeSetFailure(promise, ClosedChannelException, Logger);
|
||||
return;
|
||||
|
@ -478,11 +454,6 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
public abstract Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress);
|
||||
|
||||
void SafeSetFailure(TaskCompletionSource promise, Exception cause)
|
||||
{
|
||||
Util.SafeSetFailure(promise, cause, Logger);
|
||||
}
|
||||
|
||||
public Task DisconnectAsync()
|
||||
{
|
||||
this.AssertEventLoop();
|
||||
|
@ -508,11 +479,6 @@ namespace DotNetty.Transport.Channels
|
|||
return TaskEx.Completed;
|
||||
}
|
||||
|
||||
void SafeSetSuccess(TaskCompletionSource promise)
|
||||
{
|
||||
Util.SafeSetSuccess(promise, Logger);
|
||||
}
|
||||
|
||||
public Task CloseAsync() /*CancellationToken cancellationToken) */
|
||||
{
|
||||
this.AssertEventLoop();
|
||||
|
@ -523,7 +489,7 @@ namespace DotNetty.Transport.Channels
|
|||
Task CloseAsync(Exception cause, bool notify)
|
||||
{
|
||||
var promise = new TaskCompletionSource();
|
||||
if (!promise.setUncancellable())
|
||||
if (!promise.SetUncancellable())
|
||||
{
|
||||
return promise.Task;
|
||||
}
|
||||
|
@ -604,19 +570,16 @@ namespace DotNetty.Transport.Channels
|
|||
{
|
||||
this.channel.DoClose();
|
||||
this.channel.closeFuture.Complete();
|
||||
this.SafeSetSuccess(promise);
|
||||
Util.SafeSetSuccess(promise, Logger);
|
||||
}
|
||||
catch (Exception t)
|
||||
{
|
||||
this.channel.closeFuture.Complete();
|
||||
this.SafeSetFailure(promise, t);
|
||||
Util.SafeSetFailure(promise, t, Logger);
|
||||
}
|
||||
}
|
||||
|
||||
void FireChannelInactiveAndDeregister(bool wasActive)
|
||||
{
|
||||
this.DeregisterAsync(wasActive && !this.channel.Active);
|
||||
}
|
||||
void FireChannelInactiveAndDeregister(bool wasActive) => this.DeregisterAsync(wasActive && !this.channel.Active);
|
||||
|
||||
public void CloseForcibly()
|
||||
{
|
||||
|
@ -942,9 +905,6 @@ namespace DotNetty.Transport.Channels
|
|||
/// Invoked when a new message is added to a {@link ChannelOutboundBuffer} of this {@link AbstractChannel}, so that
|
||||
/// the {@link Channel} implementation converts the message to another. (e.g. heap buffer -> direct buffer)
|
||||
/// </summary>
|
||||
protected virtual object FilterOutboundMessage(object msg)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
protected virtual object FilterOutboundMessage(object msg) => msg;
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ namespace DotNetty.Transport.Channels
|
|||
handler.GetType(),
|
||||
handlerType => Tuple.Create(CalculateSkipPropagationFlags(handlerType)));
|
||||
|
||||
return skipDirection == null ? 0 : skipDirection.Item1;
|
||||
return skipDirection?.Item1 ?? 0;
|
||||
}
|
||||
|
||||
protected static int CalculateSkipPropagationFlags(Type handlerType)
|
||||
|
@ -284,8 +284,7 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
public Task WriteAndFlushAsync(object message) // todo: cancellationToken?
|
||||
{
|
||||
AbstractChannelHandlerContext target;
|
||||
target = this.FindContextOutbound();
|
||||
AbstractChannelHandlerContext target = this.FindContextOutbound();
|
||||
Task writeFuture = target.Invoker.InvokeWriteAsync(target, this.pipeline.Touch(message, target));
|
||||
target = this.FindContextOutbound();
|
||||
target.Invoker.InvokeFlush(target);
|
||||
|
@ -298,10 +297,7 @@ namespace DotNetty.Transport.Channels
|
|||
return next.Invoker.InvokeBindAsync(next, localAddress);
|
||||
}
|
||||
|
||||
public Task ConnectAsync(EndPoint remoteAddress)
|
||||
{
|
||||
return this.ConnectAsync(remoteAddress, null);
|
||||
}
|
||||
public Task ConnectAsync(EndPoint remoteAddress) => this.ConnectAsync(remoteAddress, null);
|
||||
|
||||
public Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
|
|
|
@ -18,9 +18,6 @@ namespace DotNetty.Transport.Channels
|
|||
this.initializationAction = initializationAction;
|
||||
}
|
||||
|
||||
protected override void InitChannel(T channel)
|
||||
{
|
||||
this.initializationAction(channel);
|
||||
}
|
||||
protected override void InitChannel(T channel) => this.initializationAction(channel);
|
||||
}
|
||||
}
|
|
@ -12,46 +12,25 @@ namespace DotNetty.Transport.Channels
|
|||
internal bool Added;
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelRegistered(IChannelHandlerContext context)
|
||||
{
|
||||
context.FireChannelRegistered();
|
||||
}
|
||||
public virtual void ChannelRegistered(IChannelHandlerContext context) => context.FireChannelRegistered();
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelUnregistered(IChannelHandlerContext context)
|
||||
{
|
||||
context.FireChannelUnregistered();
|
||||
}
|
||||
public virtual void ChannelUnregistered(IChannelHandlerContext context) => context.FireChannelUnregistered();
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelActive(IChannelHandlerContext context)
|
||||
{
|
||||
context.FireChannelActive();
|
||||
}
|
||||
public virtual void ChannelActive(IChannelHandlerContext context) => context.FireChannelActive();
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelInactive(IChannelHandlerContext context)
|
||||
{
|
||||
context.FireChannelInactive();
|
||||
}
|
||||
public virtual void ChannelInactive(IChannelHandlerContext context) => context.FireChannelInactive();
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelRead(IChannelHandlerContext context, object message)
|
||||
{
|
||||
context.FireChannelRead(message);
|
||||
}
|
||||
public virtual void ChannelRead(IChannelHandlerContext context, object message) => context.FireChannelRead(message);
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelReadComplete(IChannelHandlerContext context)
|
||||
{
|
||||
context.FireChannelReadComplete();
|
||||
}
|
||||
public virtual void ChannelReadComplete(IChannelHandlerContext context) => context.FireChannelReadComplete();
|
||||
|
||||
[Skip]
|
||||
public virtual void ChannelWritabilityChanged(IChannelHandlerContext context)
|
||||
{
|
||||
context.FireChannelWritabilityChanged();
|
||||
}
|
||||
public virtual void ChannelWritabilityChanged(IChannelHandlerContext context) => context.FireChannelWritabilityChanged();
|
||||
|
||||
[Skip]
|
||||
public virtual void HandlerAdded(IChannelHandlerContext context)
|
||||
|
@ -64,64 +43,34 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
|
||||
[Skip]
|
||||
public virtual void UserEventTriggered(IChannelHandlerContext context, object evt)
|
||||
{
|
||||
context.FireUserEventTriggered(evt);
|
||||
}
|
||||
public virtual void UserEventTriggered(IChannelHandlerContext context, object evt) => context.FireUserEventTriggered(evt);
|
||||
|
||||
[Skip]
|
||||
public virtual Task WriteAsync(IChannelHandlerContext context, object message)
|
||||
{
|
||||
return context.WriteAsync(message);
|
||||
}
|
||||
public virtual Task WriteAsync(IChannelHandlerContext context, object message) => context.WriteAsync(message);
|
||||
|
||||
[Skip]
|
||||
public virtual void Flush(IChannelHandlerContext context)
|
||||
{
|
||||
context.Flush();
|
||||
}
|
||||
public virtual void Flush(IChannelHandlerContext context) => context.Flush();
|
||||
|
||||
[Skip]
|
||||
public virtual Task BindAsync(IChannelHandlerContext context, EndPoint localAddress)
|
||||
{
|
||||
return context.BindAsync(localAddress);
|
||||
}
|
||||
public virtual Task BindAsync(IChannelHandlerContext context, EndPoint localAddress) => context.BindAsync(localAddress);
|
||||
|
||||
[Skip]
|
||||
public virtual Task ConnectAsync(IChannelHandlerContext context, EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
return context.ConnectAsync(remoteAddress, localAddress);
|
||||
}
|
||||
public virtual Task ConnectAsync(IChannelHandlerContext context, EndPoint remoteAddress, EndPoint localAddress) => context.ConnectAsync(remoteAddress, localAddress);
|
||||
|
||||
[Skip]
|
||||
public virtual Task DisconnectAsync(IChannelHandlerContext context)
|
||||
{
|
||||
return context.DisconnectAsync();
|
||||
}
|
||||
public virtual Task DisconnectAsync(IChannelHandlerContext context) => context.DisconnectAsync();
|
||||
|
||||
[Skip]
|
||||
public virtual Task CloseAsync(IChannelHandlerContext context)
|
||||
{
|
||||
return context.CloseAsync();
|
||||
}
|
||||
public virtual Task CloseAsync(IChannelHandlerContext context) => context.CloseAsync();
|
||||
|
||||
[Skip]
|
||||
public virtual void ExceptionCaught(IChannelHandlerContext context, Exception exception)
|
||||
{
|
||||
context.FireExceptionCaught(exception);
|
||||
}
|
||||
public virtual void ExceptionCaught(IChannelHandlerContext context, Exception exception) => context.FireExceptionCaught(exception);
|
||||
|
||||
[Skip]
|
||||
public virtual Task DeregisterAsync(IChannelHandlerContext context)
|
||||
{
|
||||
return context.DeregisterAsync();
|
||||
}
|
||||
public virtual Task DeregisterAsync(IChannelHandlerContext context) => context.DeregisterAsync();
|
||||
|
||||
[Skip]
|
||||
public virtual void Read(IChannelHandlerContext context)
|
||||
{
|
||||
context.Read();
|
||||
}
|
||||
public virtual void Read(IChannelHandlerContext context) => context.Read();
|
||||
|
||||
public virtual bool IsSharable => false;
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
public static Task InvokeBindAsyncNow(
|
||||
public static Task InvokeBindNowAsync(
|
||||
IChannelHandlerContext ctx, EndPoint localAddress)
|
||||
{
|
||||
try
|
||||
|
@ -137,7 +137,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
public static Task InvokeConnectAsyncNow(
|
||||
public static Task InvokeConnectNowAsync(
|
||||
IChannelHandlerContext ctx,
|
||||
EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
public static Task InvokeDisconnectAsyncNow(IChannelHandlerContext ctx)
|
||||
public static Task InvokeDisconnectNowAsync(IChannelHandlerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
public static Task InvokeCloseAsyncNow(IChannelHandlerContext ctx)
|
||||
public static Task InvokeCloseNowAsync(IChannelHandlerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -175,7 +175,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
public static Task InvokeDeregisterAsyncNow(IChannelHandlerContext ctx)
|
||||
public static Task InvokeDeregisterNowAsync(IChannelHandlerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -199,7 +199,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
public static Task InvokeWriteAsyncNow(IChannelHandlerContext ctx, object msg)
|
||||
public static Task InvokeWriteNowAsync(IChannelHandlerContext ctx, object msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -239,10 +239,7 @@ namespace DotNetty.Transport.Channels
|
|||
InvokeExceptionCaughtNow(ctx, cause);
|
||||
}
|
||||
|
||||
static Task ComposeExceptionTask(Exception cause)
|
||||
{
|
||||
return TaskEx.FromException(cause);
|
||||
}
|
||||
static Task ComposeExceptionTask(Exception cause) => TaskEx.FromException(cause);
|
||||
|
||||
// todo: use "nameof" once available
|
||||
static readonly string ExceptionCaughtMethodName = ((MethodCallExpression)((Expression<Action<IChannelHandler>>)(_ => _.ExceptionCaught(null, null))).Body).Method.Name;
|
||||
|
|
|
@ -48,14 +48,8 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
public sealed class ChannelOption<T> : ChannelOption
|
||||
{
|
||||
public void Validate(T value)
|
||||
{
|
||||
Contract.Requires(value != null);
|
||||
}
|
||||
public void Validate(T value) => Contract.Requires(value != null);
|
||||
|
||||
public override bool Set(IChannelConfiguration configuration, object value)
|
||||
{
|
||||
return configuration.SetOption(this, (T)value);
|
||||
}
|
||||
public override bool Set(IChannelConfiguration configuration, object value) => configuration.SetOption(this, (T)value);
|
||||
}
|
||||
}
|
|
@ -96,7 +96,7 @@ namespace DotNetty.Transport.Channels
|
|||
do
|
||||
{
|
||||
this.flushed++;
|
||||
if (!entry.Promise.setUncancellable())
|
||||
if (!entry.Promise.SetUncancellable())
|
||||
{
|
||||
// Was cancelled so make sure we free up memory and notify about the freed bytes
|
||||
int pending = entry.Cancel();
|
||||
|
@ -326,7 +326,6 @@ namespace DotNetty.Transport.Channels
|
|||
public List<ArraySegment<byte>> GetNioBuffers()
|
||||
{
|
||||
long nioBufferSize = 0;
|
||||
int nioBufferCount = 0;
|
||||
InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.Get();
|
||||
List<ArraySegment<byte>> nioBuffers = NioBuffers.Get(threadLocalMap);
|
||||
Entry entry = this.flushedEntry;
|
||||
|
|
|
@ -92,10 +92,7 @@ namespace DotNetty.Transport.Channels
|
|||
return default(T);
|
||||
}
|
||||
|
||||
public bool SetOption(ChannelOption option, object value)
|
||||
{
|
||||
return option.Set(this, value);
|
||||
}
|
||||
public bool SetOption(ChannelOption option, object value) => option.Set(this, value);
|
||||
|
||||
public virtual bool SetOption<T>(ChannelOption<T> option, T value)
|
||||
{
|
||||
|
|
|
@ -169,11 +169,11 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
if (this.executor.InEventLoop)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress);
|
||||
return ChannelHandlerInvokerUtil.InvokeBindNowAsync(ctx, localAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress));
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeBindNowAsync(ctx, localAddress));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,11 +190,11 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
if (this.executor.InEventLoop)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeConnectAsyncNow(ctx, remoteAddress, localAddress);
|
||||
return ChannelHandlerInvokerUtil.InvokeConnectNowAsync(ctx, remoteAddress, localAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeConnectAsyncNow(ctx, remoteAddress, localAddress));
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeConnectNowAsync(ctx, remoteAddress, localAddress));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,11 +208,11 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
if (this.executor.InEventLoop)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeDisconnectAsyncNow(ctx);
|
||||
return ChannelHandlerInvokerUtil.InvokeDisconnectNowAsync(ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeDisconnectAsyncNow(ctx));
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeDisconnectNowAsync(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,11 +226,11 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
if (this.executor.InEventLoop)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeCloseAsyncNow(ctx);
|
||||
return ChannelHandlerInvokerUtil.InvokeCloseNowAsync(ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeCloseAsyncNow(ctx));
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeCloseNowAsync(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,11 +244,11 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
if (this.executor.InEventLoop)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeDeregisterAsyncNow(ctx);
|
||||
return ChannelHandlerInvokerUtil.InvokeDeregisterNowAsync(ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeDeregisterAsyncNow(ctx));
|
||||
return this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeDeregisterNowAsync(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,7 +285,7 @@ namespace DotNetty.Transport.Channels
|
|||
|
||||
if (this.executor.InEventLoop)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg);
|
||||
return ChannelHandlerInvokerUtil.InvokeWriteNowAsync(ctx, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -419,7 +419,7 @@ namespace DotNetty.Transport.Channels
|
|||
{
|
||||
buffer?.DecrementPendingOutboundBytes(this.size);
|
||||
}
|
||||
ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(this.ctx, this.msg).LinkOutcome(this.promise);
|
||||
ChannelHandlerInvokerUtil.InvokeWriteNowAsync(this.ctx, this.msg).LinkOutcome(this.promise);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -108,10 +108,7 @@ namespace DotNetty.Transport.Channels
|
|||
return asLongText;
|
||||
}
|
||||
|
||||
public int CompareTo(IChannelId other)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public int CompareTo(IChannelId other) => 0;
|
||||
|
||||
static byte[] ParseMachineId(string value)
|
||||
{
|
||||
|
@ -293,10 +290,7 @@ namespace DotNetty.Transport.Channels
|
|||
}
|
||||
}
|
||||
|
||||
static int CompareAddresses(IPAddress current, IPAddress candidate)
|
||||
{
|
||||
return ScoreAddress(current) - ScoreAddress(candidate);
|
||||
}
|
||||
static int CompareAddresses(IPAddress current, IPAddress candidate) => ScoreAddress(current) - ScoreAddress(candidate);
|
||||
|
||||
static int ScoreAddress(IPAddress addr)
|
||||
{
|
||||
|
@ -392,10 +386,7 @@ namespace DotNetty.Transport.Channels
|
|||
return i;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.hashCode;
|
||||
}
|
||||
public override int GetHashCode() => this.hashCode;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
@ -412,9 +403,6 @@ namespace DotNetty.Transport.Channels
|
|||
return Equals(this.data, ((DefaultChannelId)obj).data);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.AsShortText();
|
||||
}
|
||||
public override string ToString() => this.AsShortText();
|
||||
}
|
||||
}
|
|
@ -52,9 +52,6 @@ namespace DotNetty.Transport.Channels
|
|||
this.handle = new HandleImpl(unknownSize);
|
||||
}
|
||||
|
||||
public IMessageSizeEstimatorHandle NewHandle()
|
||||
{
|
||||
return this.handle;
|
||||
}
|
||||
public IMessageSizeEstimatorHandle NewHandle() => this.handle;
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
static readonly IInternalLogger logger = InternalLoggerFactory.GetInstance<EmbeddedChannel>();
|
||||
|
||||
readonly EmbeddedEventLoop loop = new EmbeddedEventLoop();
|
||||
readonly IChannelConfiguration config;
|
||||
|
||||
Queue<object> inboundMessages;
|
||||
Queue<object> outboundMessages;
|
||||
|
@ -75,7 +74,7 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
public EmbeddedChannel(IChannelId id, params IChannelHandler[] handlers)
|
||||
: base(null, id)
|
||||
{
|
||||
this.config = new DefaultChannelConfiguration(this);
|
||||
this.Configuration = new DefaultChannelConfiguration(this);
|
||||
if (handlers == null)
|
||||
{
|
||||
throw new NullReferenceException("handlers cannot be null");
|
||||
|
@ -100,7 +99,7 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
p.AddLast(new LastInboundHandler(this.InboundMessages, this.RecordException));
|
||||
}
|
||||
|
||||
public override IChannelConfiguration Configuration => this.config;
|
||||
public override IChannelConfiguration Configuration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Queue{T}" /> which holds all of the <see cref="object" />s that
|
||||
|
@ -114,15 +113,9 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
/// </summary>
|
||||
public Queue<object> OutboundMessages => this.outboundMessages ?? (this.outboundMessages = new Queue<object>());
|
||||
|
||||
public T ReadInbound<T>()
|
||||
{
|
||||
return (T)Poll(this.inboundMessages);
|
||||
}
|
||||
public T ReadInbound<T>() => (T)Poll(this.inboundMessages);
|
||||
|
||||
public T ReadOutbound<T>()
|
||||
{
|
||||
return (T)Poll(this.outboundMessages);
|
||||
}
|
||||
public T ReadOutbound<T>() => (T)Poll(this.outboundMessages);
|
||||
|
||||
public override bool DisconnectSupported => false;
|
||||
|
||||
|
@ -130,35 +123,20 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
|
||||
protected override EndPoint RemoteAddressInternal => this.Active ? REMOTE_ADDRESS : null;
|
||||
|
||||
protected override IChannelUnsafe NewUnsafe()
|
||||
{
|
||||
return new DefaultUnsafe(this);
|
||||
}
|
||||
protected override IChannelUnsafe NewUnsafe() => new DefaultUnsafe(this);
|
||||
|
||||
protected override bool IsCompatible(IEventLoop eventLoop)
|
||||
{
|
||||
return eventLoop is EmbeddedEventLoop;
|
||||
}
|
||||
protected override bool IsCompatible(IEventLoop eventLoop) => eventLoop is EmbeddedEventLoop;
|
||||
|
||||
protected override void DoBind(EndPoint localAddress)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
protected override void DoRegister()
|
||||
{
|
||||
this.state = State.Active;
|
||||
}
|
||||
protected override void DoRegister() => this.state = State.Active;
|
||||
|
||||
protected override void DoDisconnect()
|
||||
{
|
||||
this.DoClose();
|
||||
}
|
||||
protected override void DoDisconnect() => this.DoClose();
|
||||
|
||||
protected override void DoClose()
|
||||
{
|
||||
this.state = State.Closed;
|
||||
}
|
||||
protected override void DoClose() => this.state = State.Closed;
|
||||
|
||||
protected override void DoBeginRead()
|
||||
{
|
||||
|
@ -370,15 +348,9 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
}
|
||||
}
|
||||
|
||||
static bool IsNotEmpty(Queue<object> queue)
|
||||
{
|
||||
return queue != null && queue.Count > 0;
|
||||
}
|
||||
static bool IsNotEmpty(Queue<object> queue) => queue != null && queue.Count > 0;
|
||||
|
||||
static object Poll(Queue<object> queue)
|
||||
{
|
||||
return IsNotEmpty(queue) ? queue.Dequeue() : null;
|
||||
}
|
||||
static object Poll(Queue<object> queue) => IsNotEmpty(queue) ? queue.Dequeue() : null;
|
||||
|
||||
class DefaultUnsafe : AbstractUnsafe
|
||||
{
|
||||
|
@ -387,10 +359,7 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
{
|
||||
}
|
||||
|
||||
public override Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
return TaskEx.Completed;
|
||||
}
|
||||
public override Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress) => TaskEx.Completed;
|
||||
}
|
||||
|
||||
internal sealed class LastInboundHandler : ChannelHandlerAdapter
|
||||
|
@ -404,17 +373,9 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
this.recordException = recordException;
|
||||
}
|
||||
|
||||
public override void ChannelRead(IChannelHandlerContext context, object message)
|
||||
{
|
||||
// have to pass the EmbeddedChannel.InboundMessages by reference via the constructor
|
||||
this.inboundMessages.Enqueue(message);
|
||||
}
|
||||
public override void ChannelRead(IChannelHandlerContext context, object message) => this.inboundMessages.Enqueue(message);
|
||||
|
||||
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
|
||||
{
|
||||
// have to pass the EmbeddedChannel.RecordException method via reference
|
||||
this.recordException(exception);
|
||||
}
|
||||
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) => this.recordException(exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,15 +16,9 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
{
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public override int GetHashCode() => 0;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is EmbeddedChannelId;
|
||||
}
|
||||
public override bool Equals(object obj) => obj is EmbeddedChannelId;
|
||||
|
||||
public int CompareTo(IChannelId other)
|
||||
{
|
||||
|
@ -35,19 +29,10 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
return string.Compare(this.AsLongText(), other.AsLongText(), StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "embedded";
|
||||
}
|
||||
public override string ToString() => "embedded";
|
||||
|
||||
public string AsShortText()
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
public string AsShortText() => this.ToString();
|
||||
|
||||
public string AsLongText()
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
public string AsLongText() => this.ToString();
|
||||
}
|
||||
}
|
|
@ -19,10 +19,7 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
|
||||
public IChannelHandlerInvoker Invoker => this;
|
||||
|
||||
public Task RegisterAsync(IChannel channel)
|
||||
{
|
||||
return channel.Unsafe.RegisterAsync(this);
|
||||
}
|
||||
public Task RegisterAsync(IChannel channel) => channel.Unsafe.RegisterAsync(this);
|
||||
|
||||
public override bool IsShuttingDown => false;
|
||||
|
||||
|
@ -35,10 +32,7 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
|
||||
public override bool IsTerminated => false;
|
||||
|
||||
public override bool IsInEventLoop(Thread thread)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override bool IsInEventLoop(Thread thread) => true;
|
||||
|
||||
public override void Execute(IRunnable command)
|
||||
{
|
||||
|
@ -54,10 +48,7 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
internal PreciseTimeSpan NextScheduledTask()
|
||||
{
|
||||
return this.NextScheduledTaskNanos();
|
||||
}
|
||||
internal PreciseTimeSpan NextScheduledTask() => this.NextScheduledTaskNanos();
|
||||
|
||||
internal void RunTasks()
|
||||
{
|
||||
|
@ -94,94 +85,40 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
/// <summary>
|
||||
/// YOLO
|
||||
/// </summary>
|
||||
internal new void CancelScheduledTasks()
|
||||
{
|
||||
base.CancelScheduledTasks();
|
||||
}
|
||||
internal new void CancelScheduledTasks() => base.CancelScheduledTasks();
|
||||
|
||||
public void InvokeChannelRegistered(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelRegisteredNow(ctx);
|
||||
}
|
||||
public void InvokeChannelRegistered(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeChannelRegisteredNow(ctx);
|
||||
|
||||
public void InvokeChannelUnregistered(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelUnregisteredNow(ctx);
|
||||
}
|
||||
public void InvokeChannelUnregistered(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeChannelUnregisteredNow(ctx);
|
||||
|
||||
public void InvokeChannelActive(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelActiveNow(ctx);
|
||||
}
|
||||
public void InvokeChannelActive(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeChannelActiveNow(ctx);
|
||||
|
||||
public void InvokeChannelInactive(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelInactiveNow(ctx);
|
||||
}
|
||||
public void InvokeChannelInactive(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeChannelInactiveNow(ctx);
|
||||
|
||||
public void InvokeExceptionCaught(IChannelHandlerContext ctx, Exception cause)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow(ctx, cause);
|
||||
}
|
||||
public void InvokeExceptionCaught(IChannelHandlerContext ctx, Exception cause) => ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow(ctx, cause);
|
||||
|
||||
public void InvokeUserEventTriggered(IChannelHandlerContext ctx, object evt)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeUserEventTriggeredNow(ctx, evt);
|
||||
}
|
||||
public void InvokeUserEventTriggered(IChannelHandlerContext ctx, object evt) => ChannelHandlerInvokerUtil.InvokeUserEventTriggeredNow(ctx, evt);
|
||||
|
||||
public void InvokeChannelRead(IChannelHandlerContext ctx, object msg)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelReadNow(ctx, msg);
|
||||
}
|
||||
public void InvokeChannelRead(IChannelHandlerContext ctx, object msg) => ChannelHandlerInvokerUtil.InvokeChannelReadNow(ctx, msg);
|
||||
|
||||
public void InvokeChannelReadComplete(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelReadCompleteNow(ctx);
|
||||
}
|
||||
public void InvokeChannelReadComplete(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeChannelReadCompleteNow(ctx);
|
||||
|
||||
public void InvokeChannelWritabilityChanged(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeChannelWritabilityChangedNow(ctx);
|
||||
}
|
||||
public void InvokeChannelWritabilityChanged(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeChannelWritabilityChangedNow(ctx);
|
||||
|
||||
public Task InvokeBindAsync(IChannelHandlerContext ctx, EndPoint localAddress)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress);
|
||||
}
|
||||
public Task InvokeBindAsync(IChannelHandlerContext ctx, EndPoint localAddress) => ChannelHandlerInvokerUtil.InvokeBindNowAsync(ctx, localAddress);
|
||||
|
||||
public Task InvokeConnectAsync(IChannelHandlerContext ctx, EndPoint remoteAddress, EndPoint localAddress)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeConnectAsyncNow(ctx, remoteAddress, localAddress);
|
||||
}
|
||||
public Task InvokeConnectAsync(IChannelHandlerContext ctx, EndPoint remoteAddress, EndPoint localAddress) => ChannelHandlerInvokerUtil.InvokeConnectNowAsync(ctx, remoteAddress, localAddress);
|
||||
|
||||
public Task InvokeDisconnectAsync(IChannelHandlerContext ctx)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeDisconnectAsyncNow(ctx);
|
||||
}
|
||||
public Task InvokeDisconnectAsync(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeDisconnectNowAsync(ctx);
|
||||
|
||||
public Task InvokeCloseAsync(IChannelHandlerContext ctx)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeCloseAsyncNow(ctx);
|
||||
}
|
||||
public Task InvokeCloseAsync(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeCloseNowAsync(ctx);
|
||||
|
||||
public Task InvokeDeregisterAsync(IChannelHandlerContext ctx)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeDeregisterAsyncNow(ctx);
|
||||
}
|
||||
public Task InvokeDeregisterAsync(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeDeregisterNowAsync(ctx);
|
||||
|
||||
public void InvokeRead(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeReadNow(ctx);
|
||||
}
|
||||
public void InvokeRead(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeReadNow(ctx);
|
||||
|
||||
public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
|
||||
{
|
||||
return ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg);
|
||||
}
|
||||
public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg) => ChannelHandlerInvokerUtil.InvokeWriteNowAsync(ctx, msg);
|
||||
|
||||
public void InvokeFlush(IChannelHandlerContext ctx)
|
||||
{
|
||||
ChannelHandlerInvokerUtil.InvokeFlushNow(ctx);
|
||||
}
|
||||
public void InvokeFlush(IChannelHandlerContext ctx) => ChannelHandlerInvokerUtil.InvokeFlushNow(ctx);
|
||||
}
|
||||
}
|
|
@ -7,9 +7,6 @@ namespace DotNetty.Transport.Channels.Embedded
|
|||
|
||||
sealed class EmbeddedSocketAddress : EndPoint
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return "embedded";
|
||||
}
|
||||
public override string ToString() => "embedded";
|
||||
}
|
||||
}
|
|
@ -23,15 +23,9 @@ namespace DotNetty.Transport.Channels
|
|||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
public IByteBuffer Allocate(IByteBufferAllocator alloc)
|
||||
{
|
||||
return alloc.Buffer(this.bufferSize);
|
||||
}
|
||||
public IByteBuffer Allocate(IByteBufferAllocator alloc) => alloc.Buffer(this.bufferSize);
|
||||
|
||||
public int Guess()
|
||||
{
|
||||
return this.bufferSize;
|
||||
}
|
||||
public int Guess() => this.bufferSize;
|
||||
|
||||
public void Record(int actualReadBytes)
|
||||
{
|
||||
|
@ -51,9 +45,6 @@ namespace DotNetty.Transport.Channels
|
|||
this.handle = new HandleImpl(bufferSize);
|
||||
}
|
||||
|
||||
public IRecvByteBufAllocatorHandle NewHandle()
|
||||
{
|
||||
return this.handle;
|
||||
}
|
||||
public IRecvByteBufAllocatorHandle NewHandle() => this.handle;
|
||||
}
|
||||
}
|
|
@ -25,14 +25,8 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
this.failed = new ReadOnlyCollection<KeyValuePair<IChannel, Exception>>(exceptions);
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<IChannel, Exception>> GetEnumerator()
|
||||
{
|
||||
return this.failed.GetEnumerator();
|
||||
}
|
||||
public IEnumerator<KeyValuePair<IChannel, Exception>> GetEnumerator() => this.failed.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.failed.GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() => this.failed.GetEnumerator();
|
||||
}
|
||||
}
|
|
@ -11,45 +11,21 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
static readonly IChannelMatcher ServerChannelMatcher = IsInstanceOf(typeof(IServerChannel));
|
||||
static readonly IChannelMatcher NonServerChannelMatcher = IsNotInstanceOf(typeof(IServerChannel));
|
||||
|
||||
public static IChannelMatcher IsServerChannel()
|
||||
{
|
||||
return ServerChannelMatcher;
|
||||
}
|
||||
public static IChannelMatcher IsServerChannel() => ServerChannelMatcher;
|
||||
|
||||
public static IChannelMatcher IsNonServerChannel()
|
||||
{
|
||||
return NonServerChannelMatcher;
|
||||
}
|
||||
public static IChannelMatcher IsNonServerChannel() => NonServerChannelMatcher;
|
||||
|
||||
public static IChannelMatcher All()
|
||||
{
|
||||
return AllMatcher;
|
||||
}
|
||||
public static IChannelMatcher All() => AllMatcher;
|
||||
|
||||
public static IChannelMatcher IsNot(IChannel channel)
|
||||
{
|
||||
return Invert(Is(channel));
|
||||
}
|
||||
public static IChannelMatcher IsNot(IChannel channel) => Invert(Is(channel));
|
||||
|
||||
public static IChannelMatcher Is(IChannel channel)
|
||||
{
|
||||
return new InstanceMatcher(channel);
|
||||
}
|
||||
public static IChannelMatcher Is(IChannel channel) => new InstanceMatcher(channel);
|
||||
|
||||
public static IChannelMatcher IsInstanceOf(Type type)
|
||||
{
|
||||
return new TypeMatcher(type);
|
||||
}
|
||||
public static IChannelMatcher IsInstanceOf(Type type) => new TypeMatcher(type);
|
||||
|
||||
public static IChannelMatcher IsNotInstanceOf(Type type)
|
||||
{
|
||||
return Invert(IsInstanceOf(type));
|
||||
}
|
||||
public static IChannelMatcher IsNotInstanceOf(Type type) => Invert(IsInstanceOf(type));
|
||||
|
||||
public static IChannelMatcher Invert(IChannelMatcher matcher)
|
||||
{
|
||||
return new InvertMatcher(matcher);
|
||||
}
|
||||
public static IChannelMatcher Invert(IChannelMatcher matcher) => new InvertMatcher(matcher);
|
||||
|
||||
public static IChannelMatcher Compose(params IChannelMatcher[] matchers)
|
||||
{
|
||||
|
@ -66,10 +42,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
|
||||
sealed class AllChannelMatcher : IChannelMatcher
|
||||
{
|
||||
public bool Matches(IChannel channel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool Matches(IChannel channel) => true;
|
||||
}
|
||||
|
||||
sealed class CompositeMatcher : IChannelMatcher
|
||||
|
@ -103,10 +76,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
public bool Matches(IChannel channel)
|
||||
{
|
||||
return !this.matcher.Matches(channel);
|
||||
}
|
||||
public bool Matches(IChannel channel) => !this.matcher.Matches(channel);
|
||||
}
|
||||
|
||||
sealed class InstanceMatcher : IChannelMatcher
|
||||
|
@ -118,10 +88,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
this.channel = channel;
|
||||
}
|
||||
|
||||
public bool Matches(IChannel ch)
|
||||
{
|
||||
return this.channel == ch;
|
||||
}
|
||||
public bool Matches(IChannel ch) => this.channel == ch;
|
||||
}
|
||||
|
||||
sealed class TypeMatcher : IChannelMatcher
|
||||
|
@ -133,10 +100,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
this.type = clazz;
|
||||
}
|
||||
|
||||
public bool Matches(IChannel channel)
|
||||
{
|
||||
return this.type.IsInstanceOfType(channel);
|
||||
}
|
||||
public bool Matches(IChannel channel) => this.type.IsInstanceOfType(channel);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,13 +7,13 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
public sealed class CombinedEnumerator<E> : IEnumerator<E>
|
||||
public sealed class CombinedEnumerator<T> : IEnumerator<T>
|
||||
{
|
||||
readonly IEnumerator<E> e1;
|
||||
readonly IEnumerator<E> e2;
|
||||
IEnumerator<E> currentEnumerator;
|
||||
readonly IEnumerator<T> e1;
|
||||
readonly IEnumerator<T> e2;
|
||||
IEnumerator<T> currentEnumerator;
|
||||
|
||||
public CombinedEnumerator(IEnumerator<E> e1, IEnumerator<E> e2)
|
||||
public CombinedEnumerator(IEnumerator<T> e1, IEnumerator<T> e2)
|
||||
{
|
||||
Contract.Requires(e1 != null);
|
||||
Contract.Requires(e2 != null);
|
||||
|
@ -22,12 +22,9 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
this.currentEnumerator = e1;
|
||||
}
|
||||
|
||||
public E Current => this.currentEnumerator.Current;
|
||||
public T Current => this.currentEnumerator.Current;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.currentEnumerator.Dispose();
|
||||
}
|
||||
public void Dispose() => this.currentEnumerator.Dispose();
|
||||
|
||||
object IEnumerator.Current => this.Current;
|
||||
|
||||
|
@ -50,9 +47,6 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
this.currentEnumerator.Reset();
|
||||
}
|
||||
public void Reset() => this.currentEnumerator.Reset();
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
{
|
||||
static int nextId;
|
||||
readonly IEventExecutor executor;
|
||||
readonly string name;
|
||||
readonly ConcurrentDictionary<IChannelId, IChannel> nonServerChannels = new ConcurrentDictionary<IChannelId, IChannel>();
|
||||
readonly ConcurrentDictionary<IChannelId, IChannel> serverChannels = new ConcurrentDictionary<IChannelId, IChannel>();
|
||||
|
||||
|
@ -33,35 +32,29 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
this.name = name;
|
||||
this.Name = name;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public bool IsEmpty => this.serverChannels.Count == 0 && this.nonServerChannels.Count == 0;
|
||||
|
||||
public string Name => this.name;
|
||||
public string Name { get; }
|
||||
|
||||
public IChannel Find(IChannelId id)
|
||||
{
|
||||
IChannel channel = null;
|
||||
IChannel channel;
|
||||
if (this.nonServerChannels.TryGetValue(id, out channel))
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
else if (this.serverChannels.TryGetValue(id, out channel))
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.serverChannels.TryGetValue(id, out channel);
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
|
||||
public Task WriteAsync(object message)
|
||||
{
|
||||
return this.WriteAsync(message, ChannelMatchers.All());
|
||||
}
|
||||
public Task WriteAsync(object message) => this.WriteAsync(message, ChannelMatchers.All());
|
||||
|
||||
public Task WriteAsync(object message, IChannelMatcher matcher)
|
||||
{
|
||||
|
@ -92,10 +85,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return this;
|
||||
}
|
||||
|
||||
public IChannelGroup Flush()
|
||||
{
|
||||
return this.Flush(ChannelMatchers.All());
|
||||
}
|
||||
public IChannelGroup Flush() => this.Flush(ChannelMatchers.All());
|
||||
|
||||
public int CompareTo(IChannelGroup other)
|
||||
{
|
||||
|
@ -108,10 +98,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return this.GetHashCode() - other.GetHashCode();
|
||||
}
|
||||
|
||||
void ICollection<IChannel>.Add(IChannel item)
|
||||
{
|
||||
this.Add(item);
|
||||
}
|
||||
void ICollection<IChannel>.Add(IChannel item) => this.Add(item);
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
@ -132,10 +119,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
}
|
||||
}
|
||||
|
||||
public void CopyTo(IChannel[] array, int arrayIndex)
|
||||
{
|
||||
this.ToArray().CopyTo(array, arrayIndex);
|
||||
}
|
||||
public void CopyTo(IChannel[] array, int arrayIndex) => this.ToArray().CopyTo(array, arrayIndex);
|
||||
|
||||
public int Count => this.nonServerChannels.Count + this.serverChannels.Count;
|
||||
|
||||
|
@ -143,7 +127,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
|
||||
public bool Remove(IChannel channel)
|
||||
{
|
||||
IChannel ch = null;
|
||||
IChannel ch;
|
||||
if (channel is IServerChannel)
|
||||
{
|
||||
return this.serverChannels.TryRemove(channel.Id, out ch);
|
||||
|
@ -154,22 +138,13 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerator<IChannel> GetEnumerator()
|
||||
{
|
||||
return new CombinedEnumerator<IChannel>(this.serverChannels.Values.GetEnumerator(),
|
||||
this.nonServerChannels.Values.GetEnumerator());
|
||||
}
|
||||
public IEnumerator<IChannel> GetEnumerator() => new CombinedEnumerator<IChannel>(this.serverChannels.Values.GetEnumerator(),
|
||||
this.nonServerChannels.Values.GetEnumerator());
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new CombinedEnumerator<IChannel>(this.serverChannels.Values.GetEnumerator(),
|
||||
this.nonServerChannels.Values.GetEnumerator());
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() => new CombinedEnumerator<IChannel>(this.serverChannels.Values.GetEnumerator(),
|
||||
this.nonServerChannels.Values.GetEnumerator());
|
||||
|
||||
public Task WriteAndFlushAsync(object message)
|
||||
{
|
||||
return this.WriteAndFlushAsync(message, ChannelMatchers.All());
|
||||
}
|
||||
public Task WriteAndFlushAsync(object message) => this.WriteAndFlushAsync(message, ChannelMatchers.All());
|
||||
|
||||
public Task WriteAndFlushAsync(object message, IChannelMatcher matcher)
|
||||
{
|
||||
|
@ -188,10 +163,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task;
|
||||
}
|
||||
|
||||
public Task DisconnectAsync()
|
||||
{
|
||||
return this.DisconnectAsync(ChannelMatchers.All());
|
||||
}
|
||||
public Task DisconnectAsync() => this.DisconnectAsync(ChannelMatchers.All());
|
||||
|
||||
public Task DisconnectAsync(IChannelMatcher matcher)
|
||||
{
|
||||
|
@ -215,10 +187,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task;
|
||||
}
|
||||
|
||||
public Task CloseAsync()
|
||||
{
|
||||
return this.CloseAsync(ChannelMatchers.All());
|
||||
}
|
||||
public Task CloseAsync() => this.CloseAsync(ChannelMatchers.All());
|
||||
|
||||
public Task CloseAsync(IChannelMatcher matcher)
|
||||
{
|
||||
|
@ -242,10 +211,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task;
|
||||
}
|
||||
|
||||
public Task DeregisterAsync()
|
||||
{
|
||||
return this.DeregisterAsync(ChannelMatchers.All());
|
||||
}
|
||||
public Task DeregisterAsync() => this.DeregisterAsync(ChannelMatchers.All());
|
||||
|
||||
public Task DeregisterAsync(IChannelMatcher matcher)
|
||||
{
|
||||
|
@ -269,10 +235,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task;
|
||||
}
|
||||
|
||||
public Task NewCloseFuture()
|
||||
{
|
||||
return this.NewCloseFuture(ChannelMatchers.All());
|
||||
}
|
||||
public Task NewCloseFuture() => this.NewCloseFuture(ChannelMatchers.All());
|
||||
|
||||
public Task NewCloseFuture(IChannelMatcher matcher)
|
||||
{
|
||||
|
@ -313,15 +276,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
return ReferenceCountUtil.Retain(message);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return this == obj;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.GetType().Name}(name: {this.Name}, size: {this.Count})";
|
||||
}
|
||||
public override string ToString() => $"{this.GetType().Name}(name: {this.Name}, size: {this.Count})";
|
||||
|
||||
public bool Add(IChannel channel)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,6 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
public class DefaultChannelGroupCompletionSource : TaskCompletionSource<int>, IChannelGroupTaskCompletionSource
|
||||
{
|
||||
readonly Dictionary<IChannel, Task> futures;
|
||||
readonly IChannelGroup group;
|
||||
int failureCount;
|
||||
int successCount;
|
||||
|
||||
|
@ -27,7 +26,8 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
Contract.Requires(group != null);
|
||||
Contract.Requires(futures != null);
|
||||
|
||||
this.group = group;
|
||||
this.Group = group;
|
||||
this.futures = new Dictionary<IChannel, Task>();
|
||||
foreach (KeyValuePair<IChannel, Task> pair in futures)
|
||||
{
|
||||
this.futures.Add(pair.Key, pair.Value);
|
||||
|
@ -84,12 +84,9 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
}
|
||||
}
|
||||
|
||||
public IChannelGroup Group => this.@group;
|
||||
public IChannelGroup Group { get; }
|
||||
|
||||
public Task Find(IChannel channel)
|
||||
{
|
||||
return this.futures[channel];
|
||||
}
|
||||
public Task Find(IChannel channel) => this.futures[channel];
|
||||
|
||||
public bool IsPartialSucess()
|
||||
{
|
||||
|
@ -99,10 +96,7 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsSucess()
|
||||
{
|
||||
return this.Task.IsCompleted && !this.Task.IsFaulted && !this.Task.IsCanceled;
|
||||
}
|
||||
public bool IsSucess() => this.Task.IsCompleted && !this.Task.IsFaulted && !this.Task.IsCanceled;
|
||||
|
||||
public bool IsPartialFailure()
|
||||
{
|
||||
|
@ -116,21 +110,12 @@ namespace DotNetty.Transport.Channels.Groups
|
|||
|
||||
public Task Current => this.futures.Values.GetEnumerator().Current;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.futures.Values.GetEnumerator().Dispose();
|
||||
}
|
||||
public void Dispose() => this.futures.Values.GetEnumerator().Dispose();
|
||||
|
||||
object IEnumerator.Current => this.futures.Values.GetEnumerator().Current;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
return this.futures.Values.GetEnumerator().MoveNext();
|
||||
}
|
||||
public bool MoveNext() => this.futures.Values.GetEnumerator().MoveNext();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
((IEnumerator)this.futures.Values.GetEnumerator()).Reset();
|
||||
}
|
||||
public void Reset() => ((IEnumerator)this.futures.Values.GetEnumerator()).Reset();
|
||||
}
|
||||
}
|
|
@ -86,26 +86,26 @@ namespace DotNetty.Transport.Channels
|
|||
/// <summary>
|
||||
/// Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
||||
/// completes, either because the operation was successful or because of an error.
|
||||
/// <p>
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
||||
/// called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// <p />
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
|
||||
/// called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// </summary>
|
||||
Task BindAsync(EndPoint localAddress);
|
||||
|
||||
/// <summary>
|
||||
/// Request to connect to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
|
||||
/// completes, either because the operation was successful or because of an error.
|
||||
/// <p>
|
||||
/// If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
||||
/// a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
||||
/// will be used.
|
||||
/// <p>
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// <p />
|
||||
/// If the connection fails because of a connection timeout, the {@link ChannelFuture} will get failed with
|
||||
/// a {@link ConnectTimeoutException}. If it fails because of connection refused a {@link ConnectException}
|
||||
/// will be used.
|
||||
/// <p />
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// </summary>
|
||||
Task ConnectAsync(EndPoint remoteAddress);
|
||||
|
||||
|
@ -113,22 +113,22 @@ namespace DotNetty.Transport.Channels
|
|||
/// Request to connect to the given {@link SocketAddress} while bind to the localAddress and notify the
|
||||
/// {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
||||
/// an error.
|
||||
/// <p>
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// <p />
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// </summary>
|
||||
Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress);
|
||||
|
||||
/// <summary>
|
||||
/// Request to disconnect from the remote peer and notify the {@link ChannelFuture} once the operation completes,
|
||||
/// either because the operation was successful or because of an error.
|
||||
/// <p>
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// <p />
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// </summary>
|
||||
Task DisconnectAsync();
|
||||
|
||||
|
@ -139,11 +139,11 @@ namespace DotNetty.Transport.Channels
|
|||
/// {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
|
||||
/// an error.
|
||||
/// The given {@link ChannelPromise} will be notified.
|
||||
/// <p>
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// <p />
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#deregister(ChannelHandlerContext, ChannelPromise)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// </summary>
|
||||
Task DeregisterAsync();
|
||||
}
|
||||
|
|
|
@ -70,97 +70,97 @@ namespace DotNetty.Transport.Channels
|
|||
/// connections
|
||||
/// and closed connections) or the inbound data was read from a remote peer. If an inbound event goes beyond the
|
||||
/// {@link ChannelHandler} at the top of the diagram, it is discarded and logged, depending on your loglevel.
|
||||
/// <p>
|
||||
/// An outbound event is handled by the {@link ChannelHandler}s in the top-down direction as shown on the right
|
||||
/// side of
|
||||
/// the diagram. An outbound event is usually triggered by your code that requests an outbound I/O operation, such
|
||||
/// as
|
||||
/// a write request and a connection attempt. If an outbound event goes beyond the {@link ChannelHandler} at the
|
||||
/// bottom of the diagram, it is handled by an I/O thread associated with the {@link Channel}. The I/O thread often
|
||||
/// performs the actual output operation such as {@link SocketChannel#write(ByteBuffer)}.
|
||||
/// <p>
|
||||
/// <h3>Forwarding an event to the next handler</h3>
|
||||
/// As explained briefly above, a {@link ChannelHandler} has to invoke the event propagation methods in
|
||||
/// {@link ChannelHandlerContext} to forward an event to its next handler. Those methods include:
|
||||
/// <p />
|
||||
/// An outbound event is handled by the {@link ChannelHandler}s in the top-down direction as shown on the right
|
||||
/// side of
|
||||
/// the diagram. An outbound event is usually triggered by your code that requests an outbound I/O operation, such
|
||||
/// as
|
||||
/// a write request and a connection attempt. If an outbound event goes beyond the {@link ChannelHandler} at the
|
||||
/// bottom of the diagram, it is handled by an I/O thread associated with the {@link Channel}. The I/O thread often
|
||||
/// performs the actual output operation such as {@link SocketChannel#write(ByteBuffer)}.
|
||||
/// <p />
|
||||
/// <h3>Forwarding an event to the next handler</h3>
|
||||
/// As explained briefly above, a {@link ChannelHandler} has to invoke the event propagation methods in
|
||||
/// {@link ChannelHandlerContext} to forward an event to its next handler. Those methods include:
|
||||
/// <ul>
|
||||
/// <li>
|
||||
/// Inbound event propagation methods:
|
||||
/// <ul>
|
||||
/// <li>
|
||||
/// Inbound event propagation methods:
|
||||
/// <ul>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelRegistered()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelActive()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelRead(Object)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelReadComplete()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireExceptionCaught(Throwable)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireUserEventTriggered(Object)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelWritabilityChanged()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelInactive()}</li>
|
||||
/// </ul>
|
||||
/// </li>
|
||||
/// <li>
|
||||
/// Outbound event propagation methods:
|
||||
/// <ul>
|
||||
/// <li>{@link ChannelHandlerContext#bind(SocketAddress, ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#write(Object, ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#flush()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#read()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#disconnect(ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#close(ChannelPromise)}</li>
|
||||
/// </ul>
|
||||
/// </li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelRegistered()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelActive()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelRead(Object)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelReadComplete()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireExceptionCaught(Throwable)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireUserEventTriggered(Object)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelWritabilityChanged()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#fireChannelInactive()}</li>
|
||||
/// </ul>
|
||||
/// and the following example shows how the event propagation is usually done:
|
||||
/// <pre>
|
||||
/// public class MyInboundHandler extends {@link ChannelHandlerAdapter} {
|
||||
/// {@code }
|
||||
/// public void channelActive({@link ChannelHandlerContext} ctx) {
|
||||
/// System.out.println("Connected!");
|
||||
/// ctx.fireChannelActive();
|
||||
/// }
|
||||
/// }
|
||||
/// public clas MyOutboundHandler extends {@link ChannelHandlerAdapter} {
|
||||
/// {@code }
|
||||
/// public void close({@link ChannelHandlerContext} ctx, {@link ChannelPromise} promise) {
|
||||
/// System.out.println("Closing ..");
|
||||
/// ctx.close(promise);
|
||||
/// }
|
||||
/// }
|
||||
/// </pre>
|
||||
/// <h3>Building a pipeline</h3>
|
||||
/// <p>
|
||||
/// A user is supposed to have one or more {@link ChannelHandler}s in a pipeline to receive I/O events
|
||||
/// (e.g. read) and
|
||||
/// to request I/O operations (e.g. write and close). For example, a typical server will have the
|
||||
/// following handlers
|
||||
/// in each channel's pipeline, but your mileage may vary depending on the complexity and characteristics
|
||||
/// of the
|
||||
/// protocol and business logic:
|
||||
/// <ol>
|
||||
/// <li>Protocol Decoder - translates binary data (e.g. {@link ByteBuf}) into a Java object.</li>
|
||||
/// <li>Protocol Encoder - translates a Java object into binary data.</li>
|
||||
/// <li>Business Logic Handler - performs the actual business logic (e.g. database access).</li>
|
||||
/// </ol>
|
||||
/// and it could be represented as shown in the following example:
|
||||
/// <pre>
|
||||
/// static final {@link EventExecutorGroup} group = new {@link DefaultEventExecutorGroup}(16);
|
||||
/// ...
|
||||
/// {@link ChannelPipeline} pipeline = ch.pipeline();
|
||||
/// pipeline.addLast("decoder", new MyProtocolDecoder());
|
||||
/// pipeline.addLast("encoder", new MyProtocolEncoder());
|
||||
/// // Tell the pipeline to run MyBusinessLogicHandler's event handler methods
|
||||
/// // in a different thread than an I/O thread so that the I/O thread is not blocked by
|
||||
/// // a time-consuming task.
|
||||
/// // If your business logic is fully asynchronous or finished very quickly, you don't
|
||||
/// // need to specify a group.
|
||||
/// pipeline.addLast(group, "handler", new MyBusinessLogicHandler());
|
||||
/// </pre>
|
||||
/// <h3>Thread safety</h3>
|
||||
/// <p>
|
||||
/// A {@link ChannelHandler} can be added or removed at any time because a {@link ChannelPipeline} is
|
||||
/// thread safe.
|
||||
/// For example, you can insert an encryption handler when sensitive information is about to be
|
||||
/// exchanged, and remove it
|
||||
/// after the exchange.
|
||||
/// </li>
|
||||
/// <li>
|
||||
/// Outbound event propagation methods:
|
||||
/// <ul>
|
||||
/// <li>{@link ChannelHandlerContext#bind(SocketAddress, ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#write(Object, ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#flush()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#read()}</li>
|
||||
/// <li>{@link ChannelHandlerContext#disconnect(ChannelPromise)}</li>
|
||||
/// <li>{@link ChannelHandlerContext#close(ChannelPromise)}</li>
|
||||
/// </ul>
|
||||
/// </li>
|
||||
/// </ul>
|
||||
/// and the following example shows how the event propagation is usually done:
|
||||
/// <pre>
|
||||
/// public class MyInboundHandler extends {@link ChannelHandlerAdapter} {
|
||||
/// {@code }
|
||||
/// public void channelActive({@link ChannelHandlerContext} ctx) {
|
||||
/// System.out.println("Connected!");
|
||||
/// ctx.fireChannelActive();
|
||||
/// }
|
||||
/// }
|
||||
/// public clas MyOutboundHandler extends {@link ChannelHandlerAdapter} {
|
||||
/// {@code }
|
||||
/// public void close({@link ChannelHandlerContext} ctx, {@link ChannelPromise} promise) {
|
||||
/// System.out.println("Closing ..");
|
||||
/// ctx.close(promise);
|
||||
/// }
|
||||
/// }
|
||||
/// </pre>
|
||||
/// <h3>Building a pipeline</h3>
|
||||
/// <p />
|
||||
/// A user is supposed to have one or more {@link ChannelHandler}s in a pipeline to receive I/O events
|
||||
/// (e.g. read) and
|
||||
/// to request I/O operations (e.g. write and close). For example, a typical server will have the
|
||||
/// following handlers
|
||||
/// in each channel's pipeline, but your mileage may vary depending on the complexity and characteristics
|
||||
/// of the
|
||||
/// protocol and business logic:
|
||||
/// <ol>
|
||||
/// <li>Protocol Decoder - translates binary data (e.g. {@link ByteBuf}) into a Java object.</li>
|
||||
/// <li>Protocol Encoder - translates a Java object into binary data.</li>
|
||||
/// <li>Business Logic Handler - performs the actual business logic (e.g. database access).</li>
|
||||
/// </ol>
|
||||
/// and it could be represented as shown in the following example:
|
||||
/// <pre>
|
||||
/// static final {@link EventExecutorGroup} group = new {@link DefaultEventExecutorGroup}(16);
|
||||
/// ...
|
||||
/// {@link ChannelPipeline} pipeline = ch.pipeline();
|
||||
/// pipeline.addLast("decoder", new MyProtocolDecoder());
|
||||
/// pipeline.addLast("encoder", new MyProtocolEncoder());
|
||||
/// // Tell the pipeline to run MyBusinessLogicHandler's event handler methods
|
||||
/// // in a different thread than an I/O thread so that the I/O thread is not blocked by
|
||||
/// // a time-consuming task.
|
||||
/// // If your business logic is fully asynchronous or finished very quickly, you don't
|
||||
/// // need to specify a group.
|
||||
/// pipeline.addLast(group, "handler", new MyBusinessLogicHandler());
|
||||
/// </pre>
|
||||
/// <h3>Thread safety</h3>
|
||||
/// <p />
|
||||
/// A {@link ChannelHandler} can be added or removed at any time because a {@link ChannelPipeline} is
|
||||
/// thread safe.
|
||||
/// For example, you can insert an encryption handler when sensitive information is about to be
|
||||
/// exchanged, and remove it
|
||||
/// after the exchange.
|
||||
/// </summary>
|
||||
public interface IChannelPipeline : IEnumerable<IChannelHandler>
|
||||
{
|
||||
|
@ -450,7 +450,7 @@ namespace DotNetty.Transport.Channels
|
|||
IChannelHandlerContext Context<T>() where T : class, IChannelHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="IChannel"/> that this pipeline is attached to.
|
||||
/// Returns the <see cref="IChannel" /> that this pipeline is attached to.
|
||||
/// </summary>
|
||||
/// <returns>the channel. <c>null</c> if this pipeline is not attached yet.</returns>
|
||||
IChannel Channel { get; }
|
||||
|
@ -611,11 +611,11 @@ namespace DotNetty.Transport.Channels
|
|||
/// read, and triggers a
|
||||
/// {@link ChannelHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
|
||||
/// handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
|
||||
/// <p>
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#read(ChannelHandlerContext)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// <p />
|
||||
/// This will result in having the
|
||||
/// {@link ChannelHandler#read(ChannelHandlerContext)}
|
||||
/// method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
|
||||
/// {@link Channel}.
|
||||
/// </summary>
|
||||
IChannelPipeline Read();
|
||||
|
||||
|
|
|
@ -99,10 +99,7 @@ namespace DotNetty.Transport.Channels
|
|||
// We need to guard against null as channel.Unsafe.OutboundBuffer may returned null
|
||||
// if the channel was already closed when constructing the PendingWriteQueue.
|
||||
// See https://github.com/netty/netty/issues/3967
|
||||
if (this.buffer != null)
|
||||
{
|
||||
this.buffer.IncrementPendingOutboundBytes(write.Size);
|
||||
}
|
||||
this.buffer?.IncrementPendingOutboundBytes(write.Size);
|
||||
return promise.Task;
|
||||
}
|
||||
|
||||
|
@ -163,14 +160,14 @@ namespace DotNetty.Transport.Channels
|
|||
* if the {@link PendingWriteQueue} is empty.
|
||||
*/
|
||||
|
||||
public Task RemoveAndWriteAll()
|
||||
public Task RemoveAndWriteAllAsync()
|
||||
{
|
||||
Contract.Assert(this.ctx.Executor.InEventLoop);
|
||||
|
||||
if (this.size == 1)
|
||||
{
|
||||
// No need to use ChannelPromiseAggregator for this case.
|
||||
return this.RemoveAndWrite();
|
||||
return this.RemoveAndWriteAsync();
|
||||
}
|
||||
PendingWrite write = this.head;
|
||||
if (write == null)
|
||||
|
@ -199,10 +196,7 @@ namespace DotNetty.Transport.Channels
|
|||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
void AssertEmpty()
|
||||
{
|
||||
Contract.Assert(this.tail == null && this.head == null && this.size == 0);
|
||||
}
|
||||
void AssertEmpty() => Contract.Assert(this.tail == null && this.head == null && this.size == 0);
|
||||
|
||||
/**
|
||||
* Removes a pending write operation and performs it via
|
||||
|
@ -212,7 +206,7 @@ namespace DotNetty.Transport.Channels
|
|||
* if the {@link PendingWriteQueue} is empty.
|
||||
*/
|
||||
|
||||
public Task RemoveAndWrite()
|
||||
public Task RemoveAndWriteAsync()
|
||||
{
|
||||
Contract.Assert(this.ctx.Executor.InEventLoop);
|
||||
|
||||
|
@ -256,12 +250,7 @@ namespace DotNetty.Transport.Channels
|
|||
{
|
||||
Contract.Assert(this.ctx.Executor.InEventLoop);
|
||||
|
||||
PendingWrite write = this.head;
|
||||
if (write == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return write.Msg;
|
||||
return this.head?.Msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,10 +280,7 @@ namespace DotNetty.Transport.Channels
|
|||
// We need to guard against null as channel.unsafe().outboundBuffer() may returned null
|
||||
// if the channel was already closed when constructing the PendingWriteQueue.
|
||||
// See https://github.com/netty/netty/issues/3967
|
||||
if (this.buffer != null)
|
||||
{
|
||||
this.buffer.DecrementPendingOutboundBytes(writeSize);
|
||||
}
|
||||
this.buffer?.DecrementPendingOutboundBytes(writeSize);
|
||||
}
|
||||
|
||||
static void SafeFail(TaskCompletionSource promise, Exception cause)
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче