Skip to content
Merged
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