Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,29 @@ public override uint Send(SNIPacket packet)
}

/// <summary>
/// Receive a packet synchronously
/// Receives a packet synchronously.
/// </summary>
/// <param name="packet">SNI packet</param>
/// <param name="timeoutInMilliseconds">Timeout in Milliseconds</param>
/// <returns>SNI error code</returns>
/// <param name="packet">The received SNI packet.</param>
/// <param name="timeoutInMilliseconds">
/// Timeout in milliseconds:
/// - If greater than 0, sets the socket's receive timeout to the specified value.
/// - If equal to -1, represents an infinite timeout (socket timeout is set to 0).
/// - If less than -1 or equal to 0, results in a timeout error.
/// </param>
/// <returns>SNI error code indicating the result of the operation.</returns>
public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds)
{
SNIPacket errorPacket;
lock (this)
{
packet = null;

if (_socket == null)
{
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Socket is null.", args0: _connectionId);
return ReportTcpSNIError(0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_10);
}

try
{
if (timeoutInMilliseconds > 0)
Expand All @@ -784,8 +796,7 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds)
}
else if (timeoutInMilliseconds == -1)
{
// SqlClient internally represents infinite timeout by -1, and for TcpClient this is translated to a timeout of 0
_socket.ReceiveTimeout = 0;
_socket.ReceiveTimeout = Timeout.Infinite;
}
else
{
Expand Down Expand Up @@ -840,7 +851,9 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds)
}
finally
{
_socket.ReceiveTimeout = 0;
// Reset the socket timeout to Timeout.Infinite after the receive operation is done
// to avoid blocking the thread in case of a timeout error.
_socket.ReceiveTimeout = Timeout.Infinite;
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,9 @@
<data name="SNI_ERROR_9" xml:space="preserve">
<value>Associating port with I/O completion mechanism failed</value>
</data>
<data name="SNI_ERROR_10" xml:space="preserve">
<value>Socket is null</value>
</data>
<data name="SNI_ERROR_11" xml:space="preserve">
<value>Timeout error</value>
</data>
Expand Down Expand Up @@ -1944,4 +1947,4 @@
<data name="SNI_PN11" xml:space="preserve">
<value>SQL Network Interfaces</value>
</data>
</root>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3805,7 +3805,7 @@
<value>Associating port with I/O completion mechanism failed</value>
</data>
<data name="SNI_ERROR_10" xml:space="preserve">
<value />
<value>Socket is null</value>
</data>
<data name="SNI_ERROR_11" xml:space="preserve">
<value>Timeout error</value>
Expand Down
Loading