Skip to content

Commit

Permalink
ensure the tcp defaults for max message size align to min buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
mregen committed May 8, 2024
1 parent 7fdc963 commit 29659e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Stack/Opc.Ua.Core/Stack/Tcp/TcpMessageType.cs
Expand Up @@ -301,5 +301,14 @@ public static class TcpMessageLimits
/// The certificates that have the key size larger than KeySizeExtraPadding need an extra padding byte in the transport message
/// </summary>
public const int KeySizeExtraPadding = 2048;

/// <summary>
/// Aligns the max message size to the nearest min buffer size.
/// </summary>
public static int AlignRoundMaxMessageSize(int value)
{
int alignmentMask = MinBufferSize - 1;
return (value + alignmentMask) & ~alignmentMask;
}
}
}
4 changes: 2 additions & 2 deletions Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs
Expand Up @@ -138,12 +138,12 @@ protected virtual void Dispose(bool disposing)
{
m_inactivityDetectPeriod = configuration.ChannelLifetime / 2;
m_quotas.MaxBufferSize = configuration.MaxBufferSize;
m_quotas.MaxMessageSize = configuration.MaxMessageSize;
m_quotas.MaxMessageSize = TcpMessageLimits.AlignRoundMaxMessageSize(configuration.MaxMessageSize);
m_quotas.ChannelLifetime = configuration.ChannelLifetime;
m_quotas.SecurityTokenLifetime = configuration.SecurityTokenLifetime;
messageContext.MaxArrayLength = configuration.MaxArrayLength;
messageContext.MaxByteStringLength = configuration.MaxByteStringLength;
messageContext.MaxMessageSize = configuration.MaxMessageSize;
messageContext.MaxMessageSize = TcpMessageLimits.AlignRoundMaxMessageSize(configuration.MaxMessageSize);
messageContext.MaxStringLength = configuration.MaxStringLength;
messageContext.MaxEncodingNestingLevels = configuration.MaxEncodingNestingLevels;
messageContext.MaxDecoderRecoveries = configuration.MaxDecoderRecoveries;
Expand Down
4 changes: 2 additions & 2 deletions Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryTransportChannel.cs
Expand Up @@ -423,13 +423,13 @@ private void SaveSettings(Uri url, TransportChannelSettings settings)
EndpointConfiguration configuration = m_settings.Configuration;
m_quotas = new ChannelQuotas {
MaxBufferSize = configuration.MaxBufferSize,
MaxMessageSize = configuration.MaxMessageSize,
MaxMessageSize = TcpMessageLimits.AlignRoundMaxMessageSize(configuration.MaxMessageSize),
ChannelLifetime = configuration.ChannelLifetime,
SecurityTokenLifetime = configuration.SecurityTokenLifetime,
MessageContext = new ServiceMessageContext() {
MaxArrayLength = configuration.MaxArrayLength,
MaxByteStringLength = configuration.MaxByteStringLength,
MaxMessageSize = configuration.MaxMessageSize,
MaxMessageSize = TcpMessageLimits.AlignRoundMaxMessageSize(configuration.MaxMessageSize),
MaxStringLength = configuration.MaxStringLength,
MaxEncodingNestingLevels = configuration.MaxEncodingNestingLevels,
MaxDecoderRecoveries = configuration.MaxDecoderRecoveries,
Expand Down

0 comments on commit 29659e1

Please sign in to comment.