Skip to content

Commit af5ac30

Browse files
committed
address feedback, allow switch
1 parent 9155cfc commit af5ac30

File tree

5 files changed

+14
-82
lines changed

5 files changed

+14
-82
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ public override bool Read()
35173517
bool more;
35183518

35193519
Debug.Assert(_stateObj == null || _stateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
3520-
TdsOperationStatus result = TryReadInternal(true, out more);
3520+
TdsOperationStatus result = TryReadInternal(true, out more);
35213521

35223522
if (result != TdsOperationStatus.Done)
35233523
{

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ internal bool Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader
19491949

19501950
bool dataReady;
19511951
TdsOperationStatus result = TryRun(runBehavior, cmdHandler, dataStream, bulkCopyHandler, stateObj, out dataReady);
1952-
Debug.Assert(result == TdsOperationStatus.Done, "Should never return false when _syncOverAsync is set");
1952+
Debug.Assert(result == TdsOperationStatus.Done, "Should always return Done when _syncOverAsync is set");
19531953
return dataReady;
19541954
}
19551955
finally

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ internal bool Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader
23872387

23882388
bool dataReady;
23892389
TdsOperationStatus result = TryRun(runBehavior, cmdHandler, dataStream, bulkCopyHandler, stateObj, out dataReady);
2390-
Debug.Assert(result == TdsOperationStatus.Done, "Should never return false when _syncOverAsync is set");
2390+
Debug.Assert(result == TdsOperationStatus.Done, "Should always return Done when _syncOverAsync is set");
23912391
return dataReady;
23922392
}
23932393
finally

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Packet.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ public int DataLength
2727
set
2828
{
2929
CheckDisposed();
30-
//if (value > 7992)
31-
//{
32-
// Debugger.Break();
33-
//}
3430
_dataLength = value;
3531
}
3632
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 11 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ sealed internal class LastIOTimer
2727
internal enum TdsOperationStatus : int
2828
{
2929
Done = 0,
30-
NeedMoreData = 2,
31-
InvalidData = 3
30+
NeedMoreData = 1,
31+
InvalidData = 2
3232
}
3333

3434
partial class TdsParserStateObject
@@ -1205,68 +1205,6 @@ public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len)
12051205
// Every time you call this method increment the offset and decrease len by the value of totalRead
12061206
public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len, out int totalRead)
12071207
{
1208-
1209-
TdsParser.ReliabilitySection.Assert("unreliable call to ReadByteArray"); // you need to setup for a thread abort somewhere before you call this method
1210-
totalRead = 0;
1211-
1212-
#if DEBUG
1213-
if (_snapshot != null && _snapshot.DoPend())
1214-
{
1215-
_networkPacketTaskSource = new TaskCompletionSource<object>();
1216-
Interlocked.MemoryBarrier();
1217-
1218-
if (s_forcePendingReadsToWaitForUser)
1219-
{
1220-
_realNetworkPacketTaskSource = new TaskCompletionSource<object>();
1221-
_realNetworkPacketTaskSource.SetResult(null);
1222-
}
1223-
else
1224-
{
1225-
_networkPacketTaskSource.TrySetResult(null);
1226-
}
1227-
return TdsOperationStatus.InvalidData;
1228-
}
1229-
#endif
1230-
1231-
Debug.Assert(buff.IsEmpty || buff.Length >= len, "Invalid length sent to ReadByteArray()!");
1232-
1233-
// loop through and read up to array length
1234-
while (len > 0)
1235-
{
1236-
if ((_inBytesPacket == 0) || (_inBytesUsed == _inBytesRead))
1237-
{
1238-
TdsOperationStatus result = TryPrepareBuffer();
1239-
if (result != TdsOperationStatus.Done)
1240-
{
1241-
return result;
1242-
}
1243-
}
1244-
1245-
int bytesToRead = Math.Min(len, Math.Min(_inBytesPacket, _inBytesRead - _inBytesUsed));
1246-
Debug.Assert(bytesToRead > 0, "0 byte read in TryReadByteArray");
1247-
if (!buff.IsEmpty)
1248-
{
1249-
ReadOnlySpan<byte> copyFrom = new ReadOnlySpan<byte>(_inBuff, _inBytesUsed, bytesToRead);
1250-
Span<byte> copyTo = buff.Slice(totalRead, bytesToRead);
1251-
copyFrom.CopyTo(copyTo);
1252-
}
1253-
1254-
totalRead += bytesToRead;
1255-
_inBytesUsed += bytesToRead;
1256-
_inBytesPacket -= bytesToRead;
1257-
len -= bytesToRead;
1258-
1259-
AssertValidState();
1260-
}
1261-
1262-
return TdsOperationStatus.Done;
1263-
}
1264-
1265-
1266-
1267-
public TdsOperationStatus TryReadPlpByteArray(Span<byte> buff, int len, out int totalRead)
1268-
{
1269-
12701208
TdsParser.ReliabilitySection.Assert("unreliable call to ReadByteArray"); // you need to setup for a thread abort somewhere before you call this method
12711209
totalRead = 0;
12721210

@@ -1973,7 +1911,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
19731911
buff = newbuf;
19741912
}
19751913

1976-
TdsOperationStatus result = TryReadPlpByteArray(buff.AsSpan(offset), bytesToRead, out bytesRead);
1914+
TdsOperationStatus result = TryReadByteArray(buff.AsSpan(offset), bytesToRead, out bytesRead);
19771915
Debug.Assert(bytesRead <= bytesLeft, "Read more bytes than we needed");
19781916
Debug.Assert((ulong)bytesRead <= _longlenleft, "Read more bytes than is available");
19791917

@@ -2010,10 +1948,9 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
20101948
result = TryReadPlpLength(false, out _);
20111949
if (result != TdsOperationStatus.Done)
20121950
{
2013-
if (!stored && result == TdsOperationStatus.NeedMoreData && _snapshot != null && _snapshot.ContinueEnabled)
1951+
if (!stored && result == TdsOperationStatus.NeedMoreData && _snapshot != null && _snapshotStatus != SnapshotStatus.NotActive && _snapshot.ContinueEnabled)
20141952
{
20151953
StoreReadPlpBytesProgress(this, bytesRead);
2016-
stored = true;
20171954
}
20181955
return result;
20191956
}
@@ -2948,7 +2885,7 @@ internal void Restore(TdsParserStateObject stateObj)
29482885
private PacketData _continuePacket;
29492886
private PacketData _sparePacket;
29502887

2951-
//private bool? _continueSupported;
2888+
private bool? _continueSupported;
29522889

29532890
#if DEBUG
29542891
private int _packetCounter;
@@ -2996,12 +2933,11 @@ public bool ContinueEnabled
29962933
{
29972934
get
29982935
{
2999-
//if (_continueSupported == null)
3000-
//{
3001-
// _continueSupported = AppContext.TryGetSwitch("Switch.Microsoft.Data.SqlClient.UseExperimentalAsyncContinue", out bool value) ? value : false;
3002-
//}
3003-
//return _continueSupported.Value;
3004-
return true;
2936+
if (_continueSupported == null)
2937+
{
2938+
_continueSupported = AppContext.TryGetSwitch("Switch.Microsoft.Data.SqlClient.UseExperimentalAsyncContinue", out bool value) ? value : false;
2939+
}
2940+
return _continueSupported.Value;
30052941
}
30062942
}
30072943

@@ -3197,7 +3133,7 @@ private void ClearState()
31973133
_packetCounter = 0;
31983134
#endif
31993135
_stateObj = null;
3200-
//_continueSupported = null;
3136+
_continueSupported = null;
32013137
}
32023138
}
32033139
}

0 commit comments

Comments
 (0)