Skip to content

Commit

Permalink
Some socket option should be set to the accepted Socket, not the list…
Browse files Browse the repository at this point in the history
…ening Socket.
  • Loading branch information
xljiulang committed Dec 9, 2024
1 parent 8566fd5 commit 8f3df76
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions Source/MQTTnet.Server/Internal/Adapter/MqttTcpServerListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,6 @@ public bool Start(bool treatErrorsAsWarning, CancellationToken cancellationToken
_socket.ReuseAddress = true;
}

if (_options.NoDelay)
{
_socket.NoDelay = true;
}

if (_options.LingerState != null)
{
_socket.LingerState = _options.LingerState;
}

if (_options.KeepAlive.HasValue)
{
_socket.KeepAlive = _options.KeepAlive.Value;
}

if (_options.TcpKeepAliveInterval.HasValue)
{
_socket.TcpKeepAliveInterval = _options.TcpKeepAliveInterval.Value;
}

if (_options.TcpKeepAliveRetryCount.HasValue)
{
_socket.TcpKeepAliveInterval = _options.TcpKeepAliveRetryCount.Value;
}

if (_options.TcpKeepAliveTime.HasValue)
{
_socket.TcpKeepAliveTime = _options.TcpKeepAliveTime.Value;
}

_socket.Bind(_localEndPoint);

// Get the local endpoint back from the socket. The port may have changed.
Expand Down Expand Up @@ -176,6 +146,32 @@ async Task TryHandleClientConnectionAsync(CrossPlatformSocket clientSocket)
_logger.Verbose("TCP client '{0}' accepted (Local endpoint={1})", remoteEndPoint, _localEndPoint);

clientSocket.NoDelay = _options.NoDelay;

if (_options.LingerState != null)
{
clientSocket.LingerState = _options.LingerState;
}

if (_options.KeepAlive.HasValue)
{
clientSocket.KeepAlive = _options.KeepAlive.Value;
}

if (_options.TcpKeepAliveInterval.HasValue)
{
clientSocket.TcpKeepAliveInterval = _options.TcpKeepAliveInterval.Value;
}

if (_options.TcpKeepAliveRetryCount.HasValue)
{
clientSocket.TcpKeepAliveInterval = _options.TcpKeepAliveRetryCount.Value;
}

if (_options.TcpKeepAliveTime.HasValue)
{
clientSocket.TcpKeepAliveTime = _options.TcpKeepAliveTime.Value;
}

stream = clientSocket.GetStream();
var clientCertificate = _tlsOptions?.CertificateProvider?.GetCertificate();

Expand Down

0 comments on commit 8f3df76

Please sign in to comment.