Disable Nagle on sockets, send packets in one shot.

This commit is contained in:
Israel Lot
2018-04-16 12:30:56 -03:00
parent a5f33bc244
commit c915af8dad
6 changed files with 60 additions and 51 deletions
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using MQTTnet.Protocol;
@@ -55,14 +56,16 @@ namespace MQTTnet.Serializer
Write(value);
}
public static void WriteRemainingLength(int length, BinaryWriter target)
public static byte[] GetRemainingLength(int length)
{
if (length == 0)
{
target.Write((byte)0);
return;
return new byte[] { (byte)0 };
}
var bytes = new byte[4];
int arraySize = 0;
// Alorithm taken from http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html.
var x = length;
do
@@ -74,8 +77,12 @@ namespace MQTTnet.Serializer
encodedByte = encodedByte | 128;
}
target.Write((byte)encodedByte);
bytes[arraySize] = (byte)encodedByte;
arraySize++;
} while (x > 0);
return bytes.Take(arraySize).ToArray();
}
}
}