diff --git a/Directory.Build.targets b/Directory.Build.targets
index 0df77903e..e823f5dec 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -8,4 +8,8 @@
$(Version). Commit Hash: $(GitHeadSha)
+
+
+
+
diff --git a/after.DotNetty.sln.targets b/after.DotNetty.sln.targets
new file mode 100644
index 000000000..0c0fbc6ae
--- /dev/null
+++ b/after.DotNetty.sln.targets
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/DotNetty.Buffers/IByteBufferAllocatorMetric .cs b/src/DotNetty.Buffers/IByteBufferAllocatorMetric.cs
similarity index 100%
rename from src/DotNetty.Buffers/IByteBufferAllocatorMetric .cs
rename to src/DotNetty.Buffers/IByteBufferAllocatorMetric.cs
diff --git a/src/DotNetty.Codecs.Http/Multipart/IHttpData .cs b/src/DotNetty.Codecs.Http/Multipart/IHttpData.cs
similarity index 100%
rename from src/DotNetty.Codecs.Http/Multipart/IHttpData .cs
rename to src/DotNetty.Codecs.Http/Multipart/IHttpData.cs
diff --git a/src/DotNetty.Codecs.Redis/Messages/DefaultBulkStringRedisContent .cs b/src/DotNetty.Codecs.Redis/Messages/DefaultBulkStringRedisContent.cs
similarity index 100%
rename from src/DotNetty.Codecs.Redis/Messages/DefaultBulkStringRedisContent .cs
rename to src/DotNetty.Codecs.Redis/Messages/DefaultBulkStringRedisContent.cs
diff --git a/src/DotNetty.Codecs/ByteToMessageDecoder.cs b/src/DotNetty.Codecs/ByteToMessageDecoder.cs
index 460013e09..f8148ab41 100644
--- a/src/DotNetty.Codecs/ByteToMessageDecoder.cs
+++ b/src/DotNetty.Codecs/ByteToMessageDecoder.cs
@@ -249,7 +249,7 @@ protected void DiscardSomeReadBytes()
// See:
// - https://github.com/netty/netty/issues/2327
// - https://github.com/netty/netty/issues/1764
- this.cumulation.DiscardReadBytes(); // todo: use discardSomeReadBytes
+ this.cumulation.DiscardSomeReadBytes();
}
}
diff --git a/src/DotNetty.Handlers/Logging/LoggingHandler.cs b/src/DotNetty.Handlers/Logging/LoggingHandler.cs
index 3079fe8b6..5c2b1b2a4 100644
--- a/src/DotNetty.Handlers/Logging/LoggingHandler.cs
+++ b/src/DotNetty.Handlers/Logging/LoggingHandler.cs
@@ -209,6 +209,48 @@ public override void ChannelRead(IChannelHandlerContext ctx, object message)
ctx.FireChannelRead(message);
}
+ public override void ChannelReadComplete(IChannelHandlerContext ctx)
+ {
+ if (this.Logger.IsEnabled(this.InternalLevel))
+ {
+ this.Logger.Log(this.InternalLevel, this.Format(ctx, "RECEIVED_COMPLETE"));
+ }
+ ctx.FireChannelReadComplete();
+ }
+
+ public override void ChannelWritabilityChanged(IChannelHandlerContext ctx)
+ {
+ if (this.Logger.IsEnabled(this.InternalLevel))
+ {
+ this.Logger.Log(this.InternalLevel, this.Format(ctx, "WRITABILITY", ctx.Channel.IsWritable));
+ }
+ ctx.FireChannelWritabilityChanged();
+ }
+
+ public override void HandlerAdded(IChannelHandlerContext ctx)
+ {
+ if (this.Logger.IsEnabled(this.InternalLevel))
+ {
+ this.Logger.Log(this.InternalLevel, this.Format(ctx, "HANDLER_ADDED"));
+ }
+ }
+ public override void HandlerRemoved(IChannelHandlerContext ctx)
+ {
+ if (this.Logger.IsEnabled(this.InternalLevel))
+ {
+ this.Logger.Log(this.InternalLevel, this.Format(ctx, "HANDLER_REMOVED"));
+ }
+ }
+
+ public override void Read(IChannelHandlerContext ctx)
+ {
+ if (this.Logger.IsEnabled(this.InternalLevel))
+ {
+ this.Logger.Log(this.InternalLevel, this.Format(ctx, "READ"));
+ }
+ ctx.Read();
+ }
+
public override Task WriteAsync(IChannelHandlerContext ctx, object msg)
{
if (this.Logger.IsEnabled(this.InternalLevel))
diff --git a/src/DotNetty.Handlers/Tls/SniHandler.cs b/src/DotNetty.Handlers/Tls/SniHandler.cs
index 2e5546151..d7082e370 100644
--- a/src/DotNetty.Handlers/Tls/SniHandler.cs
+++ b/src/DotNetty.Handlers/Tls/SniHandler.cs
@@ -28,7 +28,7 @@ public sealed class SniHandler : ByteToMessageDecoder
bool readPending;
public SniHandler(ServerTlsSniSettings settings)
- : this(stream => new SslStream(stream, false), settings)
+ : this(stream => new SslStream(stream, true), settings)
{
}
diff --git a/src/DotNetty.Handlers/Tls/TlsHandler.Extensions.cs b/src/DotNetty.Handlers/Tls/TlsHandler.Extensions.cs
index 311d7440b..c7d44425c 100644
--- a/src/DotNetty.Handlers/Tls/TlsHandler.Extensions.cs
+++ b/src/DotNetty.Handlers/Tls/TlsHandler.Extensions.cs
@@ -40,18 +40,18 @@ private static SslStream CreateSslStream(TlsSettings settings, Stream stream)
// Enable client certificate function only if ClientCertificateRequired is true in the configuration
if (serverSettings.ClientCertificateMode == ClientCertificateMode.NoCertificate)
{
- return new SslStream(stream, false);
+ return new SslStream(stream, true);
}
#if DESKTOPCLR
// SSL 版本 2 协议不支持客户端证书
if (serverSettings.EnabledProtocols == SslProtocols.Ssl2)
{
- return new SslStream(stream, false);
+ return new SslStream(stream, true);
}
#endif
return new SslStream(stream,
- leaveInnerStreamOpen: false,
+ leaveInnerStreamOpen: true,
userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) =>
{
if (certificate == null)
@@ -84,7 +84,7 @@ private static SslStream CreateSslStream(TlsSettings settings, Stream stream)
{
var clientSettings = (ClientTlsSettings)settings;
return new SslStream(stream,
- leaveInnerStreamOpen: false,
+ leaveInnerStreamOpen: true,
userCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) =>
{
if (clientSettings.ServerCertificateValidation != null)
diff --git a/src/DotNetty.Handlers/Tls/TlsHandler.cs b/src/DotNetty.Handlers/Tls/TlsHandler.cs
index fbf11eb2f..9ed1990b8 100644
--- a/src/DotNetty.Handlers/Tls/TlsHandler.cs
+++ b/src/DotNetty.Handlers/Tls/TlsHandler.cs
@@ -3,21 +3,22 @@
namespace DotNetty.Handlers.Tls
{
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.IO;
- using System.Net.Security;
- using System.Runtime.ExceptionServices;
- using System.Security.Cryptography.X509Certificates;
- using System.Threading;
- using System.Threading.Tasks;
- using DotNetty.Buffers;
- using DotNetty.Codecs;
- using DotNetty.Common.Concurrency;
- using DotNetty.Common.Utilities;
- using DotNetty.Common.Internal.Logging;
- using DotNetty.Transport.Channels;
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Diagnostics.Contracts;
+ using System.IO;
+ using System.Net.Security;
+ using System.Runtime.ExceptionServices;
+ using System.Security.Cryptography.X509Certificates;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using DotNetty.Buffers;
+ using DotNetty.Codecs;
+ using DotNetty.Common.Concurrency;
+ using DotNetty.Common.Utilities;
+ using DotNetty.Common.Internal.Logging;
+ using DotNetty.Transport.Channels;
#if !DESKTOPCLR && (NET40 || NET45 || NET451 || NET46 || NET461 || NET462 || NET47 || NET471)
确保编译不出问题
@@ -26,632 +27,573 @@ namespace DotNetty.Handlers.Tls
确保编译不出问题
#endif
- public sealed partial class TlsHandler : ByteToMessageDecoder
- {
- #region @@ Fields @@
+ public sealed partial class TlsHandler : ByteToMessageDecoder
+ {
+ #region @@ Fields @@
- private static readonly IInternalLogger s_logger = InternalLoggerFactory.GetInstance();
+ private static readonly IInternalLogger s_logger = InternalLoggerFactory.GetInstance();
- private readonly TlsSettings _settings;
- private const int c_fallbackReadBufferSize = 256;
- private const int c_unencryptedWriteBatchSize = 14 * 1024;
+ private readonly TlsSettings _settings;
+ private const int c_fallbackReadBufferSize = 256;
+ private const int c_unencryptedWriteBatchSize = 14 * 1024;
- private static readonly Exception s_channelClosedException = new IOException("Channel is closed");
+ private static readonly Exception s_channelClosedException = new IOException("Channel is closed");
#if !NET40
- private static readonly Action s_handshakeCompletionCallback = new Action(HandleHandshakeCompleted);
+ private static readonly Action s_handshakeCompletionCallback = new Action(HandleHandshakeCompleted);
#endif
- private readonly SslStream _sslStream;
- private readonly MediationStream _mediationStream;
- private readonly TaskCompletionSource _closeFuture;
-
- private TlsHandlerState _state;
- private int _packetLength;
- private volatile IChannelHandlerContext _capturedContext;
- private BatchingPendingWriteQueue _pendingUnencryptedWrites;
- private Task _lastContextWriteTask;
- private bool _firedChannelRead;
- private IByteBuffer _pendingSslStreamReadBuffer;
- private Task _pendingSslStreamReadFuture;
+ private readonly SslStream _sslStream;
+ private readonly MediationStream _mediationStream;
+ private readonly TaskCompletionSource _closeFuture;
- #endregion
+ private TlsHandlerState _state;
+ private int _packetLength;
+ private volatile IChannelHandlerContext _capturedContext;
+ private BatchingPendingWriteQueue _pendingUnencryptedWrites;
+ private Task _lastContextWriteTask;
+ private bool _firedChannelRead;
+ private IByteBuffer _pendingSslStreamReadBuffer;
+ private Task _pendingSslStreamReadFuture;
- #region @@ Constructors @@
+ #endregion
- //public TlsHandler(TlsSettings settings)
- // : this(stream => new SslStream(stream, false), settings)
- //{
- //}
+ #region @@ Constructors @@
- public TlsHandler(Func sslStreamFactory, TlsSettings settings)
- {
- Contract.Requires(sslStreamFactory != null);
- Contract.Requires(settings != null);
+ //public TlsHandler(TlsSettings settings)
+ // : this(stream => new SslStream(stream, true), settings)
+ //{
+ //}
- _settings = settings;
- _closeFuture = new TaskCompletionSource();
- _mediationStream = new MediationStream(this);
- _sslStream = sslStreamFactory(_mediationStream);
- }
+ public TlsHandler(Func sslStreamFactory, TlsSettings settings)
+ {
+ Contract.Requires(sslStreamFactory != null);
+ Contract.Requires(settings != null);
- public static TlsHandler Client(string targetHost) => new TlsHandler(new ClientTlsSettings(targetHost));
+ _settings = settings;
+ _closeFuture = new TaskCompletionSource();
+ _mediationStream = new MediationStream(this);
+ _sslStream = sslStreamFactory(_mediationStream);
+ }
- public static TlsHandler Client(string targetHost, X509Certificate clientCertificate) => new TlsHandler(new ClientTlsSettings(targetHost, new List { clientCertificate }));
+ public static TlsHandler Client(string targetHost) => new TlsHandler(new ClientTlsSettings(targetHost));
- public static TlsHandler Server(X509Certificate certificate) => new TlsHandler(new ServerTlsSettings(certificate));
+ public static TlsHandler Client(string targetHost, X509Certificate clientCertificate) => new TlsHandler(new ClientTlsSettings(targetHost, new List { clientCertificate }));
- #endregion
+ public static TlsHandler Server(X509Certificate certificate) => new TlsHandler(new ServerTlsSettings(certificate));
- #region @@ Properties @@
+ #endregion
- // using workaround mentioned here: https://github.com/dotnet/corefx/issues/4510
- public X509Certificate2 LocalCertificate => _sslStream.LocalCertificate as X509Certificate2 ?? new X509Certificate2(_sslStream.LocalCertificate?.Export(X509ContentType.Cert));
+ #region @@ Properties @@
- public X509Certificate2 RemoteCertificate => _sslStream.RemoteCertificate as X509Certificate2 ?? new X509Certificate2(_sslStream.RemoteCertificate?.Export(X509ContentType.Cert));
+ // using workaround mentioned here: https://github.com/dotnet/corefx/issues/4510
+ public X509Certificate2 LocalCertificate => _sslStream.LocalCertificate as X509Certificate2 ?? new X509Certificate2(_sslStream.LocalCertificate?.Export(X509ContentType.Cert));
- private bool IsServer => _settings is ServerTlsSettings;
+ public X509Certificate2 RemoteCertificate => _sslStream.RemoteCertificate as X509Certificate2 ?? new X509Certificate2(_sslStream.RemoteCertificate?.Export(X509ContentType.Cert));
- #endregion
+ private bool IsServer => _settings is ServerTlsSettings;
- #region -- IDisposable Members --
+ #endregion
- public void Dispose() => _sslStream?.Dispose();
+ #region -- ChannelActive --
- #endregion
-
- #region -- ChannelActive --
-
- public override void ChannelActive(IChannelHandlerContext context)
- {
- base.ChannelActive(context);
+ public override void ChannelActive(IChannelHandlerContext context)
+ {
+ base.ChannelActive(context);
- if (!IsServer)
- {
- EnsureAuthenticated();
- }
- }
+ if (!IsServer)
+ {
+ EnsureAuthenticated();
+ }
+ }
- #endregion
+ #endregion
- #region -- ChannelInactive --
+ #region -- ChannelInactive --
- public override void ChannelInactive(IChannelHandlerContext context)
- {
- // Make sure to release SslStream,
- // and notify the handshake future if the connection has been closed during handshake.
- HandleFailure(s_channelClosedException);
+ public override void ChannelInactive(IChannelHandlerContext context)
+ {
+ // Make sure to release SslStream,
+ // and notify the handshake future if the connection has been closed during handshake.
+ HandleFailure(s_channelClosedException);
- base.ChannelInactive(context);
- }
+ base.ChannelInactive(context);
+ }
- #endregion
+ #endregion
- #region -- ExceptionCaught --
+ #region -- ExceptionCaught --
- public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
- {
- if (IgnoreException(exception))
- {
- // Close the connection explicitly just in case the transport
- // did not close the connection automatically.
- if (context.Channel.Active)
+ public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
- context.CloseAsync();
+ if (IgnoreException(exception))
+ {
+ // Close the connection explicitly just in case the transport
+ // did not close the connection automatically.
+ if (context.Channel.Active)
+ {
+ context.CloseAsync();
+ }
+ }
+ else
+ {
+ base.ExceptionCaught(context, exception);
+ }
}
- }
- else
- {
- base.ExceptionCaught(context, exception);
- }
- }
-
- #endregion
-
- #region ** IgnoreException **
-
- private bool IgnoreException(Exception t)
- {
- if (t is ObjectDisposedException && _closeFuture.Task.IsCompleted)
- {
- return true;
- }
- return false;
- }
-
- #endregion
-
- #region -- HandlerAdded --
-
- public override void HandlerAdded(IChannelHandlerContext context)
- {
- base.HandlerAdded(context);
- _capturedContext = context;
- _pendingUnencryptedWrites = new BatchingPendingWriteQueue(context, c_unencryptedWriteBatchSize);
- if (context.Channel.Active && !IsServer)
- {
- // todo: support delayed initialization on an existing/active channel if in client mode
- EnsureAuthenticated();
- }
- }
- #endregion
-
- #region ++ HandlerRemovedInternal ++
-
- protected override void HandlerRemovedInternal(IChannelHandlerContext context)
- {
- if (!_pendingUnencryptedWrites.IsEmpty)
- {
- // Check if queue is not empty first because create a new ChannelException is expensive
- _pendingUnencryptedWrites.RemoveAndFailAll(new ChannelException("Write has failed due to TlsHandler being removed from channel pipeline."));
- }
- }
-
- #endregion
+ #endregion
- #region ++ Decode ++
+ #region ** IgnoreException **
- protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List