├── .gitattributes ├── .gitignore ├── CONTRIBUTING.MD ├── DotNetty.nuspec ├── DotNetty.sln.DotSettings ├── DotNettyRPC.sln ├── DotNettyRPC.sln.DotSettings ├── LICENSE.txt ├── README.md ├── RELEASE_NOTES.md ├── ThirdPartyNotices.txt ├── build.cmd ├── build.fsx ├── build.sh ├── console └── Rpc.Console │ ├── App.config │ ├── IIntParameter.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── Rpc.Console.csproj ├── examples ├── Echo.Client │ ├── App.config │ ├── ClientSettings.cs │ ├── Echo.Client.csproj │ ├── EchoClientHandler.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── Echo.Server │ ├── App.config │ ├── Echo.Server.csproj │ ├── EchoServerHandler.cs │ ├── EchoServerSettings.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── packages.config ├── rpc ├── rpc.core │ ├── MessageSendCallBack.cs │ ├── MessageSendChannelInitializer.cs │ ├── MessageSendConnector.cs │ ├── MessageSendExecutor.cs │ ├── MessageSendHandler.cs │ ├── MessageSendProxy.cs │ ├── MessageSendSerializeFrame.cs │ ├── MessageSendSettings.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RpcServerLoader.cs │ ├── packages.config │ └── rpc.core.csproj ├── rpc.model │ ├── MessageRequest.cs │ ├── MessageResponse.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── rpc.model.csproj └── rpc.serialize │ ├── DefaultSerializer.cs │ ├── ISerializeFrame.cs │ ├── ISerializer.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── rpc.serialize.csproj ├── shared └── dotnetty.com.pfx ├── src ├── DotNetty.Buffers │ ├── AbstractByteBuffer.cs │ ├── AbstractByteBufferAllocator.cs │ ├── AbstractDerivedByteBuffer.cs │ ├── AbstractReferenceCountedByteBuffer.cs │ ├── AdvancedLeakAwareByteBuf.cs │ ├── ByteBufferUtil.cs │ ├── ByteOrder.cs │ ├── CompositeByteBuffer.cs │ ├── DotNetty.Buffers.csproj │ ├── DotNetty.Buffers.nuspec │ ├── DuplicatedByteBuffer.cs │ ├── EmptyByteBuffer.cs │ ├── IByteBuffer.cs │ ├── IByteBufferAllocator.cs │ ├── IByteBufferHolder.cs │ ├── IllegalReferenceCountException.cs │ ├── PooledByteBuffer.cs │ ├── PooledByteBufferAllocator.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SimpleLeakAwareByteBuf.cs │ ├── SlicedByteBuffer.cs │ ├── SwappedByteBuffer.cs │ ├── Unpooled.cs │ ├── UnpooledByteBufferAllocator.cs │ ├── UnpooledHeapByteBuffer.cs │ └── WrappedByteBuf.cs ├── DotNetty.Codecs.Mqtt │ ├── DotNetty.Codecs.Mqtt.csproj │ ├── DotNetty.Codecs.Mqtt.nuspec │ ├── MqttDecoder.cs │ ├── MqttEncoder.cs │ ├── Packets │ │ ├── ConnAckPacket.cs │ │ ├── ConnectPacket.cs │ │ ├── ConnectReturnCode.cs │ │ ├── DisconnectPacket.cs │ │ ├── Packet.cs │ │ ├── PacketType.cs │ │ ├── PacketWithId.cs │ │ ├── PingReqPacket.cs │ │ ├── PingRespPacket.cs │ │ ├── PubAckPacket.cs │ │ ├── PubCompPacket.cs │ │ ├── PubRecPacket.cs │ │ ├── PubRelPacket.cs │ │ ├── PublishPacket.cs │ │ ├── QualityOfService.cs │ │ ├── SubAckPacket.cs │ │ ├── SubscribePacket.cs │ │ ├── SubscriptionRequest.cs │ │ ├── UnsubAckPacket.cs │ │ └── UnsubscribePacket.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Friends.cs │ ├── Signatures.cs │ └── Util.cs ├── DotNetty.Codecs │ ├── ByteToMessageDecoder.cs │ ├── CodecException.cs │ ├── CorruptedFrameException.cs │ ├── DecoderException.cs │ ├── DotNetty.Codecs.csproj │ ├── DotNetty.Codecs.nuspec │ ├── EncoderException.cs │ ├── LengthFieldBasedFrameDecoder.cs │ ├── LengthFieldPrepender.cs │ ├── LineBasedFrameDecoder.cs │ ├── MessageToMessageDecoder.cs │ ├── MessageToMessageEncoder.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ReplayingDecoder.cs │ ├── Strings │ │ ├── StringDecoder.cs │ │ └── StringEncoder.cs │ ├── TooLongFrameException.cs │ └── UnsupportedMessageTypeException.cs ├── DotNetty.Common │ ├── Concurrency │ │ ├── AbstractEventExecutor.cs │ │ ├── AbstractScheduledEventExecutor.cs │ │ ├── ActionScheduledAsyncTask.cs │ │ ├── ActionScheduledTask.cs │ │ ├── ExecutorTaskScheduler.cs │ │ ├── ICallable`T.cs │ │ ├── IEventExecutor.cs │ │ ├── IPausableEventExecutor.cs │ │ ├── IRunnable.cs │ │ ├── IScheduledRunnable.cs │ │ ├── IScheduledTask.cs │ │ ├── IWrappedEventExecutor.cs │ │ ├── ScheduledAsyncTask.cs │ │ ├── ScheduledTask.cs │ │ ├── SingleThreadEventExecutor.cs │ │ ├── StateActionScheduledAsyncTask.cs │ │ ├── StateActionScheduledTask.cs │ │ ├── StateActionWithContextScheduledAsyncTask.cs │ │ ├── StateActionWithContextScheduledTask.cs │ │ └── TaskCompletionSource.cs │ ├── Deque.cs │ ├── DotNetty.Common.csproj │ ├── DotNetty.Common.nuspec │ ├── IReferenceCounted.cs │ ├── IResourceLeak.cs │ ├── IResourceLeakHint.cs │ ├── Internal │ │ ├── Logging │ │ │ ├── AbstractInternalLogger.cs │ │ │ ├── DefaultEventSource.cs │ │ │ ├── EventSourceLogger.cs │ │ │ ├── EventSourceLoggerFactory.cs │ │ │ ├── FormattingTuple.cs │ │ │ ├── IInternalLogger.cs │ │ │ ├── InternalLogLevel.cs │ │ │ ├── InternalLoggerFactory.cs │ │ │ └── MessageFormatter.cs │ │ └── SystemPropertyUtil.cs │ ├── PreciseTimeSpan.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Friends.cs │ ├── ResourceLeakDetector.cs │ ├── ThreadLocalObjectList.cs │ ├── ThreadLocalPool.cs │ └── Utilities │ │ ├── AtomicReference.cs │ │ ├── BitOps.cs │ │ ├── ByteArrayExtensions.cs │ │ ├── ByteProcessor.cs │ │ ├── DebugExtensions.cs │ │ ├── MpscLinkedQueue.cs │ │ ├── PriorityQueue.cs │ │ ├── RecyclableMpscLinkedQueueNode.cs │ │ ├── ReferenceCountUtil.cs │ │ ├── StringUtil.cs │ │ └── TaskEx.cs ├── DotNetty.Handlers │ ├── DotNetty.Handlers.csproj │ ├── DotNetty.Handlers.nuspec │ ├── Logging │ │ ├── LogLevel.cs │ │ ├── LogLevelExtensions.cs │ │ └── LoggingHandler.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Tls │ │ ├── TlsHandler.cs │ │ └── TlsHandshakeCompletionEvent.cs ├── DotNetty.Transport │ ├── Bootstrapping │ │ ├── AbstractBootstrap.cs │ │ ├── Bootstrap.cs │ │ ├── DefaultNameResolver.cs │ │ ├── INameResolver.cs │ │ └── ServerBootstrap.cs │ ├── Channels │ │ ├── AbstractChannel.cs │ │ ├── AbstractChannelHandlerContext.cs │ │ ├── ActionChannelInitializer.cs │ │ ├── ChannelException.cs │ │ ├── ChannelHandlerAdapter.cs │ │ ├── ChannelHandlerInvokerUtil.cs │ │ ├── ChannelInitializer.cs │ │ ├── ChannelOption.cs │ │ ├── ChannelOutboundBuffer.cs │ │ ├── ChannelPipelineException.cs │ │ ├── ClosedChannelException.cs │ │ ├── ConnectException.cs │ │ ├── ConnectTimeoutException.cs │ │ ├── DefaultChannelConfiguration.cs │ │ ├── DefaultChannelHandlerContext.cs │ │ ├── DefaultChannelHandlerInvoker.cs │ │ ├── DefaultChannelId.cs │ │ ├── DefaultChannelPipeline.cs │ │ ├── DefaultMessageSizeEstimator.cs │ │ ├── Embedded │ │ │ ├── EmbeddedChannel.cs │ │ │ ├── EmbeddedChannelId.cs │ │ │ ├── EmbeddedEventLoop.cs │ │ │ └── EmbeddedSocketAddress.cs │ │ ├── FixedRecvByteBufAllocator.cs │ │ ├── Groups │ │ │ ├── ChannelGroupException.cs │ │ │ ├── ChannelMatchers.cs │ │ │ ├── CombinedEnumerator.cs │ │ │ ├── DefaultChannelGroup.cs │ │ │ ├── DefaultChannelGroupCompletionSource.cs │ │ │ ├── IChannelGroup.cs │ │ │ ├── IChannelGroupTaskCompletionSource.cs │ │ │ └── IChannelMatcher.cs │ │ ├── IChannel.cs │ │ ├── IChannelConfiguration.cs │ │ ├── IChannelHandler.cs │ │ ├── IChannelHandlerContext.cs │ │ ├── IChannelHandlerInvoker.cs │ │ ├── IChannelId.cs │ │ ├── IChannelPipeline.cs │ │ ├── IChannelUnsafe.cs │ │ ├── IEventLoop.cs │ │ ├── IEventLoopGroup.cs │ │ ├── IMessageSizeEstimator.cs │ │ ├── IMessageSizeEstimatorHandle.cs │ │ ├── IRecvByteBufAllocator.cs │ │ ├── IRecvByteBufAllocatorHandle.cs │ │ ├── IServerChannel.cs │ │ ├── MultithreadEventLoopGroup.cs │ │ ├── NotYetConnectedException.cs │ │ ├── PausableChannelEventExecutor.cs │ │ ├── PendingWriteQueue.cs │ │ ├── RejectedExecutionException.cs │ │ ├── SingleThreadEventLoop.cs │ │ ├── SkipAttribute.cs │ │ ├── Sockets │ │ │ ├── AbstractSocketByteChannel.cs │ │ │ ├── AbstractSocketChannel.cs │ │ │ ├── AbstractSocketMessageChannel.cs │ │ │ ├── ChannelInputShutdownEvent.cs │ │ │ ├── DefaultServerSocketChannelConfig.cs │ │ │ ├── DefaultSocketChannelConfiguration.cs │ │ │ ├── IServerSocketChannel.cs │ │ │ ├── IServerSocketChannelConfiguration.cs │ │ │ ├── ISocketChannel.cs │ │ │ ├── ISocketChannelConfiguration.cs │ │ │ ├── SocketChannelAsyncOperation.cs │ │ │ ├── TcpServerSocketChannel.cs │ │ │ └── TcpSocketChannel.cs │ │ └── Util.cs │ ├── DotNetty.Transport.csproj │ ├── DotNetty.Transport.nuspec │ └── Properties │ │ ├── AssemblyInfo.cs │ │ └── Friends.cs └── SharedAssemblyInfo.cs ├── test ├── DotNetty.Buffers.Tests │ ├── AbstractByteBufferTests.cs │ ├── ByteBufferDerivationTests.cs │ ├── DotNetty.Buffers.Tests.csproj │ ├── LeakDetectionTest.cs │ ├── PooledBufferAllocatorTests.cs │ ├── PortionedMemoryStream.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── DotNetty.Codecs.Mqtt.Tests │ ├── DotNetty.Codecs.Mqtt.Tests.csproj │ ├── MqttCodecTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── DotNetty.Codecs.Tests │ ├── DotNetty.Codecs.Tests.csproj │ ├── Frame │ │ ├── LengthFieldBasedFrameDecoderTests.cs │ │ └── LengthFieldPrependerTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── DotNetty.Common.Tests │ ├── Concurrency │ │ └── SingleThreadEventExecutorTests.cs │ ├── DotNetty.Common.Tests.csproj │ ├── Internal │ │ └── Logging │ │ │ └── InternalLoggerFactoryTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ResourceLeakDetectorTest.cs │ ├── ThreadLocalPoolTest.cs │ ├── Utilities │ │ └── PriorityQueueTest.cs │ └── packages.config ├── DotNetty.Microbench │ ├── BenchTests.cs │ ├── DotNetty.Microbench.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Utilities │ │ ├── CodeTimer.cs │ │ └── CycleTime.cs │ └── packages.config ├── DotNetty.Tests.Common │ ├── DotNetty.Tests.Common.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TestBase.cs │ ├── TestScenarioRunner.cs │ ├── TestScenarioStep.cs │ ├── XUnitOutputSink.cs │ └── packages.config ├── DotNetty.Tests.End2End │ ├── DiagnosticsTests.cs │ ├── DotNetty.Tests.End2End.csproj │ ├── EchoChannelHandler.cs │ ├── End2EndTests.cs │ ├── ExceptionCatchHandler.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── DotNetty.Transport.Tests │ ├── Channel │ ├── DefaulChannelIdTest.cs │ └── Embedded │ │ └── EmbeddedChannelTest.cs │ ├── DotNetty.Transport.Tests.csproj │ ├── Properties │ └── AssemblyInfo.cs │ └── packages.config └── tools └── AddCopyrightHeaderToSourceFiles.ps1 /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.rb text=auto 26 | *.java text=auto 27 | *.html text=auto 28 | *.htm text=auto 29 | *.css text=auto 30 | *.scss text=auto 31 | *.sass text=auto 32 | *.less text=auto 33 | *.js text=auto 34 | *.lisp text=auto 35 | *.clj text=auto 36 | *.sql text=auto 37 | *.php text=auto 38 | *.lua text=auto 39 | *.m text=auto 40 | *.asm text=auto 41 | *.erl text=auto 42 | *.fs text=auto 43 | *.fsx text=auto 44 | *.hs text=auto 45 | 46 | *.csproj text=auto 47 | *.vbproj text=auto 48 | *.fsproj text=auto 49 | *.dbproj text=auto 50 | *.sln text=auto eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Oo]bj/ 2 | [Bb]in/ 3 | TestResults/ 4 | .nuget/ 5 | .fake/ 6 | _ReSharper.*/ 7 | packages/ 8 | artifacts/ 9 | PublishProfiles/ 10 | *.user 11 | *.suo 12 | *.cache 13 | *.docstates 14 | _ReSharper.* 15 | nuget.exe 16 | *net45.csproj 17 | *net451.csproj 18 | *k10.csproj 19 | *.psess 20 | *.vsp 21 | *.pidb 22 | *.userprefs 23 | *DS_Store 24 | *.ncrunchsolution 25 | *.*sdf 26 | *.ipch 27 | *.sln.ide 28 | *.lock.json 29 | *.db -------------------------------------------------------------------------------- /DotNetty.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | DotNetty 5 | 0.1.2-alpha1 6 | DotNetty framework 7 | Microsoft 8 | Microsoft 9 | false 10 | DotNetty is a port of netty framework. It is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. 11 | en-US 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation 2 | All rights reserved. 3 | 4 | MIT License 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #DotNettyRPC Project 2 | 3 | 4 | DotNettyRPC is based on Netty to build the RPC system, the message network transmission support the current mainstream codec! 5 | 6 | ### DotNettyRPC Introduction: 7 | * DotNettyRPC is based on CSharp language,network communications rely on DotNetty. 8 | * DotNettyRPC create proxy instance using interface dynamicly. 9 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | #### 0.2.6 April 27 2016 2 | - TlsHandler negotiates TLS 1.0+ on server side (#89). 3 | - STEE properly supports graceful shutdown (#7). 4 | - UnpooledHeapByteBuffer.GetBytes honors received index and length (#88). 5 | - Port of MessageToMessageDecoder, LineBasedFrameDecoder, StringDecoder, StringEncoder, ByteProcessor and ForEachByte family of methods on Byte Buffers (#86). 6 | 7 | #### 0.2.5 April 14 2016 8 | - Fixes regression in STEE where while evaluation of idling timeout did not account for immediately pending scheduled tasks (#83). 9 | 10 | #### 0.2.4 April 07 2016 11 | - Proper handling of pooled buffer growth beyond max capacity of buffer in pool (fixing #71). 12 | - Improved pooling of buffers when a buffer was released in other thread (#73). 13 | - Introduction of IEventExecutor.Schedule and proper cancellation of scheduled tasks (#80). 14 | - Better handling of wake-ups for scheduled tasks (#81). 15 | - Default internal logging initialization is deferred to allow override it completely (#80 extra). 16 | - Honoring `IByteBuffer.ArrayOffset` in `IByteBuffer.ToString(Encoding)` (#80 extra). 17 | 18 | #### 0.2.3 February 10 2016 19 | - Critical fix to handling of async operations when initiated from outside the event loop (#66). 20 | - Fix to enable setting socket-related options through SetOption on Bootstrap (#68). 21 | - build changes to allow signing assemblies 22 | 23 | #### 0.2.2 January 30 2016 24 | - `ResourceLeakDetector` fix (#64) 25 | - Assigned GUID on default internal logger `EventSource` 26 | - `IByteBuffer.ToString(..)` for efficient string decoding directly from Byte Buffer 27 | 28 | #### 0.2.1 December 08 2015 29 | - fixes to EmptyByteBuffer 30 | - ported LoggingHandler 31 | 32 | #### 0.2.0 November 17 2015 33 | - Proper Event Executor model port 34 | - EmbeddedChannel 35 | - Better test coverage for executor model and basic channel functionality 36 | - Channel groups support 37 | - Channel ID 38 | - Complete `LengthFieldBasedFrameDecoder` and `LengthFieldPrepender` 39 | - Resource leak detection support (basic is on by default for pooled byte buffers) 40 | - Proper internal logging 41 | - Reacher byte buffer API 42 | - Proper utilities set for byte buffers, strings, system properties 43 | - Performance improvements in SingleThreadEventExecutor 44 | 45 | #### 0.1.3 September 21 2015 46 | - Fixed `TcpSocketChannel` closure on graceful socket closure 47 | - Better alignment of IChannel implementations to netty's expected behavior for `Open`, `Active`, `LocalAddress`, `RemoteAddress` 48 | - Proper port of `Default/IChannelPipeline` and `AbstractChannelHandlerContext` to enable channel handlers to run on different invoker. 49 | 50 | #### 0.1.2 August 09 2015 51 | First public release -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | pushd %~dp0 4 | 5 | SETLOCAL 6 | SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe 7 | 8 | IF EXIST %CACHED_NUGET% goto copynuget 9 | echo Downloading latest version of NuGet.exe... 10 | IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet 11 | @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'" 12 | 13 | :copynuget 14 | IF EXIST .nuget\nuget.exe goto restore 15 | md .nuget 16 | copy %CACHED_NUGET% .nuget\nuget.exe > nul 17 | 18 | :restore 19 | 20 | .nuget\NuGet.exe update -self 21 | 22 | .nuget\NuGet.exe install FAKE -OutputDirectory packages -ExcludeVersion -Version 4.25.4 23 | 24 | .nuget\NuGet.exe install xunit.runner.console -OutputDirectory packages\FAKE -ExcludeVersion -Version 2.1.0 25 | 26 | if not exist packages\SourceLink.Fake\tools\SourceLink.fsx ( 27 | .nuget\nuget.exe install SourceLink.Fake -OutputDirectory packages -ExcludeVersion 28 | ) 29 | rem cls 30 | 31 | set encoding=utf-8 32 | packages\FAKE\tools\FAKE.exe build.fsx %* 33 | 34 | popd 35 | 36 | 37 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_PATH="${BASH_SOURCE[0]}"; 4 | if ([ -h "${SCRIPT_PATH}" ]) then 5 | while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done 6 | fi 7 | pushd . > /dev/null 8 | cd `dirname ${SCRIPT_PATH}` > /dev/null 9 | SCRIPT_PATH=`pwd`; 10 | popd > /dev/null 11 | 12 | if ! [ -f $SCRIPT_PATH/.nuget/nuget.exe ] 13 | then 14 | wget "https://www.nuget.org/nuget.exe" -P $SCRIPT_PATH/.nuget/ 15 | fi 16 | 17 | mono $SCRIPT_PATH/.nuget/nuget.exe update -self 18 | 19 | mono $SCRIPT_PATH/.nuget/nuget.exe install FAKE -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion -Version 4.25.4 20 | 21 | mono $SCRIPT_PATH/.nuget/nuget.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/packages/FAKE -ExcludeVersion -Version 2.0.0 22 | 23 | if ! [ -e $SCRIPT_PATH/packages/SourceLink.Fake/tools/SourceLink.fsx ] ; then 24 | mono $SCRIPT_PATH/.nuget/nuget.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/packages -ExcludeVersion 25 | 26 | fi 27 | 28 | export encoding=utf-8 29 | 30 | mono $SCRIPT_PATH/packages/FAKE/tools/FAKE.exe build.fsx "$@" 31 | -------------------------------------------------------------------------------- /console/Rpc.Console/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /console/Rpc.Console/IIntParameter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Rpc.Console 4 | { 5 | public interface IIntParameter 6 | { 7 | void Method(int value); 8 | } 9 | } -------------------------------------------------------------------------------- /console/Rpc.Console/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Rpc.Console 8 | { 9 | using System.Diagnostics; 10 | using System.Net; 11 | using System.Security.Cryptography.X509Certificates; 12 | using DotNetty.Codecs; 13 | using DotNetty.Handlers.Tls; 14 | using DotNetty.Transport.Bootstrapping; 15 | using DotNetty.Transport.Channels; 16 | using DotNetty.Transport.Channels.Sockets; 17 | using rpc.core; 18 | using rpc.serialize; 19 | using Console = System.Console; 20 | 21 | class Program 22 | { 23 | 24 | static async Task RunClient() 25 | { 26 | var executor = new MessageSendExecutor("127.0.0.1", 8007, new DefaultSerializer()); 27 | var myService = executor.Execute(); 28 | var sw =new Stopwatch(); 29 | sw.Start(); 30 | for (int i = 0; i < 1; i++) 31 | { 32 | myService.Method(1); 33 | } 34 | 35 | sw.Stop(); 36 | Console.WriteLine("一万次调用耗时:{0}毫秒",sw.ElapsedMilliseconds); 37 | } 38 | 39 | static void Main(string[] args) 40 | { 41 | 42 | Task.Run(() => RunClient()).Wait(); 43 | 44 | 45 | 46 | 47 | 48 | Console.ReadLine(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /console/Rpc.Console/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Rpc.Console")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Rpc.Console")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7e1000df-fd19-4add-9d36-1263673627c2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /examples/Echo.Client/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/Echo.Client/ClientSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | 4 | namespace Echo.Client 5 | { 6 | using System.Net; 7 | 8 | public static class EchoClientSettings 9 | { 10 | public static bool IsSsl 11 | { 12 | get 13 | { 14 | string ssl = ConfigurationManager.AppSettings["ssl"]; 15 | return !string.IsNullOrEmpty(ssl) && bool.Parse(ssl); 16 | } 17 | } 18 | 19 | public static IPAddress Host 20 | { 21 | get { return IPAddress.Parse(ConfigurationManager.AppSettings["host"]); } 22 | } 23 | 24 | public static int Port 25 | { 26 | get { return int.Parse(ConfigurationManager.AppSettings["port"]); } 27 | } 28 | 29 | public static int Size 30 | { 31 | get { return int.Parse(ConfigurationManager.AppSettings["size"]); } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/Echo.Client/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Echo.Client 5 | { 6 | using System; 7 | using System.Diagnostics.Tracing; 8 | using System.Net; 9 | using System.Security.Cryptography.X509Certificates; 10 | using System.Threading.Tasks; 11 | using DotNetty.Codecs; 12 | using DotNetty.Common.Internal.Logging; 13 | using DotNetty.Handlers.Tls; 14 | using DotNetty.Transport.Bootstrapping; 15 | using DotNetty.Transport.Channels; 16 | using DotNetty.Transport.Channels.Sockets; 17 | 18 | class Program 19 | { 20 | static async Task RunClient() 21 | { 22 | 23 | var group = new MultithreadEventLoopGroup(); 24 | 25 | try 26 | { 27 | var bootstrap = new Bootstrap(); 28 | bootstrap 29 | .Group(group) 30 | .Channel() 31 | .Option(ChannelOption.TcpNodelay, true) 32 | .Handler(new ActionSendChannelInitializer(channel => 33 | { 34 | IChannelPipeline pipeline = channel.Pipeline; 35 | 36 | if (EchoClientSettings.IsSsl) 37 | { 38 | var cert = new X509Certificate2("dotnetty.com.pfx", "password"); 39 | string targetHost = cert.GetNameInfo(X509NameType.DnsName, false); 40 | pipeline.AddLast(TlsHandler.Client(targetHost, null, (sender, certificate, chain, errors) => true)); 41 | } 42 | pipeline.AddLast(new LengthFieldPrepender(2)); 43 | pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2)); 44 | 45 | pipeline.AddLast(new EchoClientHandler()); 46 | })); 47 | 48 | IChannel bootstrapChannel = await bootstrap.ConnectAsync(new IPEndPoint(EchoClientSettings.Host, EchoClientSettings.Port)); 49 | 50 | Console.ReadLine(); 51 | 52 | await bootstrapChannel.CloseAsync(); 53 | } 54 | finally 55 | { 56 | group.ShutdownGracefullyAsync().Wait(1000); 57 | 58 | } 59 | } 60 | 61 | static void Main(string[] args) 62 | { 63 | Task.Run(() => RunClient()).Wait(); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /examples/Echo.Client/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Echo.Client")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Echo.Client")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c24ab93f-41e9-4291-ba8f-e9d3cf6c2ebc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /examples/Echo.Client/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/Echo.Server/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/Echo.Server/EchoServerHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Echo.Server 4 | { 5 | using System; 6 | using System.IO; 7 | using System.Runtime.Serialization; 8 | using System.Runtime.Serialization.Formatters.Binary; 9 | using System.Text; 10 | using DotNetty.Buffers; 11 | using DotNetty.Transport.Channels; 12 | using rpc.model; 13 | using rpc.serialize; 14 | 15 | public class EchoServerHandler : ChannelHandlerAdapter 16 | { 17 | DefaultSerializer serializable; 18 | 19 | public EchoServerHandler() 20 | { 21 | this.serializable = new DefaultSerializer(); 22 | } 23 | public override void ChannelRead(IChannelHandlerContext context, object message) 24 | { 25 | 26 | IByteBuffer buffer = message as SlicedByteBuffer; 27 | var response = new MessageResponse(); 28 | if (buffer != null) 29 | { 30 | var request = (MessageRequest)this.serializable.Deserialize(buffer.ToArray()); 31 | Console.WriteLine("Received from client: " + buffer.ToString(Encoding.UTF8)); 32 | response.MessageId = request.MessageId; 33 | response.Result = "hello world"; 34 | } 35 | 36 | context.WriteAsync(this.serializable.Serialize(message)); 37 | } 38 | 39 | public override void ChannelReadComplete(IChannelHandlerContext context) 40 | { 41 | context.Flush(); 42 | } 43 | 44 | public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) 45 | { 46 | // Console.WriteLine("Exception: " + exception); 47 | // context.CloseAsync(); 48 | } 49 | 50 | private Object ByteArrayToObject(byte[] arrBytes) 51 | { 52 | MemoryStream memStream = new MemoryStream(); 53 | BinaryFormatter binForm = new BinaryFormatter(); 54 | memStream.Write(arrBytes, 0, arrBytes.Length); 55 | memStream.Seek(0, SeekOrigin.Begin); 56 | Object obj = (Object)binForm.Deserialize(memStream); 57 | return obj; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/Echo.Server/EchoServerSettings.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace Echo.Server 4 | { 5 | using System.Configuration; 6 | 7 | public static class EchoServerSettings 8 | { 9 | public static bool IsSsl 10 | { 11 | get 12 | { 13 | string ssl = ConfigurationManager.AppSettings["ssl"]; 14 | return !string.IsNullOrEmpty(ssl) && bool.Parse(ssl); 15 | } 16 | } 17 | 18 | public static int Port 19 | { 20 | get { return int.Parse(ConfigurationManager.AppSettings["port"]); } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /examples/Echo.Server/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Echo.Server 5 | { 6 | using System; 7 | using System.Diagnostics.Tracing; 8 | using System.Security.Cryptography.X509Certificates; 9 | using System.Threading.Tasks; 10 | using DotNetty.Codecs; 11 | using DotNetty.Common.Internal.Logging; 12 | using DotNetty.Handlers.Logging; 13 | using DotNetty.Handlers.Tls; 14 | using DotNetty.Transport.Bootstrapping; 15 | using DotNetty.Transport.Channels; 16 | using DotNetty.Transport.Channels.Sockets; 17 | 18 | 19 | class Program 20 | { 21 | static async Task RunServer() 22 | { 23 | 24 | var bossGroup = new MultithreadEventLoopGroup(1); 25 | var workerGroup = new MultithreadEventLoopGroup(); 26 | try 27 | { 28 | var bootstrap = new ServerBootstrap(); 29 | bootstrap 30 | .Group(bossGroup, workerGroup) 31 | .Channel() 32 | .Option(ChannelOption.SoBacklog, 100) 33 | .Handler(new LoggingHandler(LogLevel.INFO)) 34 | .ChildHandler(new ActionSendChannelInitializer(channel => 35 | { 36 | IChannelPipeline pipeline = channel.Pipeline; 37 | 38 | if (EchoServerSettings.IsSsl) 39 | { 40 | pipeline.AddLast(TlsHandler.Server(new X509Certificate2("dotnetty.com.pfx", "password"))); 41 | } 42 | pipeline.AddLast(new LengthFieldPrepender(2)); 43 | pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2)); 44 | 45 | pipeline.AddLast(new EchoServerHandler()); 46 | })); 47 | 48 | IChannel bootstrapChannel = await bootstrap.BindAsync(EchoServerSettings.Port); 49 | 50 | Console.ReadLine(); 51 | 52 | await bootstrapChannel.CloseAsync(); 53 | } 54 | finally 55 | { 56 | Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync()); 57 | 58 | } 59 | } 60 | 61 | static void Main(string[] args) 62 | { 63 | Task.Run(() => RunServer()).Wait(); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /examples/Echo.Server/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Echo.Server")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Echo.Server")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ba163586-f875-4488-9188-53a4a14dfd34")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /examples/Echo.Server/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendCallBack.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using System; 6 | using System.Threading; 7 | using rpc.model; 8 | 9 | public class MessageSendCallBack 10 | { 11 | private MessageRequest request; 12 | private MessageResponse response; 13 | readonly object _lock = new object(); 14 | SpinLock spinlock = new SpinLock(); 15 | 16 | public MessageSendCallBack(MessageRequest request) 17 | { 18 | this.request = request; 19 | } 20 | 21 | public object Start() 22 | { 23 | bool lockTaken = false; 24 | try 25 | { 26 | lock (this._lock) 27 | { 28 | this.spinlock.TryEnter(1000 * 10, ref lockTaken); // set locker timeout 29 | return this.response; 30 | } 31 | } 32 | finally 33 | { 34 | //TODO maybe some callback for caller 35 | //Console.WriteLine("locked response "); 36 | } 37 | } 38 | 39 | public void Over(MessageResponse response) 40 | { 41 | lock (this._lock) 42 | { 43 | this.spinlock.Exit(); // release the lock 44 | this.response = response; 45 | } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendChannelInitializer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using System; 6 | using System.Diagnostics.Contracts; 7 | using DotNetty.Transport.Channels; 8 | using DotNetty.Transport.Channels.Sockets; 9 | using rpc.serialize; 10 | 11 | public class MessageSendChannelInitializer : ChannelInitializer 12 | where T : IChannel 13 | { 14 | readonly Action initializationAction; 15 | ISerializer protocol; 16 | private ISerializeFrame frame =new MessageSendSerializeFrame(); 17 | 18 | public MessageSendChannelInitializer(Action initializationAction) 19 | { 20 | 21 | this.initializationAction = initializationAction; 22 | } 23 | public MessageSendChannelInitializer BuildSerializeProtocol(ISerializer protocol) 24 | { 25 | this.protocol = protocol; 26 | return this; 27 | } 28 | protected override void InitChannel(T channel) 29 | { 30 | this.initializationAction(channel); 31 | IChannelPipeline pipeline = channel.Pipeline; 32 | this.frame.Select(this.protocol,pipeline); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendConnector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using System; 6 | using System.Net; 7 | using System.Security.Cryptography.X509Certificates; 8 | using System.Threading.Tasks; 9 | using DotNetty.Codecs; 10 | using DotNetty.Handlers.Tls; 11 | using DotNetty.Transport.Bootstrapping; 12 | using DotNetty.Transport.Channels; 13 | using DotNetty.Transport.Channels.Sockets; 14 | using rpc.serialize; 15 | 16 | public class MessageSendConnector 17 | { 18 | private IEventLoopGroup eventLoopGroup; 19 | private ISerializer protocol; 20 | IPEndPoint ipEndPoint; 21 | 22 | public MessageSendConnector(IEventLoopGroup eventLoopGroup, IPEndPoint ipEndPoint, ISerializer protocol) 23 | { 24 | this.eventLoopGroup = eventLoopGroup; 25 | this.ipEndPoint = ipEndPoint; 26 | this.protocol = protocol; 27 | } 28 | 29 | public async Task Call() 30 | { 31 | var bootstrap = new Bootstrap(); 32 | bootstrap 33 | .Group(this.eventLoopGroup) 34 | .Channel() 35 | .Option(ChannelOption.SoKeepalive, true) 36 | .Handler(new MessageSendChannelInitializer(channel => 37 | { 38 | //IChannelPipeline pipeline = channel.Pipeline; 39 | 40 | //pipeline.AddLast(new LengthFieldPrepender(2)); 41 | //pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2)); 42 | 43 | //pipeline.AddLast(new MessageSendHandler()); 44 | //RpcServerLoader.Instance.SetMessageSendHandler(pipeline.Get()); 45 | }).BuildSerializeProtocol(new DefaultSerializer())); 46 | 47 | IChannel bootstrapChannel = await bootstrap.ConnectAsync(this.ipEndPoint); 48 | 49 | Console.ReadLine(); 50 | 51 | await bootstrapChannel.CloseAsync(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendExecutor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using System; 6 | using System.Threading; 7 | using NProxy.Core; 8 | using rpc.serialize; 9 | 10 | public class MessageSendExecutor 11 | { 12 | RpcServerLoader loader = RpcServerLoader.Instance; 13 | private static ProxyFactory _proxyFactory; 14 | 15 | public MessageSendExecutor() 16 | { 17 | 18 | } 19 | 20 | public MessageSendExecutor(string serverAddr, int port, ISerializer serializer) 21 | { 22 | this.loader.Load(serverAddr,port,serializer); 23 | 24 | } 25 | 26 | public void SetRpcServerLoader(string serverAddr, int port, ISerializer serializer) 27 | { 28 | this.loader.Load(serverAddr, port, serializer); 29 | 30 | } 31 | 32 | public T Execute() where T : class 33 | { 34 | _proxyFactory = new ProxyFactory(); 35 | var proxy = _proxyFactory.CreateProxy(Type.EmptyTypes, new MessageSendProxy()); 36 | return proxy; 37 | } 38 | 39 | public void Stop() 40 | { 41 | //TODO stop current executor 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace rpc.core 8 | { 9 | using System.Reflection; 10 | using NProxy.Core; 11 | using rpc.model; 12 | 13 | public class MessageSendProxy:IInvocationHandler 14 | { 15 | public object Invoke(object target, MethodInfo methodInfo, object[] parameters) 16 | { 17 | if (methodInfo == null) 18 | { 19 | throw new ArgumentNullException("methodInfo is null"); 20 | } 21 | // get class name 22 | // ReSharper disable once PossibleNullReferenceException 23 | string className = methodInfo.DeclaringType.FullName; 24 | ParameterInfo[] paramWrapper = methodInfo.GetParameters(); 25 | 26 | var request = new MessageRequest(); 27 | request.MessageId = Guid.NewGuid().ToString(); 28 | request.ClassName = methodInfo.DeclaringType.FullName; 29 | request.MethodName = methodInfo.Name; 30 | request.ParamTypes = paramWrapper.Select(s => s.ParameterType).ToArray(); 31 | request.Parameters = parameters; 32 | 33 | MessageSendHandler handler = RpcServerLoader.Instance.GetMessageSendHandler(); 34 | MessageSendCallBack callBack = handler.SendRequest(request); 35 | return callBack.Start(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendSerializeFrame.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using DotNetty.Codecs; 6 | using DotNetty.Transport.Channels; 7 | using rpc.serialize; 8 | 9 | public class MessageSendSerializeFrame:ISerializeFrame 10 | { 11 | public void Select(ISerializer protocol, IChannelPipeline pipeline) 12 | { 13 | 14 | if (protocol.GetType() == typeof(DefaultSerializer)) 15 | { 16 | pipeline.AddLast(new LengthFieldPrepender(2)); 17 | pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2)); 18 | pipeline.AddLast(new MessageSendHandler(protocol)); 19 | } //TODO use pf or other protocal ,now use binary serializer as default 20 | 21 | RpcServerLoader.Instance.SetMessageSendHandler(pipeline.Get()); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /rpc/rpc.core/MessageSendSettings.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using System.Configuration; 6 | using System.Net; 7 | 8 | public static class MessageSendSettings 9 | { 10 | public static IPAddress Host 11 | { 12 | get { return IPAddress.Parse(ConfigurationManager.AppSettings["host"]); } 13 | } 14 | 15 | public static int Port 16 | { 17 | get { return int.Parse(ConfigurationManager.AppSettings["port"]); } 18 | } 19 | 20 | public static int Size 21 | { 22 | get { return int.Parse(ConfigurationManager.AppSettings["size"]); } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /rpc/rpc.core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("rpc.core")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("rpc.core")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ab7e36f6-2f1a-48e2-817e-7187ec7d71fa")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /rpc/rpc.core/RpcServerLoader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.core 4 | { 5 | using System; 6 | using System.Net; 7 | using DotNetty.Transport.Channels; 8 | using rpc.serialize; 9 | 10 | public class RpcServerLoader 11 | { 12 | private static readonly Lazy lazy = new Lazy(()=>new RpcServerLoader()); 13 | private MessageSendHandler messageSendHandler = null; 14 | private readonly IEventLoopGroup eventLoopGroup = new MultithreadEventLoopGroup(); 15 | public static RpcServerLoader Instance { get { return lazy.Value; } } 16 | 17 | private RpcServerLoader() 18 | { 19 | 20 | } 21 | 22 | public async void Load(string serverAddr, int port, ISerializer serializer) 23 | { 24 | var ipEndPoint = new IPEndPoint(IPAddress.Parse(serverAddr), port); 25 | var connector = new MessageSendConnector(this.eventLoopGroup,ipEndPoint,serializer); 26 | 27 | await connector.Call(); // TODO asynchronously run 28 | } 29 | 30 | public void SetMessageSendHandler(MessageSendHandler handler) 31 | { 32 | this.messageSendHandler = handler; //TODO add thread safe lock 33 | } 34 | 35 | public MessageSendHandler GetMessageSendHandler() 36 | { 37 | return this.messageSendHandler; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /rpc/rpc.core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /rpc/rpc.model/MessageRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace rpc.model 8 | { 9 | [Serializable] 10 | public class MessageRequest 11 | { 12 | public string MessageId { get; set; } 13 | 14 | public string ClassName { get; set; } 15 | 16 | public string MethodName { get; set; } 17 | 18 | public Type[] ParamTypes { get; set; } 19 | 20 | public object[] Parameters { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rpc/rpc.model/MessageResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.model 4 | { 5 | using System; 6 | using System.Runtime.Remoting; 7 | 8 | [Serializable] 9 | public class MessageResponse 10 | { 11 | public string MessageId { get; set; } 12 | 13 | public string Error { get; set; } 14 | 15 | public object Result { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /rpc/rpc.model/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("rpc.model")] 9 | [assembly: AssemblyDescription("rpc model definition")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("rpc.model")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0d31ca65-fbc4-43cc-98ad-440cc9433e42")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /rpc/rpc.serialize/DefaultSerializer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.serialize 4 | { 5 | using System; 6 | using System.IO; 7 | using System.Runtime.Serialization.Formatters.Binary; 8 | 9 | public class DefaultSerializer:ISerializer 10 | { 11 | public byte[] Serialize(object target) 12 | { 13 | if (target == null) 14 | return null; 15 | var bf = new BinaryFormatter(); 16 | var ms = new MemoryStream(); 17 | bf.Serialize(ms, target); 18 | return ms.ToArray(); 19 | } 20 | 21 | public object Deserialize(byte[] buffer) 22 | { 23 | var memStream = new MemoryStream(); 24 | var binForm = new BinaryFormatter(); 25 | memStream.Write(buffer, 0, buffer.Length); 26 | memStream.Seek(0, SeekOrigin.Begin); 27 | object obj = binForm.Deserialize(memStream); 28 | return obj; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /rpc/rpc.serialize/ISerializeFrame.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.serialize 4 | { 5 | using DotNetty.Transport.Channels; 6 | 7 | public interface ISerializeFrame 8 | { 9 | void Select(ISerializer protocol, IChannelPipeline pipeline); 10 | } 11 | } -------------------------------------------------------------------------------- /rpc/rpc.serialize/ISerializer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace rpc.serialize 4 | { 5 | public interface ISerializer 6 | { 7 | /// 8 | /// serialize a object to byte array ,for netty client send message 9 | /// 10 | /// 11 | /// 12 | byte[] Serialize(object target); 13 | 14 | /// 15 | /// deserialize byte array received by servier side 16 | /// 17 | /// 18 | /// 19 | object Deserialize(byte[] buffer); 20 | } 21 | } -------------------------------------------------------------------------------- /rpc/rpc.serialize/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("rpc.serialize")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("rpc.serialize")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("eda82365-b05d-4531-9822-bca3c211e014")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /shared/dotnetty.com.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yixincapital/DotNettyRPC/51b7375875120b52abacadc2ea00fe011d7b900a/shared/dotnetty.com.pfx -------------------------------------------------------------------------------- /src/DotNetty.Buffers/AbstractDerivedByteBuffer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | using DotNetty.Common; 7 | 8 | /// 9 | /// Abstract base class for implementations that wrap another 10 | /// . 11 | /// 12 | public abstract class AbstractDerivedByteBuffer : AbstractByteBuffer 13 | { 14 | protected AbstractDerivedByteBuffer(int maxCapacity) 15 | : base(maxCapacity) 16 | { 17 | } 18 | 19 | public sealed override int ReferenceCount 20 | { 21 | get { return this.Unwrap().ReferenceCount; } 22 | } 23 | 24 | public sealed override IReferenceCounted Retain() 25 | { 26 | this.Unwrap().Retain(); 27 | return this; 28 | } 29 | 30 | public sealed override IReferenceCounted Retain(int increment) 31 | { 32 | this.Unwrap().Retain(increment); 33 | return this; 34 | } 35 | 36 | public sealed override IReferenceCounted Touch() 37 | { 38 | this.Unwrap().Touch(); 39 | return this; 40 | } 41 | 42 | public sealed override IReferenceCounted Touch(object hint) 43 | { 44 | this.Unwrap().Touch(hint); 45 | return this; 46 | } 47 | 48 | public sealed override bool Release() 49 | { 50 | return this.Unwrap().Release(); 51 | } 52 | 53 | public sealed override bool Release(int decrement) 54 | { 55 | return this.Unwrap().Release(decrement); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/ByteOrder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | public enum ByteOrder 7 | { 8 | /// 9 | /// Default on most Windows systems 10 | /// 11 | LittleEndian = 0, 12 | BigEndian = 1 13 | } 14 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/DotNetty.Buffers.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @project@@title@ 6 | @build.number@ 7 | @authors@ 8 | @authors@ 9 | Byte buffers support for DotNetty. 10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt 11 | https://github.com/Azure/DotNetty/ 12 | false 13 | @releaseNotes@ 14 | @copyright@ 15 | @tags@ buffers 16 | @dependencies@ 17 | @references@ 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/DotNetty.Buffers/IByteBufferAllocator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | /// 7 | /// Thread-safe interface for allocating instances for use inside Helios reactive I/O 8 | /// 9 | public interface IByteBufferAllocator 10 | { 11 | IByteBuffer Buffer(); 12 | 13 | IByteBuffer Buffer(int initialCapacity); 14 | 15 | IByteBuffer Buffer(int initialCapacity, int maxCapacity); 16 | 17 | CompositeByteBuffer CompositeBuffer(); 18 | 19 | CompositeByteBuffer CompositeBuffer(int maxComponents); 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/IByteBufferHolder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | using DotNetty.Common; 7 | 8 | public interface IByteBufferHolder : IReferenceCounted 9 | { 10 | /// 11 | /// Return the data which is held by this {@link ByteBufHolder}. 12 | /// 13 | IByteBuffer Content { get; } 14 | 15 | /// 16 | /// Create a deep copy of this {@link ByteBufHolder}. 17 | /// 18 | IByteBufferHolder Copy(); 19 | 20 | /// 21 | /// Duplicate the {@link ByteBufHolder}. Be aware that this will not automatically call {@link #retain()}. 22 | /// 23 | IByteBufferHolder Duplicate(); 24 | 25 | //IByteBufferHolder Retain(); 26 | 27 | //IByteBufferHolder Retain(int increment); 28 | 29 | //IByteBufferHolder touch(); 30 | 31 | //IByteBufferHolder touch(object hint); 32 | } 33 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/IllegalReferenceCountException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | using System; 7 | 8 | /// 9 | /// Exception thrown during instances where a reference count is used incorrectly 10 | /// 11 | public class IllegalReferenceCountException : InvalidOperationException 12 | { 13 | public IllegalReferenceCountException(int count) 14 | : base(string.Format("Illegal reference count of {0} for this object", count)) 15 | { 16 | } 17 | 18 | public IllegalReferenceCountException(int refCnt, int increment) 19 | : base("refCnt: " + refCnt + ", " + (increment > 0 ? "increment: " + increment : "decrement: " + -increment)) 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/PooledByteBufferAllocator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | using System.Diagnostics.Contracts; 7 | using DotNetty.Common; 8 | 9 | public class PooledByteBufferAllocator : AbstractByteBufferAllocator 10 | { 11 | readonly ThreadLocalPool pool; 12 | 13 | public PooledByteBufferAllocator(int maxPooledBufSize, int maxLocalPoolSize) 14 | { 15 | Contract.Requires(maxLocalPoolSize > maxPooledBufSize); 16 | 17 | this.MaxPooledBufSize = maxPooledBufSize; 18 | this.pool = new ThreadLocalPool( 19 | handle => new PooledByteBuffer(handle, this, maxPooledBufSize, int.MaxValue), 20 | maxLocalPoolSize / maxPooledBufSize, 21 | false); 22 | } 23 | 24 | public int MaxPooledBufSize { get; private set; } 25 | 26 | protected override IByteBuffer NewBuffer(int initialCapacity, int maxCapacity) 27 | { 28 | if (initialCapacity > this.MaxPooledBufSize) 29 | { 30 | return new UnpooledHeapByteBuffer(this, initialCapacity, maxCapacity); 31 | } 32 | 33 | PooledByteBuffer buffer = this.pool.Take(); 34 | buffer.Init(); 35 | 36 | return ToLeakAwareBuffer(buffer); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | 11 | [assembly: AssemblyTitle("DotNetty.Buffers")] 12 | [assembly: AssemblyDescription("")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyProduct("DotNetty.Buffers")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | 22 | [assembly: ComVisible(false)] 23 | 24 | // The following GUID is for the ID of the typelib if this project is exposed to COM 25 | 26 | [assembly: Guid("0a7e12f0-c77e-484d-a210-dcb82b4b5bf4")] -------------------------------------------------------------------------------- /src/DotNetty.Buffers/SimpleLeakAwareByteBuf.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | using DotNetty.Common; 7 | 8 | sealed class SimpleLeakAwareByteBuf : WrappedByteBuffer 9 | { 10 | readonly IResourceLeak leak; 11 | 12 | internal SimpleLeakAwareByteBuf(IByteBuffer buf, IResourceLeak leak) 13 | : base(buf) 14 | { 15 | this.leak = leak; 16 | } 17 | 18 | public override IReferenceCounted Touch() 19 | { 20 | return this; 21 | } 22 | 23 | public override IReferenceCounted Touch(object hint) 24 | { 25 | return this; 26 | } 27 | 28 | public override bool Release() 29 | { 30 | bool deallocated = base.Release(); 31 | if (deallocated) 32 | { 33 | this.leak.Close(); 34 | } 35 | return deallocated; 36 | } 37 | 38 | public override bool Release(int decrement) 39 | { 40 | bool deallocated = base.Release(decrement); 41 | if (deallocated) 42 | { 43 | this.leak.Close(); 44 | } 45 | return deallocated; 46 | } 47 | 48 | public override IByteBuffer WithOrder(ByteOrder endianness) 49 | { 50 | this.leak.Record(); 51 | if (this.Order == endianness) 52 | { 53 | return this; 54 | } 55 | else 56 | { 57 | return new SimpleLeakAwareByteBuf(base.WithOrder(endianness), this.leak); 58 | } 59 | } 60 | 61 | public override IByteBuffer Slice() 62 | { 63 | return new SimpleLeakAwareByteBuf(base.Slice(), this.leak); 64 | } 65 | 66 | public override IByteBuffer Slice(int index, int length) 67 | { 68 | return new SimpleLeakAwareByteBuf(base.Slice(index, length), this.leak); 69 | } 70 | 71 | public override IByteBuffer Duplicate() 72 | { 73 | return new SimpleLeakAwareByteBuf(base.Duplicate(), this.leak); 74 | } 75 | 76 | public override IByteBuffer ReadSlice(int length) 77 | { 78 | return new SimpleLeakAwareByteBuf(base.ReadSlice(length), this.leak); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /src/DotNetty.Buffers/UnpooledByteBufferAllocator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers 5 | { 6 | /// 7 | /// Unpooled implementation of . 8 | /// 9 | public class UnpooledByteBufferAllocator : AbstractByteBufferAllocator 10 | { 11 | /// 12 | /// Default instance 13 | /// 14 | public static readonly UnpooledByteBufferAllocator Default = new UnpooledByteBufferAllocator(); 15 | 16 | protected override IByteBuffer NewBuffer(int initialCapacity, int maxCapacity) 17 | { 18 | return new UnpooledHeapByteBuffer(this, initialCapacity, maxCapacity); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/DotNetty.Codecs.Mqtt.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @project@@title@ 6 | @build.number@ 7 | @authors@ 8 | @authors@ 9 | Mqtt codec support for DotNetty. 10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt 11 | https://github.com/Azure/DotNetty/ 12 | false 13 | @releaseNotes@ 14 | @copyright@ 15 | @tags@ MQTT codecs 16 | @dependencies@ 17 | @references@ 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/ConnAckPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class ConnAckPacket : Packet 7 | { 8 | public override PacketType PacketType 9 | { 10 | get { return PacketType.CONNACK; } 11 | } 12 | 13 | public bool SessionPresent { get; set; } 14 | 15 | public ConnectReturnCode ReturnCode { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/ConnectPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | using DotNetty.Buffers; 7 | 8 | public sealed class ConnectPacket : Packet 9 | { 10 | public override PacketType PacketType 11 | { 12 | get { return PacketType.CONNECT; } 13 | } 14 | 15 | public string ProtocolName { get; set; } 16 | 17 | public int ProtocolLevel { get; set; } 18 | 19 | public bool CleanSession { get; set; } 20 | 21 | public bool HasWill { get; set; } 22 | 23 | public QualityOfService WillQualityOfService { get; set; } 24 | 25 | public bool WillRetain { get; set; } 26 | 27 | public bool HasPassword { get; set; } 28 | 29 | public bool HasUsername { get; set; } 30 | 31 | public int KeepAliveInSeconds { get; set; } 32 | 33 | public string Username { get; set; } 34 | 35 | public string Password { get; set; } 36 | 37 | public string ClientId { get; set; } 38 | 39 | public string WillTopicName { get; set; } 40 | 41 | public IByteBuffer WillMessage { get; set; } 42 | } 43 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/ConnectReturnCode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public enum ConnectReturnCode 7 | { 8 | Accepted = 0x00, 9 | RefusedUnacceptableProtocolVersion = 0X01, 10 | RefusedIdentifierRejected = 0x02, 11 | RefusedServerUnavailable = 0x03, 12 | RefusedBadUsernameOrPassword = 0x04, 13 | RefusedNotAuthorized = 0x05 14 | } 15 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/DisconnectPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class DisconnectPacket : Packet 7 | { 8 | public static readonly DisconnectPacket Instance = new DisconnectPacket(); 9 | 10 | DisconnectPacket() 11 | { 12 | } 13 | 14 | public override PacketType PacketType 15 | { 16 | get { return PacketType.DISCONNECT; } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/Packet.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public abstract class Packet 7 | { 8 | public abstract PacketType PacketType { get; } 9 | 10 | public virtual bool Duplicate 11 | { 12 | get { return false; } 13 | } 14 | 15 | public virtual QualityOfService QualityOfService 16 | { 17 | get { return QualityOfService.AtMostOnce; } 18 | } 19 | 20 | public virtual bool RetainRequested 21 | { 22 | get { return false; } 23 | } 24 | 25 | public override string ToString() 26 | { 27 | return string.Format("{0}[Type={1}, QualityOfService={2}, Duplicate={3}, Retain={4}]", this.GetType().Name, this.PacketType, this.QualityOfService, this.Duplicate, this.RetainRequested); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PacketType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public enum PacketType 7 | { 8 | // ReSharper disable InconsistentNaming 9 | CONNECT = 1, 10 | CONNACK = 2, 11 | PUBLISH = 3, 12 | PUBACK = 4, 13 | PUBREC = 5, 14 | PUBREL = 6, 15 | PUBCOMP = 7, 16 | SUBSCRIBE = 8, 17 | SUBACK = 9, 18 | UNSUBSCRIBE = 10, 19 | UNSUBACK = 11, 20 | PINGREQ = 12, 21 | PINGRESP = 13, 22 | DISCONNECT = 14 23 | } 24 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PacketWithId.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public abstract class PacketWithId : Packet 7 | { 8 | public int PacketId { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PingReqPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class PingReqPacket : Packet 7 | { 8 | public static readonly PingReqPacket Instance = new PingReqPacket(); 9 | 10 | PingReqPacket() 11 | { 12 | } 13 | 14 | public override PacketType PacketType 15 | { 16 | get { return PacketType.PINGREQ; } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PingRespPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class PingRespPacket : Packet 7 | { 8 | public static readonly PingRespPacket Instance = new PingRespPacket(); 9 | 10 | PingRespPacket() 11 | { 12 | } 13 | 14 | public override PacketType PacketType 15 | { 16 | get { return PacketType.PINGRESP; } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PubAckPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class PubAckPacket : PacketWithId 7 | { 8 | public override PacketType PacketType 9 | { 10 | get { return PacketType.PUBACK; } 11 | } 12 | 13 | public static PubAckPacket InResponseTo(PublishPacket publishPacket) 14 | { 15 | return new PubAckPacket 16 | { 17 | PacketId = publishPacket.PacketId 18 | }; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PubCompPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class PubCompPacket : PacketWithId 7 | { 8 | public override PacketType PacketType 9 | { 10 | get { return PacketType.PUBCOMP; } 11 | } 12 | 13 | public static PubCompPacket InResponseTo(PubRelPacket publishPacket) 14 | { 15 | return new PubCompPacket 16 | { 17 | PacketId = publishPacket.PacketId 18 | }; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PubRecPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class PubRecPacket : PacketWithId 7 | { 8 | public override PacketType PacketType 9 | { 10 | get { return PacketType.PUBREC; } 11 | } 12 | 13 | public static PubRecPacket InResponseTo(PublishPacket publishPacket) 14 | { 15 | return new PubRecPacket 16 | { 17 | PacketId = publishPacket.PacketId 18 | }; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/PubRelPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class PubRelPacket : PacketWithId 7 | { 8 | public override PacketType PacketType 9 | { 10 | get { return PacketType.PUBREL; } 11 | } 12 | 13 | public override QualityOfService QualityOfService 14 | { 15 | get { return QualityOfService.AtLeastOnce; } 16 | } 17 | 18 | public static PubRelPacket InResponseTo(PubRecPacket publishPacket) 19 | { 20 | return new PubRelPacket 21 | { 22 | PacketId = publishPacket.PacketId 23 | }; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/QualityOfService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public enum QualityOfService 7 | { 8 | AtMostOnce = 0, 9 | AtLeastOnce = 0x1, 10 | ExactlyOnce = 0x2, 11 | Reserved = 0x3, 12 | Failure = 0x80 13 | } 14 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/SubAckPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | using System.Collections.Generic; 7 | 8 | public sealed class SubAckPacket : PacketWithId 9 | { 10 | public override PacketType PacketType 11 | { 12 | get { return PacketType.SUBACK; } 13 | } 14 | 15 | public IReadOnlyList ReturnCodes { get; set; } 16 | 17 | public static SubAckPacket InResponseTo(SubscribePacket subscribePacket, QualityOfService maxQoS) 18 | { 19 | var subAckPacket = new SubAckPacket 20 | { 21 | PacketId = subscribePacket.PacketId 22 | }; 23 | IReadOnlyList subscriptionRequests = subscribePacket.Requests; 24 | var returnCodes = new QualityOfService[subscriptionRequests.Count]; 25 | for (int i = 0; i < subscriptionRequests.Count; i++) 26 | { 27 | QualityOfService requestedQos = subscriptionRequests[i].QualityOfService; 28 | returnCodes[i] = requestedQos <= maxQoS ? requestedQos : maxQoS; 29 | } 30 | 31 | subAckPacket.ReturnCodes = returnCodes; 32 | 33 | return subAckPacket; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/SubscribePacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | using System.Collections.Generic; 7 | 8 | public sealed class SubscribePacket : PacketWithId 9 | { 10 | public SubscribePacket() 11 | { 12 | } 13 | 14 | public SubscribePacket(int packetId, params SubscriptionRequest[] requests) 15 | { 16 | this.PacketId = packetId; 17 | this.Requests = requests; 18 | } 19 | 20 | public override PacketType PacketType 21 | { 22 | get { return PacketType.SUBSCRIBE; } 23 | } 24 | 25 | public override QualityOfService QualityOfService 26 | { 27 | get { return QualityOfService.AtLeastOnce; } 28 | } 29 | 30 | public IReadOnlyList Requests { get; set; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/SubscriptionRequest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | using System; 7 | using System.Diagnostics.Contracts; 8 | 9 | public class SubscriptionRequest : IEquatable 10 | { 11 | public SubscriptionRequest(string topicFilter, QualityOfService qualityOfService) 12 | { 13 | Contract.Requires(!string.IsNullOrEmpty(topicFilter)); 14 | 15 | this.TopicFilter = topicFilter; 16 | this.QualityOfService = qualityOfService; 17 | } 18 | 19 | public string TopicFilter { get; private set; } 20 | 21 | public QualityOfService QualityOfService { get; private set; } 22 | 23 | public bool Equals(SubscriptionRequest other) 24 | { 25 | return this.QualityOfService == other.QualityOfService 26 | && this.TopicFilter.Equals(other.TopicFilter, StringComparison.Ordinal); 27 | } 28 | 29 | public override string ToString() 30 | { 31 | return string.Format("{0}[TopicFilter={1}, QualityOfService={2}]", this.GetType().Name, this.TopicFilter, this.QualityOfService); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/UnsubAckPacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | public sealed class UnsubAckPacket : PacketWithId 7 | { 8 | public override PacketType PacketType 9 | { 10 | get { return PacketType.UNSUBACK; } 11 | } 12 | 13 | public static UnsubAckPacket InResponseTo(UnsubscribePacket unsubscribePacket) 14 | { 15 | return new UnsubAckPacket 16 | { 17 | PacketId = unsubscribePacket.PacketId 18 | }; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Packets/UnsubscribePacket.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt.Packets 5 | { 6 | using System.Collections.Generic; 7 | 8 | public sealed class UnsubscribePacket : PacketWithId 9 | { 10 | public UnsubscribePacket() 11 | { 12 | } 13 | 14 | public UnsubscribePacket(int packetId, params string[] topicFilters) 15 | { 16 | this.PacketId = packetId; 17 | this.TopicFilters = topicFilters; 18 | } 19 | 20 | public override PacketType PacketType 21 | { 22 | get { return PacketType.UNSUBSCRIBE; } 23 | } 24 | 25 | public override QualityOfService QualityOfService 26 | { 27 | get { return QualityOfService.AtLeastOnce; } 28 | } 29 | 30 | public IEnumerable TopicFilters { get; set; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Resources; 6 | 7 | [assembly: NeutralResourcesLanguage("en-US")] 8 | [assembly: AssemblyMetadata("Serviceable", "True")] -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Properties/Friends.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | #if !NOTEST 7 | 8 | //[assembly: InternalsVisibleTo("DotNetty.Codecs.Mqtt.Tests")] 9 | 10 | #endif -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Signatures.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt 5 | { 6 | using System.Runtime.CompilerServices; 7 | using DotNetty.Codecs.Mqtt.Packets; 8 | 9 | static class Signatures 10 | { 11 | const byte QoS1Signature = (int)QualityOfService.AtLeastOnce << 1; 12 | 13 | // most often used (anticipated) come first 14 | 15 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 16 | public static bool IsPublish(int signature) 17 | { 18 | const byte TypeOnlyMask = 0xf << 4; 19 | return (signature & TypeOnlyMask) == ((int)PacketType.PUBLISH << 4); 20 | } 21 | 22 | public const byte PubAck = (int)PacketType.PUBACK << 4; 23 | public const byte PubRec = (int)PacketType.PUBREC << 4; 24 | public const byte PubRel = ((int)PacketType.PUBREL << 4) | QoS1Signature; 25 | public const byte PubComp = (int)PacketType.PUBCOMP << 4; 26 | public const byte Connect = (int)PacketType.CONNECT << 4; 27 | public const byte ConnAck = (int)PacketType.CONNACK << 4; 28 | public const byte Subscribe = ((int)PacketType.SUBSCRIBE << 4) | QoS1Signature; 29 | public const byte SubAck = (int)PacketType.SUBACK << 4; 30 | public const byte PingReq = (int)PacketType.PINGREQ << 4; 31 | public const byte PingResp = (int)PacketType.PINGRESP << 4; 32 | public const byte Disconnect = (int)PacketType.DISCONNECT << 4; 33 | public const byte Unsubscribe = ((int)PacketType.UNSUBSCRIBE << 4) | QoS1Signature; 34 | public const byte UnsubAck = (int)PacketType.UNSUBACK << 4; 35 | } 36 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs.Mqtt/Util.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Mqtt 5 | { 6 | static class Util 7 | { 8 | public const string ProtocolName = "MQTT"; 9 | public const int ProtocolLevel = 4; 10 | 11 | static readonly char[] TopicWildcards = { '#', '+' }; 12 | 13 | public static void ValidateTopicName(string topicName) 14 | { 15 | if (topicName.Length == 0) 16 | { 17 | throw new DecoderException("[MQTT-4.7.3-1]"); 18 | } 19 | 20 | if (topicName.IndexOfAny(TopicWildcards) > 0) 21 | { 22 | throw new DecoderException(string.Format("Invalid PUBLISH topic name: {0}", topicName)); 23 | } 24 | } 25 | 26 | public static void ValidatePacketId(int packetId) 27 | { 28 | if (packetId < 1) 29 | { 30 | throw new DecoderException("Invalid packet identifier: " + packetId); 31 | } 32 | } 33 | 34 | public static void ValidateClientId(string clientId) 35 | { 36 | if (clientId == null) 37 | { 38 | throw new DecoderException("Client identifier is required."); 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs/CodecException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs 5 | { 6 | using System; 7 | 8 | /// 9 | /// An which is thrown by a codec. 10 | /// 11 | [Serializable] 12 | public class CodecException : Exception 13 | { 14 | public CodecException() 15 | { 16 | } 17 | 18 | public CodecException(string message, Exception innereException) 19 | : base(message, innereException) 20 | { 21 | } 22 | 23 | public CodecException(string message) 24 | : base(message) 25 | { 26 | } 27 | 28 | public CodecException(Exception innerException) 29 | : base(null, innerException) 30 | { 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs/CorruptedFrameException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace DotNetty.Codecs 4 | { 5 | using System; 6 | 7 | /// 8 | /// A which is thrown when the received frame data could not 9 | /// be decoded by an inbound handler. 10 | /// 11 | public class CorruptedFrameException : DecoderException 12 | { 13 | public CorruptedFrameException(string message) 14 | : base(message) 15 | { 16 | } 17 | 18 | public CorruptedFrameException(Exception cause) 19 | : base(cause) 20 | { 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/DotNetty.Codecs/DecoderException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs 5 | { 6 | using System; 7 | 8 | public class DecoderException : Exception 9 | { 10 | public DecoderException(string message) 11 | : base(message) 12 | { 13 | } 14 | 15 | public DecoderException(Exception cause) 16 | : base(null, cause) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs/DotNetty.Codecs.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @project@@title@ 6 | @build.number@ 7 | @authors@ 8 | @authors@ 9 | Common wire format codecs DotNetty. 10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt 11 | https://github.com/Azure/DotNetty/ 12 | false 13 | @releaseNotes@ 14 | @copyright@ 15 | @tags@ codecs encoding framing decoding 16 | @dependencies@ 17 | @references@ 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/DotNetty.Codecs/EncoderException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs 5 | { 6 | using System; 7 | 8 | public class EncoderException : Exception 9 | { 10 | public EncoderException(string message) 11 | : base(message) 12 | { 13 | } 14 | 15 | public EncoderException(Exception innerException) 16 | : base(null, innerException) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Resources; 6 | 7 | [assembly: NeutralResourcesLanguage("en-US")] 8 | [assembly: AssemblyMetadata("Serviceable", "True")] -------------------------------------------------------------------------------- /src/DotNetty.Codecs/Strings/StringEncoder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using DotNetty.Buffers; 10 | using DotNetty.Transport.Channels; 11 | 12 | /** 13 | * Encodes the requested {@link String} into a {@link ByteBuf}. 14 | * A typical setup for a text-based line protocol in a TCP/IP socket would be: 15 | *
16 |     * {@link ChannelPipeline} pipeline = ...;
17 |     *
18 |     * // Decoders
19 |     * pipeline.addLast("frameDecoder", new {@link LineBasedFrameDecoder}(80));
20 |     * pipeline.addLast("stringDecoder", new {@link StringDecoder}(CharsetUtil.UTF_8));
21 |     *
22 |     * // Encoder
23 |     * pipeline.addLast("stringEncoder", new {@link StringEncoder}(CharsetUtil.UTF_8));
24 |     * 
25 | * and then you can use a {@link String} instead of a {@link ByteBuf} 26 | * as a message: 27 | *
28 |     * void channelRead({@link ChannelHandlerContext} ctx, {@link String} msg) {
29 |     *     ch.write("Did you say '" + msg + "'?\n");
30 |     * }
31 |     * 
32 | */ 33 | public class StringEncoder : MessageToMessageEncoder 34 | { 35 | readonly Encoding encoding; 36 | 37 | /// 38 | /// Initializes a new instance of the class with the current system character set. 39 | /// 40 | public StringEncoder() : this(Encoding.Default) 41 | { 42 | } 43 | 44 | /// 45 | /// Initializes a new instance of the class with the specified character set.. 46 | /// 47 | /// Encoding. 48 | public StringEncoder(Encoding encoding) 49 | { 50 | if (encoding == null) 51 | { 52 | throw new NullReferenceException("encoding"); 53 | } 54 | 55 | this.encoding = encoding; 56 | } 57 | 58 | public override bool IsSharable 59 | { 60 | get { return true; } 61 | } 62 | 63 | protected override void Encode(IChannelHandlerContext context, string message, List output) 64 | { 65 | if (message.Length == 0) 66 | { 67 | return; 68 | } 69 | 70 | output.Add(ByteBufferUtil.EncodeString(context.Allocator, message, encoding)); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/DotNetty.Codecs/TooLongFrameException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | namespace DotNetty.Codecs 4 | { 5 | using System; 6 | 7 | /// 8 | /// A which is thrown when the length of the frame 9 | /// decoded is greater than the allowed maximum. 10 | /// 11 | public class TooLongFrameException : DecoderException 12 | { 13 | public TooLongFrameException(string message) 14 | : base(message) 15 | { 16 | } 17 | 18 | public TooLongFrameException(Exception cause) 19 | : base(cause) 20 | { 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/DotNetty.Codecs/UnsupportedMessageTypeException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs 5 | { 6 | using System; 7 | using System.Text; 8 | 9 | /// 10 | /// Thrown if an unsupported message is received by an codec. 11 | /// 12 | [Serializable] 13 | public class UnsupportedMessageTypeException : CodecException 14 | { 15 | public UnsupportedMessageTypeException( 16 | object message, params Type[] expectedTypes) 17 | : base(ComposeMessage( 18 | message == null ? "null" : message.GetType().Name, expectedTypes)) 19 | { 20 | } 21 | 22 | public UnsupportedMessageTypeException() 23 | { 24 | } 25 | 26 | public UnsupportedMessageTypeException(string message, Exception innerException) 27 | : base(message, innerException) 28 | { 29 | } 30 | 31 | public UnsupportedMessageTypeException(string message) 32 | : base(message) 33 | { 34 | } 35 | 36 | public UnsupportedMessageTypeException(Exception innerException) 37 | : base(innerException) 38 | { 39 | } 40 | 41 | static string ComposeMessage(string actualType, params Type[] expectedTypes) 42 | { 43 | var buf = new StringBuilder(actualType); 44 | 45 | if (expectedTypes != null && expectedTypes.Length > 0) 46 | { 47 | buf.Append(" (expected: ").Append(expectedTypes[0].Name); 48 | for (int i = 1; i < expectedTypes.Length; i++) 49 | { 50 | Type t = expectedTypes[i]; 51 | if (t == null) 52 | { 53 | break; 54 | } 55 | buf.Append(", ").Append(t.Name); 56 | } 57 | buf.Append(')'); 58 | } 59 | 60 | return buf.ToString(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/ActionScheduledAsyncTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | using System.Threading; 8 | 9 | sealed class ActionScheduledAsyncTask : ScheduledAsyncTask 10 | { 11 | readonly Action action; 12 | 13 | public ActionScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action action, PreciseTimeSpan deadline, CancellationToken cancellationToken) 14 | : base(executor, deadline, new TaskCompletionSource(), cancellationToken) 15 | { 16 | this.action = action; 17 | } 18 | 19 | protected override void Execute() 20 | { 21 | this.action(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/ActionScheduledTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | 8 | sealed class ActionScheduledTask : ScheduledTask 9 | { 10 | readonly Action action; 11 | 12 | public ActionScheduledTask(AbstractScheduledEventExecutor executor, Action action, PreciseTimeSpan deadline) 13 | : base(executor, deadline, new TaskCompletionSource()) 14 | { 15 | this.action = action; 16 | } 17 | 18 | protected override void Execute() 19 | { 20 | this.action(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/ExecutorTaskScheduler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | using DotNetty.Common.Utilities; 9 | 10 | public sealed class ExecutorTaskScheduler : TaskScheduler 11 | { 12 | readonly IEventExecutor executor; 13 | bool started; 14 | 15 | public ExecutorTaskScheduler(IEventExecutor executor) 16 | { 17 | this.executor = executor; 18 | } 19 | 20 | protected override void QueueTask(Task task) 21 | { 22 | if (this.started) 23 | { 24 | this.executor.Execute(new TaskQueueNode(this, task)); 25 | } 26 | else 27 | { 28 | // hack: enables this executor to be seen as default on Executor's worker thread. 29 | // This is a special case for SingleThreadEventExecutor.Loop initiated task. 30 | this.started = true; 31 | this.TryExecuteTask(task); 32 | } 33 | } 34 | 35 | protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued) 36 | { 37 | if (taskWasPreviouslyQueued || !this.executor.InEventLoop) 38 | { 39 | return false; 40 | } 41 | 42 | return this.TryExecuteTask(task); 43 | } 44 | 45 | protected override IEnumerable GetScheduledTasks() 46 | { 47 | return null; 48 | } 49 | 50 | protected override bool TryDequeue(Task task) 51 | { 52 | return false; 53 | } 54 | 55 | sealed class TaskQueueNode : MpscLinkedQueueNode, IRunnable 56 | { 57 | readonly ExecutorTaskScheduler scheduler; 58 | readonly Task task; 59 | 60 | public TaskQueueNode(ExecutorTaskScheduler scheduler, Task task) 61 | { 62 | this.scheduler = scheduler; 63 | this.task = task; 64 | } 65 | 66 | public override IRunnable Value 67 | { 68 | get { return this; } 69 | } 70 | 71 | public void Run() 72 | { 73 | this.scheduler.TryExecuteTask(this.task); 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/ICallable`T.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | public interface ICallable 7 | { 8 | T Call(); 9 | } 10 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/IPausableEventExecutor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | /// 7 | /// Implement this interface if you need your {@link EventExecutor} implementation to be able 8 | /// to reject new work. 9 | /// 10 | public interface IPausableEventExecutor : IWrappedEventExecutor 11 | { 12 | /// 13 | /// After a call to this method the {@link EventExecutor} may throw a {@link RejectedExecutionException} when 14 | /// attempting to assign new work to it (i.e. through a call to {@link EventExecutor#execute(Runnable)}). 15 | /// 16 | void RejectNewTasks(); 17 | 18 | /// 19 | /// With a call to this method the {@link EventExecutor} signals that it is now accepting new work. 20 | /// 21 | void AcceptNewTasks(); 22 | 23 | /// 24 | /// Returns {@code true} if and only if this {@link EventExecutor} is accepting a new task. 25 | /// 26 | bool IsAcceptingNewTasks { get; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/IRunnable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | public interface IRunnable 7 | { 8 | void Run(); 9 | } 10 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/IScheduledRunnable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | 8 | public interface IScheduledRunnable : IRunnable, IScheduledTask, IComparable 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/IScheduledTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System.Runtime.CompilerServices; 7 | using System.Threading.Tasks; 8 | 9 | public interface IScheduledTask 10 | { 11 | bool Cancel(); 12 | 13 | PreciseTimeSpan Deadline { get; } 14 | 15 | Task Completion { get; } 16 | 17 | TaskAwaiter GetAwaiter(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/IWrappedEventExecutor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | public interface IWrappedEventExecutor : IEventExecutor 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/ScheduledAsyncTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System.Threading; 7 | 8 | abstract class ScheduledAsyncTask : ScheduledTask 9 | { 10 | readonly CancellationToken cancellationToken; 11 | CancellationTokenRegistration cancellationTokenRegistration; 12 | 13 | protected ScheduledAsyncTask(AbstractScheduledEventExecutor executor, PreciseTimeSpan deadline, TaskCompletionSource promise, CancellationToken cancellationToken) 14 | : base(executor, deadline, promise) 15 | { 16 | this.cancellationToken = cancellationToken; 17 | this.cancellationTokenRegistration = cancellationToken.Register(s => ((ScheduledAsyncTask)s).Cancel(), this); 18 | } 19 | 20 | public override void Run() 21 | { 22 | this.cancellationTokenRegistration.Dispose(); 23 | if (this.cancellationToken.IsCancellationRequested) 24 | { 25 | this.Promise.TrySetCanceled(); 26 | } 27 | else 28 | { 29 | base.Run(); 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/StateActionScheduledAsyncTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | using System.Threading; 8 | 9 | sealed class StateActionScheduledAsyncTask : ScheduledAsyncTask 10 | { 11 | readonly Action action; 12 | 13 | public StateActionScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action action, object state, PreciseTimeSpan deadline, 14 | CancellationToken cancellationToken) 15 | : base(executor, deadline, new TaskCompletionSource(state), cancellationToken) 16 | { 17 | this.action = action; 18 | } 19 | 20 | protected override void Execute() 21 | { 22 | this.action(this.Completion.AsyncState); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/StateActionScheduledTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | 8 | sealed class StateActionScheduledTask : ScheduledTask 9 | { 10 | readonly Action action; 11 | 12 | public StateActionScheduledTask(AbstractScheduledEventExecutor executor, Action action, object state, PreciseTimeSpan deadline) 13 | : base(executor, deadline, new TaskCompletionSource(state)) 14 | { 15 | this.action = action; 16 | } 17 | 18 | protected override void Execute() 19 | { 20 | this.action(this.Completion.AsyncState); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/StateActionWithContextScheduledAsyncTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | using System.Threading; 8 | 9 | sealed class StateActionWithContextScheduledAsyncTask : ScheduledAsyncTask 10 | { 11 | readonly Action action; 12 | readonly object context; 13 | 14 | public StateActionWithContextScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action action, object context, object state, 15 | PreciseTimeSpan deadline, CancellationToken cancellationToken) 16 | : base(executor, deadline, new TaskCompletionSource(state), cancellationToken) 17 | { 18 | this.action = action; 19 | this.context = context; 20 | } 21 | 22 | protected override void Execute() 23 | { 24 | this.action(this.context, this.Completion.AsyncState); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/StateActionWithContextScheduledTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System; 7 | 8 | sealed class StateActionWithContextScheduledTask : ScheduledTask 9 | { 10 | readonly Action action; 11 | readonly object context; 12 | 13 | public StateActionWithContextScheduledTask(AbstractScheduledEventExecutor executor, Action action, object context, object state, 14 | PreciseTimeSpan deadline) 15 | : base(executor, deadline, new TaskCompletionSource(state)) 16 | { 17 | this.action = action; 18 | this.context = context; 19 | } 20 | 21 | protected override void Execute() 22 | { 23 | this.action(this.context, this.Completion.AsyncState); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Concurrency/TaskCompletionSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Concurrency 5 | { 6 | using System.Threading.Tasks; 7 | 8 | public sealed class TaskCompletionSource : TaskCompletionSource 9 | { 10 | public static readonly TaskCompletionSource Void = CreateVoidTcs(); 11 | 12 | public TaskCompletionSource(object state) 13 | : base(state) 14 | { 15 | } 16 | 17 | public TaskCompletionSource() 18 | { 19 | } 20 | 21 | public bool TryComplete() 22 | { 23 | return this.TrySetResult(0); 24 | } 25 | 26 | public void Complete() 27 | { 28 | this.SetResult(0); 29 | } 30 | 31 | public bool setUncancellable() 32 | { 33 | // todo: support cancellation token where used 34 | return true; 35 | } 36 | 37 | public override string ToString() 38 | { 39 | return "TaskCompletionSource[status: " + this.Task.Status.ToString() + "]"; 40 | } 41 | 42 | static TaskCompletionSource CreateVoidTcs() 43 | { 44 | var tcs = new TaskCompletionSource(); 45 | tcs.TryComplete(); 46 | return tcs; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/DotNetty.Common.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @project@@title@ 6 | @build.number@ 7 | @authors@ 8 | @authors@ 9 | DotNetty is a port of netty framework. It is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers and clients. 10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt 11 | https://github.com/Azure/DotNetty/ 12 | false 13 | @releaseNotes@ 14 | @copyright@ 15 | @tags@ 16 | @dependencies@ 17 | @references@ 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/DotNetty.Common/IReferenceCounted.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common 5 | { 6 | /// 7 | /// Reference counting interface for reusable objects 8 | /// 9 | public interface IReferenceCounted 10 | { 11 | /// 12 | /// Returns the reference count of this object 13 | /// 14 | int ReferenceCount { get; } 15 | 16 | /// 17 | /// Increases the reference count by 1 18 | /// 19 | IReferenceCounted Retain(); 20 | 21 | /// 22 | /// Increases the reference count by . 23 | /// 24 | IReferenceCounted Retain(int increment); 25 | 26 | /// 27 | /// Records the current access location of this object for debugging purposes. 28 | /// If this object is determined to be leaked, the information recorded by this operation will be provided to you 29 | /// via . This method is a shortcut to with null as an argument. 30 | /// 31 | /// 32 | IReferenceCounted Touch(); 33 | 34 | /// 35 | /// Records the current access location of this object with an additonal arbitrary information for debugging 36 | /// purposes. If this object is determined to be leaked, the information recorded by this operation will be 37 | /// provided to you via . 38 | /// 39 | IReferenceCounted Touch(object hint); 40 | 41 | /// 42 | /// Decreases the reference count by 1 and deallocates this object if the reference count reaches 0. 43 | /// 44 | /// true if and only if the reference count is 0 and this object has been deallocated 45 | bool Release(); 46 | 47 | /// 48 | /// Decreases the reference count by and deallocates this object if the reference count reaches 0. 49 | /// 50 | /// true if and only if the reference count is 0 and this object has been deallocated 51 | bool Release(int decrement); 52 | } 53 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/IResourceLeak.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common 5 | { 6 | public interface IResourceLeak 7 | { 8 | /// 9 | /// Records the caller's current stack trace so that the can tell where the 10 | /// leaked 11 | /// resource was accessed lastly. This method is a shortcut to with null as an 12 | /// argument. 13 | /// 14 | void Record(); 15 | 16 | /// 17 | /// Records the caller's current stack trace and the specified additional arbitrary information 18 | /// so that the can tell where the leaked resource was accessed lastly. 19 | /// 20 | /// 21 | void Record(object hint); 22 | 23 | /// 24 | /// Close the leak so that does not warn about leaked resources. 25 | /// 26 | /// true if called first time, false if called already 27 | bool Close(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/IResourceLeakHint.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common 5 | { 6 | /// 7 | /// A hint object that provides human-readable message for easier resource leak tracking. 8 | /// 9 | public interface IResourceLeakHint 10 | { 11 | /// 12 | /// Returns a human-readable message that potentially enables easier resource leak tracking. 13 | /// 14 | /// 15 | string ToHintString(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Internal/Logging/EventSourceLoggerFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Internal.Logging 5 | { 6 | class EventSourceLoggerFactory : InternalLoggerFactory 7 | { 8 | protected internal override IInternalLogger NewInstance(string name) 9 | { 10 | return new EventSourceLogger(name); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Internal/Logging/FormattingTuple.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Internal.Logging 5 | { 6 | using System; 7 | using System.Diagnostics.Contracts; 8 | 9 | /// 10 | /// Holds the results of formatting done by {@link MessageFormatter}. 11 | /// 12 | class FormattingTuple 13 | { 14 | static readonly FormattingTuple NULL = new FormattingTuple(null); 15 | 16 | public FormattingTuple(string message) 17 | : this(message, null, null) 18 | { 19 | } 20 | 21 | public FormattingTuple(string message, object[] argArray, Exception exception) 22 | { 23 | this.Message = message; 24 | this.Exception = exception; 25 | if (exception == null) 26 | { 27 | this.ArgArray = argArray; 28 | } 29 | else 30 | { 31 | this.ArgArray = GetTrimmedCopy(argArray); 32 | } 33 | } 34 | 35 | static object[] GetTrimmedCopy(object[] argArray) 36 | { 37 | Contract.Requires(argArray != null && argArray.Length > 0); 38 | 39 | int trimemdLen = argArray.Length - 1; 40 | var trimmed = new object[trimemdLen]; 41 | Array.Copy(argArray, 0, trimmed, 0, trimemdLen); 42 | return trimmed; 43 | } 44 | 45 | public string Message { get; private set; } 46 | 47 | public object[] ArgArray { get; private set; } 48 | 49 | public Exception Exception { get; private set; } 50 | } 51 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Internal/Logging/InternalLogLevel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Internal.Logging 5 | { 6 | /// The log level that {@link IInternalLogger} can log at. 7 | public enum InternalLogLevel 8 | { 9 | /// 10 | /// 'TRACE' log level. 11 | /// 12 | TRACE, 13 | 14 | /// 15 | /// 'DEBUG' log level. 16 | /// 17 | DEBUG, 18 | 19 | /// 20 | /// 'INFO' log level. 21 | /// 22 | INFO, 23 | 24 | /// 25 | /// 'WARN' log level. 26 | /// 27 | WARN, 28 | 29 | /// 30 | /// 'ERROR' log level. 31 | /// 32 | ERROR 33 | } 34 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Resources; 6 | 7 | [assembly: NeutralResourcesLanguage("en-US")] 8 | [assembly: AssemblyMetadata("Serviceable", "True")] -------------------------------------------------------------------------------- /src/DotNetty.Common/Properties/Friends.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | #if !NOTEST 7 | 8 | //[assembly: InternalsVisibleTo("DotNetty.Common.Tests")] 9 | 10 | #endif -------------------------------------------------------------------------------- /src/DotNetty.Common/ThreadLocalObjectList.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common 5 | { 6 | using System.Collections.Generic; 7 | 8 | public class ThreadLocalObjectList : List 9 | { 10 | static readonly ThreadLocalPool Pool = new ThreadLocalPool(handle => new ThreadLocalObjectList(handle)); 11 | 12 | readonly ThreadLocalPool.Handle returnHandle; 13 | 14 | ThreadLocalObjectList(ThreadLocalPool.Handle returnHandle) 15 | { 16 | this.returnHandle = returnHandle; 17 | } 18 | 19 | public static ThreadLocalObjectList Take() 20 | { 21 | return Pool.Take(); 22 | } 23 | 24 | public void Return() 25 | { 26 | this.Clear(); 27 | this.returnHandle.Release(this); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Utilities/BitOps.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Utilities 5 | { 6 | using System.Runtime.CompilerServices; 7 | 8 | public static class BitOps 9 | { 10 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 11 | public static int RightUShift(this int value, int bits) 12 | { 13 | return unchecked((int)((uint)value >> bits)); 14 | } 15 | 16 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 17 | public static long RightUShift(this long value, int bits) 18 | { 19 | return unchecked((long)((ulong)value >> bits)); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Utilities/ByteArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Utilities 5 | { 6 | using System; 7 | using System.Diagnostics.Contracts; 8 | 9 | /// 10 | /// Extension methods used for slicing byte arrays 11 | /// 12 | public static class ByteArrayExtensions 13 | { 14 | public static readonly byte[] Empty = new byte[0]; 15 | 16 | public static byte[] Slice(this byte[] array, int length) 17 | { 18 | Contract.Requires(array != null); 19 | 20 | if (length > array.Length) 21 | { 22 | throw new ArgumentOutOfRangeException("length", string.Format("length({0}) cannot be longer than Array.length({1})", length, array.Length)); 23 | } 24 | return Slice(array, 0, length); 25 | } 26 | 27 | public static byte[] Slice(this byte[] array, int index, int length) 28 | { 29 | Contract.Requires(array != null); 30 | 31 | if (index + length > array.Length) 32 | { 33 | throw new ArgumentOutOfRangeException("length", string.Format("index: ({0}), length({1}) index + length cannot be longer than Array.length({2})", index, length, array.Length)); 34 | } 35 | var result = new byte[length]; 36 | Array.Copy(array, index, result, 0, length); 37 | return result; 38 | } 39 | 40 | public static void SetRange(this byte[] array, int index, byte[] src) 41 | { 42 | SetRange(array, index, src, 0, src.Length); 43 | } 44 | 45 | public static void SetRange(this byte[] array, int index, byte[] src, int srcIndex, int srcLength) 46 | { 47 | Contract.Requires(array != null); 48 | Contract.Requires(src != null); 49 | if (index + srcLength > array.Length) 50 | { 51 | throw new ArgumentOutOfRangeException("srcLength", string.Format("index: ({0}), srcLength({1}) index + length cannot be longer than Array.length({2})", index, srcLength, array.Length)); 52 | } 53 | if (srcIndex + srcLength > src.Length) 54 | { 55 | throw new ArgumentOutOfRangeException("srcLength", string.Format("index: ({0}), srcLength({1}) index + length cannot be longer than src.length({2})", srcIndex, srcLength, src.Length)); 56 | } 57 | 58 | Array.Copy(src, srcIndex, array, index, srcLength); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Utilities/DebugExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Utilities 5 | { 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | public static class DebugExtensions 10 | { 11 | public static string ToDebugString(this IDictionary dictionary) 12 | { 13 | var sb = new StringBuilder(); 14 | bool first = true; 15 | foreach (KeyValuePair pair in dictionary) 16 | { 17 | if (first) 18 | { 19 | first = false; 20 | sb.Append('{'); 21 | } 22 | else 23 | { 24 | sb.Append(", "); 25 | } 26 | 27 | sb.Append("{`").Append(pair.Key).Append("`: ").Append(pair.Value).Append('}'); 28 | } 29 | return sb.Append('}').ToString(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/DotNetty.Common/Utilities/RecyclableMpscLinkedQueueNode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Utilities 5 | { 6 | using System.Diagnostics.Contracts; 7 | 8 | public abstract class RecyclableMpscLinkedQueueNode : MpscLinkedQueueNode 9 | { 10 | readonly ThreadLocalPool.Handle handle; 11 | 12 | protected RecyclableMpscLinkedQueueNode(ThreadLocalPool.Handle handle) 13 | { 14 | Contract.Requires(handle != null); 15 | this.handle = handle; 16 | } 17 | 18 | internal override void Unlink() 19 | { 20 | base.Unlink(); 21 | this.handle.Release(this); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/DotNetty.Handlers/DotNetty.Handlers.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @project@@title@ 6 | @build.number@ 7 | @authors@ 8 | @authors@ 9 | TLS and other handler support DotNetty. 10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt 11 | https://github.com/Azure/DotNetty/ 12 | false 13 | @releaseNotes@ 14 | @copyright@ 15 | @tags@ TLS SSL handlers 16 | @dependencies@ 17 | @references@ 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/DotNetty.Handlers/Logging/LogLevel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Handlers.Logging 5 | { 6 | using DotNetty.Common.Internal.Logging; 7 | 8 | public enum LogLevel 9 | { 10 | TRACE = InternalLogLevel.TRACE, 11 | DEBUG = InternalLogLevel.DEBUG, 12 | INFO = InternalLogLevel.INFO, 13 | WARN = InternalLogLevel.WARN, 14 | ERROR = InternalLogLevel.ERROR, 15 | } 16 | } -------------------------------------------------------------------------------- /src/DotNetty.Handlers/Logging/LogLevelExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Handlers.Logging 5 | { 6 | using DotNetty.Common.Internal.Logging; 7 | 8 | public static class LogLevelExtensions 9 | { 10 | public static InternalLogLevel ToInternalLevel(this LogLevel level) 11 | { 12 | return (InternalLogLevel)level; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/DotNetty.Handlers/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Resources; 6 | 7 | [assembly: NeutralResourcesLanguage("en-US")] 8 | [assembly: AssemblyMetadata("Serviceable", "True")] -------------------------------------------------------------------------------- /src/DotNetty.Handlers/Tls/TlsHandshakeCompletionEvent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Handlers.Tls 5 | { 6 | using System; 7 | using System.Diagnostics.Contracts; 8 | 9 | public sealed class TlsHandshakeCompletionEvent 10 | { 11 | public static readonly TlsHandshakeCompletionEvent Success = new TlsHandshakeCompletionEvent(); 12 | 13 | readonly Exception exception; 14 | 15 | /// 16 | /// Creates a new event that indicates a successful handshake. 17 | /// 18 | TlsHandshakeCompletionEvent() 19 | { 20 | this.exception = null; 21 | } 22 | 23 | /// 24 | /// Creates a new event that indicates an unsuccessful handshake. 25 | /// Use {@link #SUCCESS} to indicate a successful handshake. 26 | /// 27 | public TlsHandshakeCompletionEvent(Exception exception) 28 | { 29 | Contract.Requires(exception != null); 30 | 31 | this.exception = exception; 32 | } 33 | 34 | /// 35 | /// Return {@code true} if the handshake was successful 36 | /// 37 | public bool IsSuccessful 38 | { 39 | get { return this.exception == null; } 40 | } 41 | 42 | /// 43 | /// Return the {@link Throwable} if {@link #isSuccess()} returns {@code false} 44 | /// and so the handshake failed. 45 | /// 46 | public Exception Exception 47 | { 48 | get { return this.exception; } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Bootstrapping/DefaultNameResolver.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Bootstrapping 5 | { 6 | using System.Net; 7 | using System.Threading.Tasks; 8 | 9 | public class DefaultNameResolver : INameResolver 10 | { 11 | public bool IsResolved(EndPoint address) 12 | { 13 | return !(address is DnsEndPoint); 14 | } 15 | 16 | public async Task ResolveAsync(EndPoint address) 17 | { 18 | var asDns = address as DnsEndPoint; 19 | if (asDns != null) 20 | { 21 | IPHostEntry resolved = await Dns.GetHostEntryAsync(asDns.Host); 22 | return new IPEndPoint(resolved.AddressList[0], asDns.Port); 23 | } 24 | else 25 | { 26 | return address; 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Bootstrapping/INameResolver.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Bootstrapping 5 | { 6 | using System.Net; 7 | using System.Threading.Tasks; 8 | 9 | public interface INameResolver 10 | { 11 | bool IsResolved(EndPoint address); 12 | 13 | Task ResolveAsync(EndPoint address); 14 | } 15 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/ActionChannelInitializer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | using System.Diagnostics.Contracts; 8 | 9 | public sealed class ActionSendChannelInitializer : ChannelInitializer 10 | where T : IChannel 11 | { 12 | readonly Action initializationAction; 13 | 14 | public ActionSendChannelInitializer(Action initializationAction) 15 | { 16 | Contract.Requires(initializationAction != null); 17 | 18 | this.initializationAction = initializationAction; 19 | } 20 | 21 | protected override void InitChannel(T channel) 22 | { 23 | this.initializationAction(channel); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/ChannelException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | using System.Runtime.Serialization; 8 | 9 | [Serializable] 10 | public class ChannelException : Exception 11 | { 12 | public ChannelException() 13 | { 14 | } 15 | 16 | public ChannelException(string message) 17 | : base(message) 18 | { 19 | } 20 | 21 | public ChannelException(string message, Exception innerException) 22 | : base(message, innerException) 23 | { 24 | } 25 | 26 | protected ChannelException(SerializationInfo info, StreamingContext context) 27 | : base(info, context) 28 | { 29 | } 30 | 31 | public ChannelException(Exception innerException) 32 | : base(null, innerException) 33 | { 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/ChannelPipelineException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | 8 | class ChannelPipelineException : Exception 9 | { 10 | public ChannelPipelineException(string message) 11 | : base(message) 12 | { 13 | } 14 | 15 | public ChannelPipelineException(string message, Exception innerException) 16 | : base(message, innerException) 17 | { 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/ClosedChannelException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.IO; 7 | 8 | public class ClosedChannelException : IOException 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/ConnectException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | 8 | public class ConnectException : Exception 9 | { 10 | public ConnectException(string message, Exception innerException) 11 | : base(message, innerException) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/ConnectTimeoutException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.IO; 7 | 8 | public class ConnectTimeoutException : IOException 9 | { 10 | public ConnectTimeoutException(string message) 11 | : base(message) 12 | { 13 | } 14 | 15 | public ConnectTimeoutException() 16 | { 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/DefaultChannelHandlerContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Diagnostics.Contracts; 7 | 8 | sealed class DefaultChannelHandlerContext : AbstractChannelHandlerContext 9 | { 10 | readonly IChannelHandler handler; 11 | 12 | public DefaultChannelHandlerContext( 13 | DefaultChannelPipeline pipeline, IChannelHandlerInvoker invoker, string name, IChannelHandler handler) 14 | : base(pipeline, invoker, name, GetSkipPropagationFlags(handler)) 15 | { 16 | Contract.Requires(handler != null); 17 | 18 | this.handler = handler; 19 | } 20 | 21 | public override IChannelHandler Handler 22 | { 23 | get { return this.handler; } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/DefaultMessageSizeEstimator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Diagnostics.Contracts; 7 | using DotNetty.Buffers; 8 | 9 | public sealed class DefaultMessageSizeEstimator : IMessageSizeEstimator 10 | { 11 | sealed class HandleImpl : IMessageSizeEstimatorHandle 12 | { 13 | readonly int unknownSize; 14 | 15 | public HandleImpl(int unknownSize) 16 | { 17 | this.unknownSize = unknownSize; 18 | } 19 | 20 | public int Size(object msg) 21 | { 22 | if (msg is IByteBuffer) 23 | { 24 | return ((IByteBuffer)msg).ReadableBytes; 25 | } 26 | if (msg is IByteBufferHolder) 27 | { 28 | return ((IByteBufferHolder)msg).Content.ReadableBytes; 29 | } 30 | // todo: FileRegion support 31 | //if (msg instanceof FileRegion) { 32 | // return 0; 33 | //} 34 | return this.unknownSize; 35 | } 36 | } 37 | 38 | /// 39 | /// Return the default implementation which returns {@code -1} for unknown messages. 40 | /// 41 | public static readonly IMessageSizeEstimator Default = new DefaultMessageSizeEstimator(0); 42 | 43 | readonly IMessageSizeEstimatorHandle handle; 44 | 45 | /// 46 | /// Create a new instance 47 | /// 48 | /// @param unknownSize The size which is returned for unknown messages. 49 | /// 50 | public DefaultMessageSizeEstimator(int unknownSize) 51 | { 52 | Contract.Requires(unknownSize >= 0); 53 | this.handle = new HandleImpl(unknownSize); 54 | } 55 | 56 | public IMessageSizeEstimatorHandle NewHandle() 57 | { 58 | return this.handle; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Embedded/EmbeddedChannelId.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Embedded 5 | { 6 | using System; 7 | 8 | /// 9 | /// A dummy implementation 10 | /// 11 | public sealed class EmbeddedChannelId : IChannelId 12 | { 13 | public static readonly EmbeddedChannelId Instance = new EmbeddedChannelId(); 14 | 15 | EmbeddedChannelId() 16 | { 17 | } 18 | 19 | public override int GetHashCode() 20 | { 21 | return 0; 22 | } 23 | 24 | public override bool Equals(object obj) 25 | { 26 | return obj is EmbeddedChannelId; 27 | } 28 | 29 | public int CompareTo(IChannelId other) 30 | { 31 | if (other is EmbeddedChannelId) 32 | { 33 | return 0; 34 | } 35 | return string.Compare(this.AsLongText(), other.AsLongText(), StringComparison.Ordinal); 36 | } 37 | 38 | public override string ToString() 39 | { 40 | return "embedded"; 41 | } 42 | 43 | public string AsShortText() 44 | { 45 | return this.ToString(); 46 | } 47 | 48 | public string AsLongText() 49 | { 50 | return this.ToString(); 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Embedded/EmbeddedSocketAddress.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Embedded 5 | { 6 | using System.Net; 7 | 8 | sealed class EmbeddedSocketAddress : EndPoint 9 | { 10 | public override string ToString() 11 | { 12 | return "embedded"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/FixedRecvByteBufAllocator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Diagnostics.Contracts; 7 | using DotNetty.Buffers; 8 | 9 | /// 10 | /// The {@link RecvByteBufAllocator} that always yields the same buffer 11 | /// size prediction. This predictor ignores the feedback from the I/O thread. 12 | /// 13 | public sealed class FixedRecvByteBufAllocator : IRecvByteBufAllocator 14 | { 15 | public static readonly FixedRecvByteBufAllocator Default = new FixedRecvByteBufAllocator(4 * 1024); 16 | 17 | sealed class HandleImpl : IRecvByteBufAllocatorHandle 18 | { 19 | readonly int bufferSize; 20 | 21 | public HandleImpl(int bufferSize) 22 | { 23 | this.bufferSize = bufferSize; 24 | } 25 | 26 | public IByteBuffer Allocate(IByteBufferAllocator alloc) 27 | { 28 | return alloc.Buffer(this.bufferSize); 29 | } 30 | 31 | public int Guess() 32 | { 33 | return this.bufferSize; 34 | } 35 | 36 | public void Record(int actualReadBytes) 37 | { 38 | } 39 | } 40 | 41 | readonly IRecvByteBufAllocatorHandle handle; 42 | 43 | /// 44 | /// Creates a new predictor that always returns the same prediction of 45 | /// the specified buffer size. 46 | /// 47 | public FixedRecvByteBufAllocator(int bufferSize) 48 | { 49 | Contract.Requires(bufferSize > 0); 50 | 51 | this.handle = new HandleImpl(bufferSize); 52 | } 53 | 54 | public IRecvByteBufAllocatorHandle NewHandle() 55 | { 56 | return this.handle; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Groups/ChannelGroupException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Groups 5 | { 6 | using System; 7 | using System.Collections; 8 | using System.Collections.Generic; 9 | using System.Collections.ObjectModel; 10 | 11 | public class ChannelGroupException : ChannelException, IEnumerable> 12 | { 13 | readonly IReadOnlyCollection> failed; 14 | 15 | public ChannelGroupException(IList> exceptions) 16 | { 17 | if (exceptions == null) 18 | { 19 | throw new ArgumentNullException("exceptions"); 20 | } 21 | if (exceptions.Count == 0) 22 | { 23 | throw new ArgumentException("excetpions must be not empty."); 24 | } 25 | this.failed = new ReadOnlyCollection>(exceptions); 26 | } 27 | 28 | public IEnumerator> GetEnumerator() 29 | { 30 | return this.failed.GetEnumerator(); 31 | } 32 | 33 | IEnumerator IEnumerable.GetEnumerator() 34 | { 35 | return this.failed.GetEnumerator(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Groups/CombinedEnumerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Groups 5 | { 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Diagnostics.Contracts; 9 | 10 | public sealed class CombinedEnumerator : IEnumerator 11 | { 12 | readonly IEnumerator e1; 13 | readonly IEnumerator e2; 14 | IEnumerator currentEnumerator; 15 | 16 | public CombinedEnumerator(IEnumerator e1, IEnumerator e2) 17 | { 18 | Contract.Requires(e1 != null); 19 | Contract.Requires(e2 != null); 20 | this.e1 = e1; 21 | this.e2 = e2; 22 | this.currentEnumerator = e1; 23 | } 24 | 25 | public E Current 26 | { 27 | get { return this.currentEnumerator.Current; } 28 | } 29 | 30 | public void Dispose() 31 | { 32 | this.currentEnumerator.Dispose(); 33 | } 34 | 35 | object IEnumerator.Current 36 | { 37 | get { return this.Current; } 38 | } 39 | 40 | public bool MoveNext() 41 | { 42 | for (;;) 43 | { 44 | if (this.currentEnumerator.MoveNext()) 45 | { 46 | return true; 47 | } 48 | if (this.currentEnumerator == this.e1) 49 | { 50 | this.currentEnumerator = this.e2; 51 | } 52 | else 53 | { 54 | return false; 55 | } 56 | } 57 | } 58 | 59 | public void Reset() 60 | { 61 | this.currentEnumerator.Reset(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Groups/IChannelGroup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Groups 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Threading.Tasks; 9 | 10 | public interface IChannelGroup : ICollection, IComparable 11 | { 12 | /// 13 | /// Returns the name of this group. A group name is purely for helping 14 | /// you to distinguish one group from others. 15 | /// 16 | string Name { get; } 17 | 18 | IChannel Find(IChannelId id); 19 | 20 | Task WriteAsync(object message); 21 | 22 | Task WriteAsync(object message, IChannelMatcher matcher); 23 | 24 | IChannelGroup Flush(); 25 | 26 | IChannelGroup Flush(IChannelMatcher matcher); 27 | 28 | Task WriteAndFlushAsync(object message); 29 | 30 | Task WriteAndFlushAsync(object message, IChannelMatcher matcher); 31 | 32 | Task DisconnectAsync(); 33 | 34 | Task DisconnectAsync(IChannelMatcher matcher); 35 | 36 | Task CloseAsync(); 37 | 38 | Task CloseAsync(IChannelMatcher matcher); 39 | 40 | Task DeregisterAsync(); 41 | 42 | Task DeregisterAsync(IChannelMatcher matcher); 43 | 44 | Task NewCloseFuture(); 45 | 46 | Task NewCloseFuture(IChannelMatcher matcher); 47 | } 48 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Groups/IChannelGroupTaskCompletionSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Groups 5 | { 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | 9 | public interface IChannelGroupTaskCompletionSource : IEnumerator 10 | { 11 | IChannelGroup Group { get; } 12 | 13 | ChannelGroupException Cause { get; } 14 | 15 | Task Find(IChannel channel); 16 | 17 | bool IsPartialSucess(); 18 | 19 | bool IsSucess(); 20 | 21 | bool IsPartialFailure(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Groups/IChannelMatcher.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Groups 5 | { 6 | public interface IChannelMatcher 7 | { 8 | bool Matches(IChannel channel); 9 | } 10 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IChannel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Net; 7 | using System.Threading.Tasks; 8 | using DotNetty.Buffers; 9 | 10 | public interface IChannel 11 | { 12 | IChannelId Id { get; } 13 | 14 | IByteBufferAllocator Allocator { get; } 15 | 16 | IEventLoop EventLoop { get; } 17 | 18 | IChannel Parent { get; } 19 | 20 | bool DisconnectSupported { get; } 21 | 22 | bool Open { get; } 23 | 24 | bool Active { get; } 25 | 26 | bool Registered { get; } 27 | 28 | EndPoint LocalAddress { get; } 29 | 30 | EndPoint RemoteAddress { get; } 31 | 32 | bool IsWritable { get; } 33 | 34 | IChannelUnsafe Unsafe { get; } 35 | 36 | IChannelPipeline Pipeline { get; } 37 | 38 | IChannelConfiguration Configuration { get; } 39 | 40 | Task CloseCompletion { get; } 41 | 42 | Task DeregisterAsync(); 43 | 44 | Task BindAsync(EndPoint localAddress); 45 | 46 | Task ConnectAsync(EndPoint remoteAddress); 47 | 48 | Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress); 49 | 50 | Task DisconnectAsync(); 51 | 52 | Task CloseAsync(); 53 | 54 | // todo: make these available through separate interface to hide them from public API on channel 55 | 56 | IChannel Read(); 57 | 58 | Task WriteAsync(object message); 59 | 60 | IChannel Flush(); 61 | 62 | Task WriteAndFlushAsync(object message); 63 | } 64 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IChannelConfiguration.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | using DotNetty.Buffers; 8 | 9 | public interface IChannelConfiguration 10 | { 11 | T GetOption(ChannelOption option); 12 | 13 | bool SetOption(ChannelOption option, object value); 14 | 15 | bool SetOption(ChannelOption option, T value); 16 | 17 | //void SetOptions(Dictionary, object> option); 18 | 19 | TimeSpan ConnectTimeout { get; set; } 20 | 21 | int MaxMessagesPerRead { get; set; } 22 | 23 | int WriteSpinCount { get; set; } 24 | 25 | IByteBufferAllocator Allocator { get; set; } 26 | 27 | IRecvByteBufAllocator RecvByteBufAllocator { get; set; } 28 | 29 | bool AutoRead { get; set; } 30 | 31 | int WriteBufferHighWaterMark { get; set; } 32 | 33 | int WriteBufferLowWaterMark { get; set; } 34 | 35 | IMessageSizeEstimator MessageSizeEstimator { get; set; } 36 | } 37 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IChannelId.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | 8 | public interface IChannelId : IComparable 9 | { 10 | string AsShortText(); 11 | 12 | string AsLongText(); 13 | } 14 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IChannelUnsafe.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Net; 7 | using System.Threading.Tasks; 8 | 9 | public interface IChannelUnsafe 10 | { 11 | IRecvByteBufAllocatorHandle RecvBufAllocHandle { get; } 12 | 13 | Task RegisterAsync(IEventLoop eventLoop); 14 | 15 | Task DeregisterAsync(); 16 | 17 | Task BindAsync(EndPoint localAddress); 18 | 19 | Task ConnectAsync(EndPoint remoteAddress, EndPoint localAddress); 20 | 21 | Task DisconnectAsync(); 22 | 23 | Task CloseAsync(); 24 | 25 | void CloseForcibly(); 26 | 27 | void BeginRead(); 28 | 29 | Task WriteAsync(object message); 30 | 31 | void Flush(); 32 | 33 | ChannelOutboundBuffer OutboundBuffer { get; } 34 | } 35 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IEventLoop.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Threading.Tasks; 7 | using DotNetty.Common.Concurrency; 8 | 9 | public interface IEventLoop : IEventExecutor 10 | { 11 | IChannelHandlerInvoker Invoker { get; } 12 | 13 | Task RegisterAsync(IChannel channel); 14 | 15 | IEventLoop Unwrap(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IEventLoopGroup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.Threading.Tasks; 7 | 8 | public interface IEventLoopGroup 9 | { 10 | Task TerminationCompletion { get; } 11 | 12 | IEventLoop GetNext(); 13 | 14 | Task ShutdownGracefullyAsync(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IMessageSizeEstimator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | public interface IMessageSizeEstimator 7 | { 8 | /// 9 | /// Creates a new handle. The handle provides the actual operations. 10 | /// 11 | IMessageSizeEstimatorHandle NewHandle(); 12 | } 13 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IMessageSizeEstimatorHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | public interface IMessageSizeEstimatorHandle 7 | { 8 | /// 9 | /// Calculate the size of the given message. 10 | /// 11 | /// @param msg The message for which the size should be calculated 12 | /// @return size The size in bytes. The returned size must be >= 0 13 | /// 14 | int Size(object msg); 15 | } 16 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IRecvByteBufAllocator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | /// 7 | /// Allocates a new receive buffer whose capacity is probably large enough to read all inbound data and small enough 8 | /// not to waste its space. 9 | /// 10 | public interface IRecvByteBufAllocator 11 | { 12 | /// 13 | /// Creates a new handle. The handle provides the actual operations and keeps the internal information which is 14 | /// required for predicting an optimal buffer capacity. 15 | /// 16 | IRecvByteBufAllocatorHandle NewHandle(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IRecvByteBufAllocatorHandle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using DotNetty.Buffers; 7 | 8 | public interface IRecvByteBufAllocatorHandle 9 | { 10 | /// 11 | /// Creates a new receive buffer whose capacity is probably large enough to read all inbound data and small 12 | /// enough not to waste its space. 13 | /// 14 | IByteBuffer Allocate(IByteBufferAllocator alloc); 15 | 16 | /// 17 | /// Similar to {@link #allocate(ByteBufAllocator)} except that it does not allocate anything but just tells the 18 | /// capacity. 19 | /// 20 | int Guess(); 21 | 22 | /// 23 | /// Records the the actual number of read bytes in the previous read operation so that the allocator allocates 24 | /// the buffer with potentially more correct capacity. 25 | /// 26 | /// @param actualReadBytes the actual number of read bytes in the previous read operation 27 | /// 28 | void Record(int actualReadBytes); 29 | } 30 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/IServerChannel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | /// 7 | /// A {@link Channel} that accepts an incoming connection attempt and creates 8 | /// its child {@link Channel}s by accepting them. {@link ServerSocketChannel} is 9 | /// a good example. 10 | /// 11 | public interface IServerChannel : IChannel 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/NotYetConnectedException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System.IO; 7 | 8 | public class NotYetConnectedException : IOException 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/RejectedExecutionException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | 8 | public class RejectedExecutionException : Exception 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/SingleThreadEventLoop.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | using System.Threading.Tasks; 8 | using DotNetty.Common.Concurrency; 9 | 10 | public class SingleThreadEventLoop : SingleThreadEventExecutor, IEventLoop 11 | { 12 | static readonly TimeSpan DefaultBreakoutInterval = TimeSpan.FromMilliseconds(100); 13 | 14 | public SingleThreadEventLoop() 15 | : this(null, DefaultBreakoutInterval) 16 | { 17 | } 18 | 19 | public SingleThreadEventLoop(string threadName) 20 | : this(threadName, DefaultBreakoutInterval) 21 | { 22 | } 23 | 24 | public SingleThreadEventLoop(string threadName, TimeSpan breakoutInterval) 25 | : base(threadName, breakoutInterval) 26 | { 27 | this.Invoker = new DefaultChannelHandlerInvoker(this); 28 | } 29 | 30 | public IChannelHandlerInvoker Invoker { get; private set; } 31 | 32 | public Task RegisterAsync(IChannel channel) 33 | { 34 | return channel.Unsafe.RegisterAsync(this); 35 | } 36 | 37 | IEventLoop IEventLoop.Unwrap() 38 | { 39 | return this; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/SkipAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | 8 | [AttributeUsage(AttributeTargets.Method)] 9 | public class SkipAttribute : Attribute 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Sockets/ChannelInputShutdownEvent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Sockets 5 | { 6 | /// 7 | /// Special event which will be fired and passed to the 8 | /// {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} methods once the input of 9 | /// a {@link SocketChannel} was shutdown and the {@link SocketChannelConfig#isAllowHalfClosure()} method returns 10 | /// {@code true}. 11 | /// 12 | public sealed class ChannelInputShutdownEvent 13 | { 14 | /// 15 | /// Instance to use 16 | /// 17 | public static readonly ChannelInputShutdownEvent Instance = new ChannelInputShutdownEvent(); 18 | 19 | ChannelInputShutdownEvent() 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Sockets/IServerSocketChannel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Sockets 5 | { 6 | /// 7 | /// A TCP/IP {@link ServerChannel} which accepts incoming TCP/IP connections. 8 | /// 9 | public interface IServerSocketChannel : IServerChannel 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Sockets/IServerSocketChannelConfiguration.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Sockets 5 | { 6 | public interface IServerSocketChannelConfiguration : IChannelConfiguration 7 | { 8 | int Backlog { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Sockets/ISocketChannel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Sockets 5 | { 6 | public interface ISocketChannel : IChannel 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Sockets/ISocketChannelConfiguration.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Sockets 5 | { 6 | public interface ISocketChannelConfiguration : IChannelConfiguration 7 | { 8 | bool AllowHalfClosure { get; set; } 9 | 10 | int ReceiveBufferSize { get; set; } 11 | 12 | int SendBufferSize { get; set; } 13 | 14 | int Linger { get; set; } 15 | 16 | bool KeepAlive { get; set; } 17 | 18 | bool ReuseAddress { get; set; } 19 | 20 | bool TcpNoDelay { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Sockets/SocketChannelAsyncOperation.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels.Sockets 5 | { 6 | using System.Diagnostics.Contracts; 7 | using System.Net.Sockets; 8 | using DotNetty.Common.Utilities; 9 | 10 | public class SocketChannelAsyncOperation : SocketAsyncEventArgs 11 | { 12 | public SocketChannelAsyncOperation(AbstractSocketChannel channel) 13 | : this(channel, true) 14 | { 15 | } 16 | 17 | public SocketChannelAsyncOperation(AbstractSocketChannel channel, bool setEmptyBuffer) 18 | { 19 | Contract.Requires(channel != null); 20 | 21 | this.Channel = channel; 22 | this.Completed += AbstractSocketChannel.IoCompletedCallback; 23 | if (setEmptyBuffer) 24 | { 25 | this.SetBuffer(ByteArrayExtensions.Empty, 0, 0); 26 | } 27 | } 28 | 29 | public void Validate() 30 | { 31 | SocketError socketError = this.SocketError; 32 | if (socketError != SocketError.Success) 33 | { 34 | throw new SocketException((int)socketError); 35 | } 36 | } 37 | 38 | public AbstractSocketChannel Channel { get; private set; } 39 | } 40 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/Channels/Util.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Channels 5 | { 6 | using System; 7 | using DotNetty.Common.Concurrency; 8 | using DotNetty.Common.Internal.Logging; 9 | 10 | static class Util 11 | { 12 | /// 13 | /// Marks the specified {@code promise} as success. If the {@code promise} is done already, log a message. 14 | /// 15 | public static void SafeSetSuccess(TaskCompletionSource promise, IInternalLogger logger) 16 | { 17 | if (promise != TaskCompletionSource.Void && !promise.TryComplete()) 18 | { 19 | logger.Warn(string.Format("Failed to mark a promise as success because it is done already: {0}", promise)); 20 | } 21 | } 22 | 23 | /// 24 | /// Marks the specified {@code promise} as failure. If the {@code promise} is done already, log a message. 25 | /// 26 | public static void SafeSetFailure(TaskCompletionSource promise, Exception cause, IInternalLogger logger) 27 | { 28 | if (promise != TaskCompletionSource.Void && !promise.TrySetException(cause)) 29 | { 30 | logger.Warn(string.Format("Failed to mark a promise as failure because it's done already: {0}", promise), cause); 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/DotNetty.Transport/DotNetty.Transport.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @project@ 5 | @project@@title@ 6 | @build.number@ 7 | @authors@ 8 | @authors@ 9 | UDP and TCP SocketChannel implementations for DotNetty. 10 | https://github.com/Azure/DotNetty/blob/master/LICENSE.txt 11 | https://github.com/Azure/DotNetty/ 12 | false 13 | @releaseNotes@ 14 | @copyright@ 15 | @tags@ 16 | @dependencies@ 17 | @references@ 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/DotNetty.Transport/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Resources; 6 | 7 | [assembly: NeutralResourcesLanguage("en-US")] 8 | [assembly: AssemblyMetadata("Serviceable", "True")] -------------------------------------------------------------------------------- /src/DotNetty.Transport/Properties/Friends.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | #if !NOTEST 7 | 8 | //[assembly: InternalsVisibleTo("DotNetty.Transport.Tests")] 9 | 10 | #endif -------------------------------------------------------------------------------- /src/SharedAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyCompanyAttribute("DotNetty")] 5 | [assembly: AssemblyCopyrightAttribute("Copyright © 2016")] 6 | [assembly: AssemblyKeyFileAttribute("")] 7 | [assembly: AssemblyDelaySignAttribute(false)] 8 | [assembly: AssemblyVersionAttribute("0.2.6")] 9 | [assembly: AssemblyFileVersionAttribute("0.2.6")] 10 | -------------------------------------------------------------------------------- /test/DotNetty.Buffers.Tests/AbstractByteBufferTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers.Tests 5 | { 6 | using System; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using DotNetty.Common.Utilities; 10 | using Xunit; 11 | 12 | public class AbstractByteBufferTests 13 | { 14 | [Fact] 15 | public async Task WriteBytesAsyncPartialWrite() 16 | { 17 | const int CopyLength = 200 * 1024; 18 | const int SourceLength = 300 * 1024; 19 | const int BufferCapacity = 400 * 1024; 20 | 21 | var bytes = new byte[SourceLength]; 22 | var random = new Random(Guid.NewGuid().GetHashCode()); 23 | random.NextBytes(bytes); 24 | 25 | IByteBuffer buffer = Unpooled.Buffer(BufferCapacity); 26 | int initialWriterIndex = buffer.WriterIndex; 27 | using (var stream = new PortionedMemoryStream(bytes, Enumerable.Repeat(1, int.MaxValue).Select(_ => random.Next(1, 10240)))) 28 | { 29 | await buffer.WriteBytesAsync(stream, CopyLength); 30 | } 31 | Assert.Equal(CopyLength, buffer.WriterIndex - initialWriterIndex); 32 | Assert.True(ByteBufferUtil.Equals(Unpooled.WrappedBuffer(bytes.Slice(0, CopyLength)), buffer)); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /test/DotNetty.Buffers.Tests/ByteBufferDerivationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers.Tests 5 | { 6 | using Xunit; 7 | 8 | public class ByteBufferDerivationTests 9 | { 10 | [Fact] 11 | public void TestSwap() 12 | { 13 | IByteBuffer buf = Unpooled.Buffer(8).SetIndex(1, 7); 14 | IByteBuffer swapped = buf.WithOrder(ByteOrder.LittleEndian); 15 | 16 | Assert.IsType(swapped); 17 | Assert.Null(swapped.Unwrap()); 18 | Assert.Same(buf, swapped.WithOrder(ByteOrder.BigEndian)); 19 | Assert.Same(swapped, swapped.WithOrder(ByteOrder.LittleEndian)); 20 | 21 | buf.SetIndex(2, 6); 22 | Assert.Equal(swapped.ReaderIndex, 2); 23 | Assert.Equal(swapped.WriterIndex, 6); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /test/DotNetty.Buffers.Tests/LeakDetectionTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers.Tests 5 | { 6 | using System; 7 | using System.Diagnostics.Tracing; 8 | using DotNetty.Common; 9 | using DotNetty.Common.Internal.Logging; 10 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging; 11 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Formatters; 12 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility; 13 | using Moq; 14 | using Xunit; 15 | 16 | public class LeakDetectionTest 17 | { 18 | readonly MockRepository mockRepo = new MockRepository(MockBehavior.Strict); 19 | 20 | [Fact] 21 | public void UnderReleaseBufferLeak() 22 | { 23 | var eventListener = new ObservableEventListener(); 24 | Mock> logListener = this.mockRepo.Create>(); 25 | var eventTextFormatter = new EventTextFormatter(); 26 | Func leakPredicate = y => y.TryFormatAsString(eventTextFormatter).Contains("LEAK"); 27 | logListener.Setup(x => x.OnNext(It.Is(y => leakPredicate(y)))).Verifiable(); 28 | logListener.Setup(x => x.OnNext(It.Is(y => !leakPredicate(y)))); 29 | eventListener.Subscribe(logListener.Object); 30 | eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose); 31 | 32 | var bufPool = new PooledByteBufferAllocator(100, 1000); 33 | IByteBuffer buffer = bufPool.Buffer(10); 34 | 35 | buffer = null; 36 | 37 | GC.Collect(); 38 | GC.WaitForPendingFinalizers(); 39 | 40 | this.mockRepo.Verify(); 41 | } 42 | 43 | [Fact] 44 | public void ResampleNoLeak() 45 | { 46 | ResourceLeakDetector.DetectionLevel preservedLevel = ResourceLeakDetector.Level; 47 | try 48 | { 49 | ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid; 50 | var bufPool = new PooledByteBufferAllocator(100, 1000); 51 | IByteBuffer buffer = bufPool.Buffer(10); 52 | buffer.Release(); 53 | buffer = bufPool.Buffer(10); 54 | buffer.Release(); 55 | } 56 | finally 57 | { 58 | ResourceLeakDetector.Level = preservedLevel; 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /test/DotNetty.Buffers.Tests/PooledBufferAllocatorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Buffers.Tests 5 | { 6 | using Xunit; 7 | 8 | public class PooledBufferAllocatorTests 9 | { 10 | [Theory] 11 | [InlineData(16 * 1024, 10, new[] {16 * 1024 - 100, 8 * 1024})] 12 | [InlineData(16 * 1024, 0, new[] { 16 * 1024 - 100, 8 * 1024 })] 13 | [InlineData(1024, 2 * 1024, new[] { 16 * 1024 - 100, 8 * 1024 })] 14 | [InlineData(1024, 0, new[] { 1024, 1 })] 15 | [InlineData(1024, 0, new[] { 1024, 0, 10 * 1024 })] 16 | public void PooledBufferGrowTest(int bufferSize, int startSize, int[] writeSizes) 17 | { 18 | var alloc = new PooledByteBufferAllocator(bufferSize, int.MaxValue); 19 | IByteBuffer buffer = alloc.Buffer(startSize); 20 | int wrote = 0; 21 | foreach (int size in writeSizes) 22 | { 23 | buffer.WriteBytes(Unpooled.WrappedBuffer(new byte[size])); 24 | wrote += size; 25 | } 26 | 27 | Assert.Equal(wrote, buffer.ReadableBytes); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /test/DotNetty.Buffers.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | 11 | [assembly: AssemblyTitle("DotNetty.Buffers.Tests")] 12 | [assembly: AssemblyDescription("")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("")] 15 | [assembly: AssemblyProduct("DotNetty.Buffers.Tests")] 16 | [assembly: AssemblyCopyright("Copyright © 2015")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | 28 | [assembly: Guid("69ccd62b-3774-42a3-a4be-89569bf822cf")] 29 | 30 | // Version information for an assembly consists of the following four values: 31 | // 32 | // Major Version 33 | // Minor Version 34 | // Build Number 35 | // Revision 36 | // 37 | // You can specify all the values or you can default the Build and Revision Numbers 38 | // by using the '*' as shown below: 39 | // [assembly: AssemblyVersion("1.0.*")] 40 | 41 | [assembly: AssemblyVersion("1.0.0.0")] 42 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /test/DotNetty.Buffers.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/DotNetty.Codecs.Mqtt.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotNetty.Codecs.Mqtt.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotNetty.Codecs.Mqtt.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4d4c9d88-34e3-41c3-955b-61da1ae07b7c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/DotNetty.Codecs.Mqtt.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/DotNetty.Codecs.Tests/Frame/LengthFieldBasedFrameDecoderTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Codecs.Tests.Frame 5 | { 6 | using System.Text; 7 | using DotNetty.Buffers; 8 | using DotNetty.Transport.Channels.Embedded; 9 | using Xunit; 10 | 11 | public class LengthFieldBasedFrameDecoderTests 12 | { 13 | [Fact] 14 | public void FailSlowTooLongFrameRecovery() 15 | { 16 | EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false)); 17 | for (int i = 0; i < 2; i++) 18 | { 19 | Assert.False(ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0, 0, 2 }))); 20 | Assert.Throws(() => 21 | { 22 | Assert.True(ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0 }))); 23 | Assert.True(false, typeof(DecoderException).Name + " must be raised."); 24 | }); 25 | ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0, 0, 1, (byte)'A' })); 26 | IByteBuffer buf = ch.ReadInbound(); 27 | Encoding iso = Encoding.GetEncoding("ISO-8859-1"); 28 | Assert.Equal("A", iso.GetString(buf.ToArray())); 29 | buf.Release(); 30 | } 31 | } 32 | 33 | [Fact] 34 | public void TestFailFastTooLongFrameRecovery() 35 | { 36 | EmbeddedChannel ch = new EmbeddedChannel( 37 | new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4)); 38 | 39 | for (int i = 0; i < 2; i++) 40 | { 41 | Assert.Throws(() => 42 | { 43 | Assert.True(ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0, 0, 2 }))); 44 | Assert.True(false, typeof(DecoderException).Name + " must be raised."); 45 | }); 46 | 47 | ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, (byte)'A' })); 48 | IByteBuffer buf = ch.ReadInbound(); 49 | Encoding iso = Encoding.GetEncoding("ISO-8859-1"); 50 | Assert.Equal("A", iso.GetString(buf.ToArray())); 51 | buf.Release(); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /test/DotNetty.Codecs.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotNetty.Codecs.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotNetty.Codecs.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("518abe50-e782-40f3-9f64-be9ae76d8326")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/DotNetty.Codecs.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/DotNetty.Common.Tests/Internal/Logging/InternalLoggerFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Tests.Internal.Logging 5 | { 6 | using System; 7 | using System.Reactive.Disposables; 8 | using DotNetty.Common.Internal.Logging; 9 | using Moq; 10 | using Xunit; 11 | 12 | public class InternalLoggerFactoryTest 13 | { 14 | // todo: CodeContracts on CI 15 | //[Fact] 16 | //public void ShouldNotAllowNullDefaultFactory() 17 | //{ 18 | // Assert.ThrowsAny(() => InternalLoggerFactory.DefaultFactory = null); 19 | //} 20 | 21 | [Fact] 22 | public void ShouldGetInstance() 23 | { 24 | IInternalLogger one = InternalLoggerFactory.GetInstance("helloWorld"); 25 | IInternalLogger two = InternalLoggerFactory.GetInstance(); 26 | 27 | Assert.NotNull(one); 28 | Assert.NotNull(two); 29 | Assert.NotSame(one, two); 30 | } 31 | 32 | [Fact] 33 | public void TestMockReturned() 34 | { 35 | Mock mock; 36 | using (SetupMockLogger(out mock)) 37 | { 38 | mock.SetupGet(x => x.TraceEnabled).Returns(true).Verifiable(); 39 | 40 | IInternalLogger logger = InternalLoggerFactory.GetInstance("mock"); 41 | 42 | Assert.Equal(logger, mock.Object); 43 | Assert.True(logger.TraceEnabled); 44 | mock.Verify(x => x.TraceEnabled, Times.Once); 45 | } 46 | } 47 | 48 | static IDisposable SetupMockLogger(out Mock loggerMock) 49 | { 50 | InternalLoggerFactory oldLoggerFactory = InternalLoggerFactory.DefaultFactory; 51 | var factoryMock = new Mock(MockBehavior.Strict); 52 | InternalLoggerFactory mockFactory = factoryMock.Object; 53 | loggerMock = new Mock(MockBehavior.Strict); 54 | 55 | factoryMock.Setup(x => x.NewInstance("mock")).Returns(loggerMock.Object); 56 | InternalLoggerFactory.DefaultFactory = mockFactory; 57 | return Disposable.Create(() => InternalLoggerFactory.DefaultFactory = oldLoggerFactory); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /test/DotNetty.Common.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Resources; 6 | 7 | [assembly: NeutralResourcesLanguage("en-US")] 8 | [assembly: AssemblyMetadata("Serviceable", "True")] -------------------------------------------------------------------------------- /test/DotNetty.Common.Tests/ResourceLeakDetectorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DotNetty.Common.Tests 8 | { 9 | using DotNetty.Common.Utilities; 10 | using Moq; 11 | using Xunit; 12 | 13 | public class ResourceLeakDetectorTest 14 | { 15 | [Fact] 16 | public void TestLeak() 17 | { 18 | var refCnt = new Mock(MockBehavior.Strict); 19 | refCnt.Setup(x => x.Touch()).Verifiable(); 20 | ReferenceCountUtil. 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/DotNetty.Common.Tests/Utilities/PriorityQueueTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Common.Tests.Utilities 5 | { 6 | using System; 7 | using DotNetty.Common.Utilities; 8 | using Xunit; 9 | 10 | public class PriorityQueueTest 11 | { 12 | [Theory] 13 | [InlineData(0, -1)] 14 | [InlineData(1, 0)] 15 | [InlineData(1, -1)] 16 | [InlineData(2, 0)] 17 | [InlineData(2, 1)] 18 | [InlineData(3, 0)] 19 | [InlineData(3, 1)] 20 | [InlineData(3, 2)] 21 | [InlineData(7, 5)] 22 | public void PriorityQueueRemoveTest(int length, int removeIndex) 23 | { 24 | var queue = new PriorityQueue>(); 25 | for (int i = length - 1; i >= 0; i--) 26 | { 27 | queue.Enqueue(Tuple.Create(i)); 28 | } 29 | 30 | if (removeIndex == -1) 31 | { 32 | queue.Remove(Tuple.Create(length)); 33 | Assert.Equal(length, queue.Count); 34 | } 35 | else 36 | { 37 | queue.Remove(Tuple.Create(removeIndex)); 38 | Assert.Equal(length - 1, queue.Count); 39 | } 40 | } 41 | 42 | [Theory] 43 | [InlineData(new[] { 1, 2, 3, 4 }, new[] { 1, 2, 3, 4 })] 44 | [InlineData(new[] { 4, 3, 2, 1 }, new[] { 1, 2, 3, 4 })] 45 | [InlineData(new[] { 3, 2, 1 }, new[] { 1, 2, 3 })] 46 | [InlineData(new[] { 1, 3, 2 }, new[] { 1, 2, 3 })] 47 | [InlineData(new[] { 1, 2 }, new[] { 1, 2 })] 48 | [InlineData(new[] { 2, 1 }, new[] { 1, 2 })] 49 | public void PriorityQueueOrderTest(int[] input, int[] expectedOutput) 50 | { 51 | var queue = new PriorityQueue>(); 52 | foreach (int value in input) 53 | { 54 | queue.Enqueue(Tuple.Create(value)); 55 | } 56 | 57 | for (int index = 0; index < expectedOutput.Length; index++) 58 | { 59 | Tuple item = queue.Dequeue(); 60 | Assert.Equal(expectedOutput[index], item.Item1); 61 | } 62 | Assert.Equal(0, queue.Count); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /test/DotNetty.Common.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/DotNetty.Microbench/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotNetty.Microbench")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotNetty.Microbench")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d0d45dcd-ef82-43fa-8b95-d85d50378806")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/DotNetty.Microbench/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /test/DotNetty.Tests.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotNetty.Tests.Common")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotNetty.Tests.Common")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("edf30087-8b53-4432-84b8-d21bd9f49e95")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/DotNetty.Tests.Common/TestBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Tests.Common 5 | { 6 | using System; 7 | using System.Diagnostics.Tracing; 8 | using DotNetty.Common.Internal.Logging; 9 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging; 10 | using Xunit.Abstractions; 11 | 12 | public abstract class TestBase : IDisposable 13 | { 14 | protected readonly ITestOutputHelper Output; 15 | readonly ObservableEventListener eventListener; 16 | 17 | protected TestBase(ITestOutputHelper output) 18 | { 19 | this.Output = output; 20 | this.eventListener = new ObservableEventListener(); 21 | this.eventListener.LogToTestOutput(output); 22 | this.eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose); 23 | } 24 | 25 | public void Dispose() 26 | { 27 | this.eventListener.Dispose(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /test/DotNetty.Tests.Common/TestScenarioStep.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Tests.End2End 5 | { 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | public class TestScenarioStep 10 | { 11 | TestScenarioStep() 12 | { 13 | } 14 | 15 | public IEnumerable SendMessages { get; private set; } 16 | 17 | public static TestScenarioStep Messages(params object[] messages) 18 | { 19 | return new TestScenarioStep 20 | { 21 | SendMessages = messages 22 | }; 23 | } 24 | 25 | public static TestScenarioStep Message(object message) 26 | { 27 | return new TestScenarioStep 28 | { 29 | SendMessages = Enumerable.Repeat(message, 1) 30 | }; 31 | } 32 | 33 | public static TestScenarioStep MoreFeedbackExpected() 34 | { 35 | return new TestScenarioStep 36 | { 37 | SendMessages = Enumerable.Empty() 38 | }; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/DotNetty.Tests.Common/XUnitOutputSink.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Tests.Common 5 | { 6 | using System; 7 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging; 8 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Formatters; 9 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility; 10 | using Xunit.Abstractions; 11 | 12 | public class XUnitOutputSink : IObserver 13 | { 14 | static readonly object LockObject = new object(); 15 | readonly ITestOutputHelper output; 16 | readonly IEventTextFormatter formatter; 17 | 18 | public XUnitOutputSink(ITestOutputHelper output, IEventTextFormatter formatter) 19 | { 20 | this.output = output; 21 | this.formatter = formatter; 22 | } 23 | 24 | public void OnCompleted() 25 | { 26 | } 27 | 28 | public void OnError(Exception error) 29 | { 30 | } 31 | 32 | public void OnNext(EventEntry value) 33 | { 34 | string formattedValue = value.TryFormatAsString(this.formatter); 35 | if (formattedValue == null) 36 | { 37 | return; 38 | } 39 | this.OnNext(formattedValue); 40 | } 41 | 42 | void OnNext(string entry) 43 | { 44 | lock (LockObject) 45 | { 46 | try 47 | { 48 | this.output.WriteLine(entry); 49 | } 50 | catch (Exception ex) 51 | { 52 | SemanticLoggingEventSource.Log.CustomSinkUnhandledFault(ex.ToString()); 53 | } 54 | } 55 | } 56 | } 57 | 58 | public static class XUnitOutputLog 59 | { 60 | public static SinkSubscription LogToTestOutput(this IObservable eventStream, ITestOutputHelper output, IEventTextFormatter formatter = null) 61 | { 62 | formatter = formatter ?? new EventTextFormatter(); 63 | var sink = new XUnitOutputSink(output, formatter); 64 | return new SinkSubscription(eventStream.Subscribe(sink), sink); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /test/DotNetty.Tests.Common/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/DotNetty.Tests.End2End/DiagnosticsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Tests.End2End 5 | { 6 | using DotNetty.Common.Internal.Logging; 7 | using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility; 8 | using Xunit; 9 | 10 | public class DiagnosticsTests 11 | { 12 | [Fact] 13 | public void VerifyEventSources() 14 | { 15 | EventSourceAnalyzer.InspectAll(DefaultEventSource.Log); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /test/DotNetty.Tests.End2End/EchoChannelHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Tests.End2End 5 | { 6 | using System; 7 | using DotNetty.Transport.Channels; 8 | 9 | class EchoChannelHandler : ChannelHandlerAdapter 10 | { 11 | public override void ChannelRead(IChannelHandlerContext context, object message) 12 | { 13 | context.Channel.WriteAsync(message); 14 | } 15 | 16 | public override void ChannelReadComplete(IChannelHandlerContext context) 17 | { 18 | context.Channel.Flush(); 19 | } 20 | 21 | public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) 22 | { 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/DotNetty.Tests.End2End/ExceptionCatchHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Tests.End2End 5 | { 6 | using System; 7 | using System.Diagnostics.Contracts; 8 | using DotNetty.Transport.Channels; 9 | 10 | class ExceptionCatchHandler : ChannelHandlerAdapter 11 | { 12 | readonly Action exceptionCaughtAction; 13 | 14 | public ExceptionCatchHandler(Action exceptionCaughtAction) 15 | { 16 | Contract.Requires(exceptionCaughtAction != null); 17 | this.exceptionCaughtAction = exceptionCaughtAction; 18 | } 19 | 20 | public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) 21 | { 22 | this.exceptionCaughtAction(exception); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/DotNetty.Tests.End2End/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | 11 | [assembly: AssemblyTitle("DotNetty.Tests.End2End")] 12 | [assembly: AssemblyDescription("")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("")] 15 | [assembly: AssemblyProduct("DotNetty.Tests.End2End")] 16 | [assembly: AssemblyCopyright("Copyright © 2015")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | 28 | [assembly: Guid("f35a59ba-67b8-43e5-a4c3-b2e6e9510fdd")] 29 | 30 | // Version information for an assembly consists of the following four values: 31 | // 32 | // Major Version 33 | // Minor Version 34 | // Build Number 35 | // Revision 36 | // 37 | // You can specify all the values or you can default the Build and Revision Numbers 38 | // by using the '*' as shown below: 39 | // [assembly: AssemblyVersion("1.0.*")] 40 | 41 | [assembly: AssemblyVersion("1.0.0.0")] 42 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /test/DotNetty.Tests.End2End/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/DotNetty.Transport.Tests/Channel/DefaulChannelIdTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace DotNetty.Transport.Tests.Channel 5 | { 6 | using System.Text.RegularExpressions; 7 | using DotNetty.Transport.Channels; 8 | using Xunit; 9 | 10 | public class DefaulChannelIdTest 11 | { 12 | [Fact] 13 | public void TestShortText() 14 | { 15 | string text = DefaultChannelId.NewInstance().AsShortText(); 16 | Assert.True(Regex.IsMatch(text, @"^[0-9a-f]{8}$")); 17 | } 18 | 19 | [Fact] 20 | public void TestLongText() 21 | { 22 | string text = DefaultChannelId.NewInstance().AsLongText(); 23 | Assert.True(Regex.IsMatch(text, @"^[0-9a-f]{16}-[0-9a-f]{8}-[0-9a-f]{8}-[0-9a-f]{16}-[0-9a-f]{8}$")); 24 | } 25 | 26 | [Fact] 27 | public void TestIdempotentMachineId() 28 | { 29 | string a = DefaultChannelId.NewInstance().AsLongText().Substring(0, 8); 30 | string b = DefaultChannelId.NewInstance().AsLongText().Substring(0, 8); 31 | Assert.Equal(a, b); 32 | } 33 | 34 | [Fact] 35 | public void TestIdempotentProcessId() 36 | { 37 | string a = DefaultChannelId.NewInstance().AsLongText().Substring(9, 4); 38 | string b = DefaultChannelId.NewInstance().AsLongText().Substring(9, 4); 39 | Assert.Equal(a, b); 40 | } 41 | 42 | // TODO: port TestSerialization https://github.com/netty/netty/blob/master/transport/src/test/java/io/netty/channel/DefaultChannelIdTest.java 43 | // requires ByteBufOutputStream and InputStream 44 | } 45 | } -------------------------------------------------------------------------------- /test/DotNetty.Transport.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotNetty.Transport.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotNetty.Transport.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1bc30cea-312e-41ed-a338-75fbc01c8c91")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/DotNetty.Transport.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tools/AddCopyrightHeaderToSourceFiles.ps1: -------------------------------------------------------------------------------- 1 | $lineBreak = "`r`n" 2 | $noticeTemplate = "// Copyright (c) Microsoft. All rights reserved.$lineBreak// Licensed under the MIT license. See LICENSE file in the project root for full license information.$lineBreak$lineBreak" 3 | $tokenToReplace = [regex]::Escape("[FileName]") 4 | 5 | Function CreateFileSpecificNotice($sourcePath){ 6 | $fileName = Split-Path $sourcePath -Leaf 7 | $fileSpecificNotice = $noticeTemplate -replace $tokenToReplace, $fileName 8 | return $fileSpecificNotice 9 | } 10 | 11 | Function SourceFileContainsNotice($sourcePath){ 12 | $copyrightSnippet = [regex]::Escape("// Copyright (c) Microsoft") 13 | 14 | $fileSpecificNotice = CreateFileSpecificNotice($sourcePath) 15 | $arrMatchResults = Get-Content $sourcePath | Select-String $copyrightSnippet 16 | 17 | if ($arrMatchResults -ne $null -and $arrMatchResults.count -gt 0){ 18 | return $true 19 | } 20 | else{ 21 | return $false 22 | } 23 | } 24 | 25 | Function AddHeaderToSourceFile($sourcePath) { 26 | # "Source path is: $sourcePath" 27 | 28 | $containsNotice = SourceFileContainsNotice($sourcePath) 29 | # "Contains notice: $containsNotice" 30 | 31 | if ($containsNotice){ 32 | #"Source file already contains notice -- not adding" 33 | } 34 | else { 35 | #"Source file does not contain notice -- adding" 36 | $noticeToInsert = CreateFileSpecificNotice($sourcePath) 37 | 38 | $fileLines = (Get-Content $sourcePath) -join $lineBreak 39 | 40 | $content = $noticeToInsert + $fileLines + $lineBreak 41 | 42 | $content | Out-File $sourcePath -Encoding utf8 43 | 44 | } 45 | } 46 | 47 | $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition 48 | $parent = (get-item $scriptPath).Parent.FullName 49 | $startingPath = "$parent\src" 50 | Get-ChildItem $startingPath\*.cs -Recurse | Select FullName | Foreach-Object { AddHeaderToSourceFile($_.FullName)} 51 | Get-ChildItem $startingPath\*.fs -Recurse | Select FullName | Foreach-Object { AddHeaderToSourceFile($_.FullName)} 52 | --------------------------------------------------------------------------------