@@ -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