Browse Source

Remove the RAW stream approach

release/3.x.x
Christian Kratky 7 years ago
parent
commit
0b002e8d11
13 changed files with 32 additions and 34 deletions
  1. +2
    -2
      Build/MQTTnet.nuspec
  2. +3
    -2
      Build/build.ps1
  3. +3
    -3
      Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs
  4. +0
    -5
      Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs
  5. +9
    -12
      Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs
  6. +2
    -2
      Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj
  7. +1
    -1
      MQTTnet.Core/Adapter/MqttChannelCommunicationAdapter.cs
  8. +0
    -1
      MQTTnet.Core/Channel/IMqttCommunicationChannel.cs
  9. +3
    -3
      MQTTnet.Core/Client/MqttClient.cs
  10. +1
    -1
      MQTTnet.sln
  11. +1
    -1
      Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj
  12. +6
    -0
      Tests/MQTTnet.TestApp.NetCore/Program.cs
  13. +1
    -1
      Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj

+ 2
- 2
Build/MQTTnet.nuspec View File

@@ -68,8 +68,8 @@
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\uap10.0\MQTTnet.*" target="lib\uap10.0\"/> <file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\uap10.0\MQTTnet.*" target="lib\uap10.0\"/>


<!-- .NET Framework --> <!-- .NET Framework -->
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\net451\MQTTnet.Core.*" target="lib\net451\"/>
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\net451\MQTTnet.*" target="lib\net451\"/>
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\net452\MQTTnet.Core.*" target="lib\net452\"/>
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\net452\MQTTnet.*" target="lib\net452\"/>
</files> </files>
</package> </package>

+ 3
- 2
Build/build.ps1 View File

@@ -8,10 +8,11 @@ $path = &$vswhere -latest -products * -requires Microsoft.Component.MSBuild -pro
if ($path) { if ($path) {
$msbuild = join-path $path 'MSBuild\15.0\Bin\MSBuild.exe' $msbuild = join-path $path 'MSBuild\15.0\Bin\MSBuild.exe'


&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net451" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net452" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard1.3" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard1.3" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="uap10.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="uap10.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard2.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m
&$msbuild ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard2.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m


Remove-Item .\NuGet -Force -Recurse Remove-Item .\NuGet -Force -Recurse
New-Item -ItemType Directory -Force -Path .\NuGet New-Item -ItemType Directory -Force -Path .\NuGet


+ 3
- 3
Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs View File

@@ -1,4 +1,4 @@
#if NET451 || NETSTANDARD1_3
#if NET452 || NETSTANDARD1_3
using System; using System;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
@@ -98,7 +98,7 @@ namespace MQTTnet.Implementations
try try
{ {
//todo: else branch can be used with min dependency NET46 //todo: else branch can be used with min dependency NET46
#if NET451
#if NET452
var clientSocket = await Task.Factory.FromAsync(_defaultEndpointSocket.BeginAccept, _defaultEndpointSocket.EndAccept, null).ConfigureAwait(false); var clientSocket = await Task.Factory.FromAsync(_defaultEndpointSocket.BeginAccept, _defaultEndpointSocket.EndAccept, null).ConfigureAwait(false);
#else #else
var clientSocket = await _defaultEndpointSocket.AcceptAsync().ConfigureAwait(false); var clientSocket = await _defaultEndpointSocket.AcceptAsync().ConfigureAwait(false);
@@ -122,7 +122,7 @@ namespace MQTTnet.Implementations
{ {
try try
{ {
#if NET451
#if NET452
var clientSocket = await Task.Factory.FromAsync(_tlsEndpointSocket.BeginAccept, _tlsEndpointSocket.EndAccept, null).ConfigureAwait(false); var clientSocket = await Task.Factory.FromAsync(_tlsEndpointSocket.BeginAccept, _tlsEndpointSocket.EndAccept, null).ConfigureAwait(false);
#else #else
var clientSocket = await _tlsEndpointSocket.AcceptAsync().ConfigureAwait(false); var clientSocket = await _tlsEndpointSocket.AcceptAsync().ConfigureAwait(false);


+ 0
- 5
Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs View File

@@ -32,7 +32,6 @@ namespace MQTTnet.Implementations


public Stream SendStream { get; private set; } public Stream SendStream { get; private set; }
public Stream ReceiveStream { get; private set; } public Stream ReceiveStream { get; private set; }
public Stream RawReceiveStream { get; private set; }


public static Func<MqttClientTcpOptions, IEnumerable<ChainValidationResult>> CustomIgnorableServerCertificateErrorsResolver { get; set; } public static Func<MqttClientTcpOptions, IEnumerable<ChainValidationResult>> CustomIgnorableServerCertificateErrorsResolver { get; set; }


@@ -70,9 +69,6 @@ namespace MQTTnet.Implementations


public void Dispose() public void Dispose()
{ {
RawReceiveStream?.Dispose();
RawReceiveStream = null;

SendStream?.Dispose(); SendStream?.Dispose();
SendStream = null; SendStream = null;


@@ -87,7 +83,6 @@ namespace MQTTnet.Implementations
{ {
SendStream = _socket.OutputStream.AsStreamForWrite(); SendStream = _socket.OutputStream.AsStreamForWrite();
ReceiveStream = _socket.InputStream.AsStreamForRead(); ReceiveStream = _socket.InputStream.AsStreamForRead();
RawReceiveStream = ReceiveStream;
} }


private static Certificate LoadCertificate(MqttClientTcpOptions options) private static Certificate LoadCertificate(MqttClientTcpOptions options)


+ 9
- 12
Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs View File

@@ -1,5 +1,4 @@
#if NET451 || NETSTANDARD1_3

#if NET452 || NETSTANDARD1_3
using System; using System;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
@@ -18,7 +17,7 @@ namespace MQTTnet.Implementations
private readonly MqttClientTcpOptions _options; private readonly MqttClientTcpOptions _options;


//todo: this can be used with min dependency NetStandard1.6 //todo: this can be used with min dependency NetStandard1.6
#if NET45
#if NET452
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
public static int BufferSize { get; set; } = 4096 * 20; // Can be changed for fine tuning by library user. public static int BufferSize { get; set; } = 4096 * 20; // Can be changed for fine tuning by library user.
@@ -49,7 +48,6 @@ namespace MQTTnet.Implementations


public Stream SendStream { get; private set; } public Stream SendStream { get; private set; }
public Stream ReceiveStream { get; private set; } public Stream ReceiveStream { get; private set; }
public Stream RawReceiveStream { get; private set; }


public static Func<X509Certificate, X509Chain, SslPolicyErrors, MqttClientTcpOptions, bool> CustomCertificateValidationCallback { get; set; } public static Func<X509Certificate, X509Chain, SslPolicyErrors, MqttClientTcpOptions, bool> CustomCertificateValidationCallback { get; set; }


@@ -61,7 +59,7 @@ namespace MQTTnet.Implementations
} }


//todo: else brach can be used with min dependency NET46 //todo: else brach can be used with min dependency NET46
#if NET451
#if NET452
await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, _options.Server, _options.GetPort(), null).ConfigureAwait(false); await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, _options.Server, _options.GetPort(), null).ConfigureAwait(false);
#else #else
await _socket.ConnectAsync(_options.Server, _options.GetPort()).ConfigureAwait(false); await _socket.ConnectAsync(_options.Server, _options.GetPort()).ConfigureAwait(false);
@@ -140,19 +138,18 @@ namespace MQTTnet.Implementations


private void CreateStreams(Socket socket, Stream sslStream) private void CreateStreams(Socket socket, Stream sslStream)
{ {
RawReceiveStream = sslStream ?? new NetworkStream(socket);

var stream = sslStream ?? new NetworkStream(socket);


//cannot use this as default buffering prevents from receiving the first connect message //cannot use this as default buffering prevents from receiving the first connect message
//need two streams otherwise read and write have to be synchronized //need two streams otherwise read and write have to be synchronized


//todo: if branch can be used with min dependency NetStandard1.6 //todo: if branch can be used with min dependency NetStandard1.6
#if NET45
SendStream = new BufferedStream(RawReceiveStream, BufferSize);
ReceiveStream = new BufferedStream(RawReceiveStream, BufferSize);
#if NET452
SendStream = new BufferedStream(stream, BufferSize);
ReceiveStream = new BufferedStream(stream, BufferSize);
#else #else
SendStream = RawReceiveStream;
ReceiveStream = RawReceiveStream;
SendStream = stream;
ReceiveStream = stream;
#endif #endif
} }




+ 2
- 2
Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">


<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard1.3;net451;uap10.0</TargetFrameworks>
<TargetFrameworks>netstandard1.3;net452;uap10.0</TargetFrameworks>
<AssemblyName>MQTTnet</AssemblyName> <AssemblyName>MQTTnet</AssemblyName>
<RootNamespace>MQTTnet</RootNamespace> <RootNamespace>MQTTnet</RootNamespace>
<AssemblyVersion>2.5.0.0</AssemblyVersion> <AssemblyVersion>2.5.0.0</AssemblyVersion>
@@ -18,7 +18,7 @@
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker> <NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier> <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion> <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>


+ 1
- 1
MQTTnet.Core/Adapter/MqttChannelCommunicationAdapter.cs View File

@@ -144,7 +144,7 @@ namespace MQTTnet.Core.Adapter
ReceivedMqttPacket receivedMqttPacket; ReceivedMqttPacket receivedMqttPacket;
if (timeout > TimeSpan.Zero) if (timeout > TimeSpan.Zero)
{ {
receivedMqttPacket = await ReceiveAsync(_channel.RawReceiveStream, cancellationToken).TimeoutAfter(timeout).ConfigureAwait(false);
receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).TimeoutAfter(timeout).ConfigureAwait(false);
} }
else else
{ {


+ 0
- 1
MQTTnet.Core/Channel/IMqttCommunicationChannel.cs View File

@@ -7,7 +7,6 @@ namespace MQTTnet.Core.Channel
{ {
Stream SendStream { get; } Stream SendStream { get; }
Stream ReceiveStream { get; } Stream ReceiveStream { get; }
Stream RawReceiveStream { get; }


Task ConnectAsync(); Task ConnectAsync();
Task DisconnectAsync(); Task DisconnectAsync();


+ 3
- 3
MQTTnet.Core/Client/MqttClient.cs View File

@@ -60,8 +60,8 @@ namespace MQTTnet.Core.Client
await _adapter.ConnectAsync(_options.CommunicationTimeout).ConfigureAwait(false); await _adapter.ConnectAsync(_options.CommunicationTimeout).ConfigureAwait(false);
_logger.LogTrace("Connection with server established."); _logger.LogTrace("Connection with server established.");


await SetupIncomingPacketProcessingAsync();
var connectResponse = await AuthenticateAsync(options.WillMessage);
await SetupIncomingPacketProcessingAsync().ConfigureAwait(false);
var connectResponse = await AuthenticateAsync(options.WillMessage).ConfigureAwait(false);


_logger.LogTrace("MQTT connection with server established."); _logger.LogTrace("MQTT connection with server established.");


@@ -218,7 +218,7 @@ namespace MQTTnet.Core.Client


while (!_isReceivingPackets && _cancellationTokenSource != null && !_cancellationTokenSource.IsCancellationRequested) while (!_isReceivingPackets && _cancellationTokenSource != null && !_cancellationTokenSource.IsCancellationRequested)
{ {
await Task.Delay(TimeSpan.FromMilliseconds(100));
await Task.Delay(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false);
} }
} }




+ 1
- 1
MQTTnet.sln View File

@@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
VisualStudioVersion = 15.0.27004.2006
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}"
EndProject EndProject


+ 1
- 1
Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<DebugType>Full</DebugType> <DebugType>Full</DebugType>
<TargetFrameworks>netcoreapp2.0;net451</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>
</PropertyGroup> </PropertyGroup>


<ItemGroup> <ItemGroup>


+ 6
- 0
Tests/MQTTnet.TestApp.NetCore/Program.cs View File

@@ -83,6 +83,12 @@ namespace MQTTnet.TestApp.NetCore


public Task SaveRetainedMessagesAsync(IList<MqttApplicationMessage> messages) public Task SaveRetainedMessagesAsync(IList<MqttApplicationMessage> messages)
{ {
var directory = Path.GetDirectoryName(Filename);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

File.WriteAllText(Filename, JsonConvert.SerializeObject(messages)); File.WriteAllText(Filename, JsonConvert.SerializeObject(messages));
return Task.FromResult(0); return Task.FromResult(0);
} }


+ 1
- 1
Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj View File

@@ -11,7 +11,7 @@
<AssemblyName>MQTTnet.TestApp.UniversalWindows</AssemblyName> <AssemblyName>MQTTnet.TestApp.UniversalWindows</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage> <DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.15063.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>


Loading…
Cancel
Save