Procházet zdrojové kódy

Remove the RAW stream approach

release/3.x.x
Christian Kratky před 7 roky
rodič
revize
0b002e8d11
13 změnil soubory, kde provedl 32 přidání a 34 odebrání
  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 Zobrazit soubor

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

<!-- .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>
</package>

+ 3
- 2
Build/build.ps1 Zobrazit soubor

@@ -8,10 +8,11 @@ $path = &$vswhere -latest -products * -requires Microsoft.Component.MSBuild -pro
if ($path) {
$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="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
New-Item -ItemType Directory -Force -Path .\NuGet


+ 3
- 3
Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs Zobrazit soubor

@@ -1,4 +1,4 @@
#if NET451 || NETSTANDARD1_3
#if NET452 || NETSTANDARD1_3
using System;
using System.Net;
using System.Net.Security;
@@ -98,7 +98,7 @@ namespace MQTTnet.Implementations
try
{
//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);
#else
var clientSocket = await _defaultEndpointSocket.AcceptAsync().ConfigureAwait(false);
@@ -122,7 +122,7 @@ namespace MQTTnet.Implementations
{
try
{
#if NET451
#if NET452
var clientSocket = await Task.Factory.FromAsync(_tlsEndpointSocket.BeginAccept, _tlsEndpointSocket.EndAccept, null).ConfigureAwait(false);
#else
var clientSocket = await _tlsEndpointSocket.AcceptAsync().ConfigureAwait(false);


+ 0
- 5
Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs Zobrazit soubor

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

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

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

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

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

SendStream?.Dispose();
SendStream = null;

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

private static Certificate LoadCertificate(MqttClientTcpOptions options)


+ 9
- 12
Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs Zobrazit soubor

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

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

//todo: this can be used with min dependency NetStandard1.6
#if NET45
#if NET452
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
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 ReceiveStream { get; private set; }
public Stream RawReceiveStream { get; private 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
#if NET451
#if NET452
await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, _options.Server, _options.GetPort(), null).ConfigureAwait(false);
#else
await _socket.ConnectAsync(_options.Server, _options.GetPort()).ConfigureAwait(false);
@@ -140,19 +138,18 @@ namespace MQTTnet.Implementations

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
//need two streams otherwise read and write have to be synchronized

//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
SendStream = RawReceiveStream;
ReceiveStream = RawReceiveStream;
SendStream = stream;
ReceiveStream = stream;
#endif
}



+ 2
- 2
Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj Zobrazit soubor

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

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


+ 1
- 1
MQTTnet.Core/Adapter/MqttChannelCommunicationAdapter.cs Zobrazit soubor

@@ -144,7 +144,7 @@ namespace MQTTnet.Core.Adapter
ReceivedMqttPacket receivedMqttPacket;
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
{


+ 0
- 1
MQTTnet.Core/Channel/IMqttCommunicationChannel.cs Zobrazit soubor

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

Task ConnectAsync();
Task DisconnectAsync();


+ 3
- 3
MQTTnet.Core/Client/MqttClient.cs Zobrazit soubor

@@ -60,8 +60,8 @@ namespace MQTTnet.Core.Client
await _adapter.ConnectAsync(_options.CommunicationTimeout).ConfigureAwait(false);
_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.");

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

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



+ 1
- 1
MQTTnet.sln Zobrazit soubor

@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
VisualStudioVersion = 15.0.27004.2006
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}"
EndProject


+ 1
- 1
Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj Zobrazit soubor

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

<ItemGroup>


+ 6
- 0
Tests/MQTTnet.TestApp.NetCore/Program.cs Zobrazit soubor

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

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

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


+ 1
- 1
Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj Zobrazit soubor

@@ -11,7 +11,7 @@
<AssemblyName>MQTTnet.TestApp.UniversalWindows</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<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>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>


Načítá se…
Zrušit
Uložit