From 4eb2b77138cf9308c3b1da98a741f663de71da03 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 11 Jul 2019 21:11:11 +0200 Subject: [PATCH] Fix wrong NoDelay usage in server implementation. --- Build/MQTTnet.nuspec | 1 + Source/MQTTnet/Implementations/MqttTcpServerListener.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index c93416e..2ffae0a 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -14,6 +14,7 @@ * [Server] Added items dictionary to client session in order to share data across interceptors as along as the session exists. * [Server] Exposed CONNECT packet properties in Application Message and Subscription interceptor. * [Server] Fixed: Sending Large packets with AspnetCore based connection throws System.ArgumentException. +* [Server] Fixed wrong usage of socket option _NoDelay_. * [MQTTnet.Server] Added REST API for publishing basic messages. Copyright Christian Kratky 2016-2019 diff --git a/Source/MQTTnet/Implementations/MqttTcpServerListener.cs b/Source/MQTTnet/Implementations/MqttTcpServerListener.cs index 62eea00..84f6482 100644 --- a/Source/MQTTnet/Implementations/MqttTcpServerListener.cs +++ b/Source/MQTTnet/Implementations/MqttTcpServerListener.cs @@ -61,6 +61,8 @@ namespace MQTTnet.Implementations _socket = new Socket(_addressFamily, SocketType.Stream, ProtocolType.Tcp); + // Usage of socket options is described here: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.setsocketoption?view=netcore-2.2 + if (_options.ReuseAddress) { _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); @@ -68,7 +70,7 @@ namespace MQTTnet.Implementations if (_options.NoDelay) { - _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true); + _socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); } _socket.Bind(_localEndPoint);