Skip to content

Commit

Permalink
Using absolute time for connection lifetime checking (DNET-787).
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Oct 12, 2017
1 parent 37565d2 commit 0e165ca
Showing 1 changed file with 13 additions and 8 deletions.
Expand Up @@ -20,7 +20,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FirebirdSql.Data.Common;
Expand All @@ -42,10 +41,10 @@ sealed class Item : IDisposable
{
bool _disposed;

public DateTimeOffset Created { get; private set; }
public long Created { get; private set; }
public FbConnectionInternal Connection { get; private set; }

public Item(DateTimeOffset created, FbConnectionInternal connection)
public Item(long created, FbConnectionInternal connection)
{
Created = created;
Connection = connection;
Expand All @@ -56,7 +55,7 @@ public void Dispose()
if (_disposed)
return;
_disposed = true;
Created = default(DateTimeOffset);
Created = default(long);
Connection.Dispose();
Connection = null;
}
Expand Down Expand Up @@ -114,7 +113,7 @@ public void ReleaseConnection(FbConnectionInternal connection)
var removed = _busy.Remove(connection);
if (removed)
{
_available.Push(new Item(DateTimeOffset.UtcNow, connection));
_available.Push(new Item(GetTicks(), connection));
}
}
}
Expand All @@ -125,7 +124,7 @@ public void CleanupPool()
{
CheckDisposedImpl();

var now = DateTimeOffset.UtcNow;
var now = GetTicks();
var available = _available.ToArray();
if (available.Count() <= _connectionString.MinPoolSize)
return;
Expand Down Expand Up @@ -160,11 +159,17 @@ static FbConnectionInternal CreateNewConnection(FbConnectionString connectionStr
return result;
}

static bool IsAlive(long connectionLifeTime, DateTimeOffset created, DateTimeOffset now)
static bool IsAlive(long connectionLifeTime, long created, long now)
{
if (connectionLifeTime == 0)
return true;
return created.AddSeconds(connectionLifeTime) > now;
return (now - created) > (connectionLifeTime * 1000);
}

static long GetTicks()
{
var ticks = Environment.TickCount;
return ticks + -(long)int.MinValue;
}

void CleanConnectionsImpl()
Expand Down

0 comments on commit 0e165ca

Please sign in to comment.