mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 02:53:06 +08:00
propper buffering in place
This commit is contained in:
@@ -418,15 +418,21 @@ namespace MQTTnet.Core.Tests
|
||||
return _stream.WriteAsync(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public Task ReadAsync(byte[] buffer)
|
||||
public async Task<ArraySegment<byte>> ReadAsync(int length, byte[] buffer)
|
||||
{
|
||||
return _stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
await _stream.ReadAsync(buffer, 0, length);
|
||||
return new ArraySegment<byte>(buffer, 0, length);
|
||||
}
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
return _stream.ToArray();
|
||||
}
|
||||
|
||||
public int Peek()
|
||||
{
|
||||
return (int)_stream.Length - (int)_stream.Position;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SerializeAndCompare(MqttBasePacket packet, string expectedBase64Value, MqttProtocolVersion protocolVersion = MqttProtocolVersion.V311)
|
||||
|
||||
@@ -29,7 +29,8 @@ namespace MQTTnet.TestApp.NetFramework
|
||||
{
|
||||
Server = "localhost",
|
||||
ClientId = "XYZ",
|
||||
CleanSession = true
|
||||
CleanSession = true,
|
||||
DefaultCommunicationTimeout = TimeSpan.FromMinutes(10)
|
||||
};
|
||||
|
||||
var client = new MqttClientFactory().CreateMqttClient(options);
|
||||
@@ -128,7 +129,8 @@ namespace MQTTnet.TestApp.NetFramework
|
||||
}
|
||||
|
||||
return MqttConnectReturnCode.ConnectionAccepted;
|
||||
}
|
||||
},
|
||||
DefaultCommunicationTimeout = TimeSpan.FromMinutes(10)
|
||||
};
|
||||
|
||||
var mqttServer = new MqttServerFactory().CreateMqttServer(options);
|
||||
|
||||
@@ -20,18 +20,18 @@ namespace MQTTnet.TestApp.NetFramework
|
||||
Console.WriteLine("1 = Start client");
|
||||
Console.WriteLine("2 = Start server");
|
||||
Console.WriteLine("3 = Start performance test");
|
||||
var pressedKey = Console.ReadKey(true);
|
||||
if (pressedKey.Key == ConsoleKey.D1)
|
||||
{
|
||||
Task.Run(() => RunClientAsync(args));
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
}
|
||||
else if (pressedKey.Key == ConsoleKey.D2)
|
||||
{
|
||||
Task.Run(() => RunServerAsync(args));
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
}
|
||||
else if (pressedKey.Key == ConsoleKey.D3)
|
||||
//var pressedKey = Console.ReadKey(true);
|
||||
//if (pressedKey.Key == ConsoleKey.D1)
|
||||
//{
|
||||
// Task.Run(() => RunClientAsync(args));
|
||||
// Thread.Sleep(Timeout.Infinite);
|
||||
//}
|
||||
//else if (pressedKey.Key == ConsoleKey.D2)
|
||||
//{
|
||||
// Task.Run(() => RunServerAsync(args));
|
||||
// Thread.Sleep(Timeout.Infinite);
|
||||
//}
|
||||
//else if (pressedKey.Key == ConsoleKey.D3)
|
||||
{
|
||||
Task.Run(() => PerformanceTest.RunAsync());
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
|
||||
Reference in New Issue
Block a user