Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close socket if a client stops processing responses. #2110

Merged
merged 16 commits into from
Apr 10, 2023
Merged
Prev Previous commit
Next Next commit
revert
  • Loading branch information
mregen committed Mar 30, 2023
commit ee4f68c01dbd1e67814f1053b3025fdc70bb5471
15 changes: 8 additions & 7 deletions Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;

namespace Opc.Ua.Bindings
Expand Down Expand Up @@ -137,6 +136,7 @@ public void Open(
m_serverCertificate = settings.ServerCertificate;
m_serverCertificateChain = settings.ServerCertificateChain;

m_bufferManager = new BufferManager("Server", (int)Int32.MaxValue, m_quotas.MaxBufferSize);
m_channels = new Dictionary<uint, TcpListenerChannel>();
m_reverseConnectListener = settings.ReverseConnectListener;

Expand Down Expand Up @@ -224,7 +224,7 @@ public void CreateReverseConnection(Uri url, int timeout)
TcpServerChannel channel = new TcpServerChannel(
m_listenerId,
this,
new BufferManager("ServerReverseConnect", 200, m_quotas.MaxBufferSize),
m_bufferManager,
m_quotas,
m_serverCertificate,
m_descriptions);
Expand Down Expand Up @@ -488,16 +488,13 @@ private void OnAccept(object sender, SocketAsyncEventArgs e)
{
try
{
// get channel id
uint channelId = GetNextChannelId();

if (m_reverseConnectListener)
{
// create the channel to manage incoming reverse connections.
channel = new TcpReverseConnectChannel(
m_listenerId,
this,
new BufferManager($"ClientReverseConnect #{channelId}", 200, m_quotas.MaxBufferSize),
m_bufferManager,
m_quotas,
m_descriptions);
}
Expand All @@ -507,7 +504,7 @@ private void OnAccept(object sender, SocketAsyncEventArgs e)
channel = new TcpServerChannel(
m_listenerId,
this,
new BufferManager($"ServerChannel #{channelId}", 200, m_quotas.MaxBufferSize),
m_bufferManager,
m_quotas,
m_serverCertificate,
m_serverCertificateChain,
Expand All @@ -522,6 +519,9 @@ private void OnAccept(object sender, SocketAsyncEventArgs e)
channel.SetReportCertificateAuditCalback(new ReportAuditCertificateEventHandler(OnReportAuditCertificateEvent));
}

// get channel id
uint channelId = GetNextChannelId();

// start accepting messages on the channel.
channel.Attach(channelId, e.AcceptSocket);

Expand Down Expand Up @@ -714,6 +714,7 @@ private void SetUri(Uri baseAddress, string relativeAddress)
private string m_listenerId;
private Uri m_uri;
private EndpointDescriptionCollection m_descriptions;
private BufferManager m_bufferManager;
private ChannelQuotas m_quotas;
private X509Certificate2 m_serverCertificate;
private X509Certificate2Collection m_serverCertificateChain;
Expand Down
2 changes: 1 addition & 1 deletion Stack/Opc.Ua.Core/Stack/Tcp/UaSCBinaryTransportChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private void SaveSettings(Uri url, TransportChannelSettings settings)
m_quotas.CertificateValidator = settings.CertificateValidator;

// create the buffer manager.
m_bufferManager = new BufferManager("Client", 200, settings.Configuration.MaxBufferSize);
m_bufferManager = new BufferManager("Client", (int)Int32.MaxValue, settings.Configuration.MaxBufferSize);
}

/// <summary>
Expand Down