Skip to content

Commit

Permalink
use cached callback and remove queued packet type
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 committed Sep 5, 2021
1 parent 717839d commit 5d6e3db
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@
<Compile Include="Microsoft\Data\SqlClient\SNI\SNILoadHandle.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIMarsConnection.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIMarsHandle.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIMarsQueuedPacket.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNINpHandle.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPacket.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPacket.Debug.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class SNIMarsHandle : SNIHandle
private readonly SNIMarsConnection _connection;
private readonly uint _status = TdsEnums.SNI_UNINITIALIZED;
private readonly Queue<SNIPacket> _receivedPacketQueue = new Queue<SNIPacket>();
private readonly Queue<SNIMarsQueuedPacket> _sendPacketQueue = new Queue<SNIMarsQueuedPacket>();
private readonly Queue<SNIPacket> _sendPacketQueue = new Queue<SNIPacket>();
private readonly object _callbackObject;
private readonly Guid _connectionId;
private readonly ushort _sessionId;
Expand Down Expand Up @@ -214,7 +214,7 @@ private uint InternalSendAsync(SNIPacket packet)
}

SNIPacket muxedPacket = SetPacketSMUXHeader(packet);
muxedPacket.SetAsyncIOCompletionCallback(HandleSendComplete);
muxedPacket.SetAsyncIOCompletionCallback(_handleSendCompleteCallback);
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Sending packet", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater);
return _connection.SendAsync(muxedPacket);
}
Expand All @@ -229,7 +229,7 @@ private uint SendPendingPackets()
{
using (TrySNIEventScope.Create(nameof(SNIMarsHandle)))
{
SNIMarsQueuedPacket packet = null;
SNIPacket packet = null;

while (true)
{
Expand All @@ -240,7 +240,7 @@ private uint SendPendingPackets()
if (_sendPacketQueue.Count != 0)
{
packet = _sendPacketQueue.Peek();
uint result = InternalSendAsync(packet.Packet);
uint result = InternalSendAsync(packet);

if (result != TdsEnums.SNI_SUCCESS && result != TdsEnums.SNI_SUCCESS_IO_PENDING)
{
Expand Down Expand Up @@ -277,9 +277,10 @@ public override uint SendAsync(SNIPacket packet)
Debug.Assert(_connection != null && Monitor.IsEntered(_connection.DemuxerSync), "SNIMarsHandle.HandleRecieveComplete should be called while holding the SNIMarsConnection.DemuxerSync because it can cause deadlocks");
using (TrySNIEventScope.Create(nameof(SNIMarsHandle)))
{
packet.SetAsyncIOCompletionCallback(_handleSendCompleteCallback);
lock (this)
{
_sendPacketQueue.Enqueue(new SNIMarsQueuedPacket(packet, _handleSendCompleteCallback));
_sendPacketQueue.Enqueue(packet);
}

SendPendingPackets();
Expand Down

This file was deleted.

0 comments on commit 5d6e3db

Please sign in to comment.