Skip to content

Commit

Permalink
Fix zero connection time issue (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
karinazhou authored Nov 28, 2019
1 parent 60fd1da commit 42497c7
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public SNITCPHandle(string serverName, int port, long timerExpire, object callba
}
else
{
_socket = Connect(serverName, port, ts);
_socket = Connect(serverName, port, ts, isInfiniteTimeOut);
}

if (_socket == null || !_socket.Connected)
Expand Down Expand Up @@ -179,7 +179,7 @@ public SNITCPHandle(string serverName, int port, long timerExpire, object callba
_status = TdsEnums.SNI_SUCCESS;
}

private static Socket Connect(string serverName, int port, TimeSpan timeout)
private static Socket Connect(string serverName, int port, TimeSpan timeout, bool isInfiniteTimeout)
{
IPAddress[] ipAddresses = Dns.GetHostAddresses(serverName);
IPAddress serverIPv4 = null;
Expand All @@ -199,7 +199,16 @@ private static Socket Connect(string serverName, int port, TimeSpan timeout)
Socket[] sockets = new Socket[2];

CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(timeout);

if (isInfiniteTimeout)
{
cts.CancelAfter(-1);
}
else
{
cts.CancelAfter(timeout);
}

void Cancel()
{
for (int i = 0; i < sockets.Length; ++i)
Expand Down

0 comments on commit 42497c7

Please sign in to comment.