Skip to content

Commit

Permalink
Count connection attempts rather than successful connections
Browse files Browse the repository at this point in the history
References #1
  • Loading branch information
andreashuber-lawo committed Oct 30, 2015
1 parent 15f8f1f commit 00040f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
1 change: 0 additions & 1 deletion Lawo.GlowAnalyzerProxy.Main/ConnectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ internal TcpClient Client

if (this.client != null)
{
++this.ConnectionCountCore;
this.BytesReceivedCore = 0;
this.LastReceived = DateTime.UtcNow;
}
Expand Down
48 changes: 29 additions & 19 deletions Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ private async Task ForwardLoop(TcpListener listener)
{
if (listener.Pending())
{
++this.ConsumerConnection.ConnectionCountCore;
string logPath;

while (File.Exists(logPath = GetLogFilename()))
Expand All @@ -355,35 +356,44 @@ private async Task ForwardLoop(TcpListener listener)

try
{
this.ConsumerConnection.Client = await listener.AcceptTcpClientAsync();
listener.Stop();
}
catch (Exception ex)
{
await EnqueueLogOperationAsync(
logInfo, "Exception", null, null, i => i.Logger.LogException("Consumer to Proxy", ex));
}
++this.ProviderConnection.ConnectionCountCore;
this.ProviderConnection.Client = await ConnectToProvider();

using (this.ConsumerConnection.Client)
{
try
{
using (this.ProviderConnection.Client = await ConnectToProvider())
{
await Task.WhenAll(
this.ForwardFromConsumerAsync(logInfo), this.ForwardFromProviderAsync(logInfo));
}
this.ConsumerConnection.Client = await listener.AcceptTcpClientAsync();
listener.Stop();
await Task.WhenAll(
this.ForwardFromConsumerAsync(logInfo), this.ForwardFromProviderAsync(logInfo));
}
catch (Exception ex)
{
listener.Stop();
await EnqueueLogOperationAsync(
logInfo, "Exception", null, null, i => i.Logger.LogException("Proxy to Provider", ex));
logInfo, "Exception", null, null, i => i.Logger.LogException("Consumer to Proxy", ex));
}

if (this.ConsumerConnection.Client != null)
{
this.ConsumerConnection.Client.Close();
this.ConsumerConnection.Client = null;
}
}
catch (Exception ex)
{
listener.Stop();
await EnqueueLogOperationAsync(
logInfo, "Exception", null, null, i => i.Logger.LogException("Proxy to Provider", ex));
}

if (this.ProviderConnection.Client != null)
{
this.ProviderConnection.Client.Close();
this.ProviderConnection.Client = null;
}

this.ConsumerConnection.Client = null;
this.ProviderConnection.Client = null;
await EnqueueLogOperationAsync(logInfo, null, null, null, i => { i.Dispose(); return new EventInfo(); });
await EnqueueLogOperationAsync(
logInfo, null, null, null, i => { i.Dispose(); return new EventInfo(); });
listener.Start();
}
else
Expand Down

0 comments on commit 00040f2

Please sign in to comment.