11
11
/*
12
12
* Win32FileStream supports different modes of accessing the disk - async mode
13
13
* and sync mode. They are two completely different codepaths in the
14
- * sync & async methods (ie, Read/Write vs. BeginRead/BeginWrite ). File
14
+ * sync & async methods (ie, Read/Write vs. ReadAsync/WriteAsync ). File
15
15
* handles in NT can be opened in only sync or overlapped (async) mode,
16
16
* and we have to deal with this pain. Stream has implementations of
17
17
* the sync methods in terms of the async ones, so we'll
@@ -650,9 +650,8 @@ public override void SetLength(long value)
650
650
SetLengthCore ( value ) ;
651
651
}
652
652
653
- // We absolutely need this method broken out so that BeginWriteCore can call
654
- // a method without having to go through buffering code that might call
655
- // FlushWrite.
653
+ // We absolutely need this method broken out so that WriteInternalCoreAsync can call
654
+ // a method without having to go through buffering code that might call FlushWrite.
656
655
[ System . Security . SecuritySafeCritical ] // auto-generated
657
656
private void SetLengthCore ( long value )
658
657
{
@@ -1109,7 +1108,7 @@ private Task<int> ReadInternalAsync(byte[] array, int offset, int numBytes, Canc
1109
1108
// OS appears to use a 4K buffer internally. If you write to a
1110
1109
// pipe that is full, you will block until someone read from
1111
1110
// that pipe. If you try reading from an empty pipe and
1112
- // Win32FileStream's BeginRead blocks waiting for data to fill it's
1111
+ // Win32FileStream's ReadAsync blocks waiting for data to fill it's
1113
1112
// internal buffer, you will be blocked. In a case where a child
1114
1113
// process writes to stdout & stderr while a parent process tries
1115
1114
// reading from both, you can easily get into a deadlock here.
@@ -1194,9 +1193,6 @@ private Task<int> ReadInternalAsync(byte[] array, int offset, int numBytes, Canc
1194
1193
_readLen = 0 ;
1195
1194
return ReadInternalCoreAsync ( array , offset + n , numBytes - n , n , cancellationToken ) ;
1196
1195
}
1197
- // WARNING: all state on asyncResult objects must be set before
1198
- // we call ReadFile in BeginReadCore, since the OS can run our
1199
- // callback & the user's callback before ReadFile returns.
1200
1196
}
1201
1197
}
1202
1198
@@ -1207,7 +1203,7 @@ unsafe private Task<int> ReadInternalCoreAsync(byte[] bytes, int offset, int num
1207
1203
Debug . Assert ( _parent . CanRead , "_parent.CanRead" ) ;
1208
1204
Debug . Assert ( bytes != null , "bytes != null" ) ;
1209
1205
Debug . Assert ( _writePos == 0 , "_writePos == 0" ) ;
1210
- Debug . Assert ( _isAsync , "BeginReadCore doesn't work on synchronous file streams!" ) ;
1206
+ Debug . Assert ( _isAsync , "ReadInternalCoreAsync doesn't work on synchronous file streams!" ) ;
1211
1207
Debug . Assert ( offset >= 0 , "offset is negative" ) ;
1212
1208
Debug . Assert ( numBytes >= 0 , "numBytes is negative" ) ;
1213
1209
@@ -1359,7 +1355,7 @@ private Task WriteInternalAsync(byte[] array, int offset, int numBytes, Cancella
1359
1355
// OS appears to use a 4K buffer internally. If you write to a
1360
1356
// pipe that is full, you will block until someone read from
1361
1357
// that pipe. If you try reading from an empty pipe and
1362
- // Win32FileStream's BeginRead blocks waiting for data to fill it's
1358
+ // Win32FileStream's ReadAsync blocks waiting for data to fill it's
1363
1359
// internal buffer, you will be blocked. In a case where a child
1364
1360
// process writes to stdout & stderr while a parent process tries
1365
1361
// reading from both, you can easily get into a deadlock here.
@@ -1404,7 +1400,7 @@ unsafe private Task<int> WriteInternalCoreAsync(byte[] bytes, int offset, int nu
1404
1400
Debug . Assert ( _parent . CanWrite , "_parent.CanWrite" ) ;
1405
1401
Debug . Assert ( bytes != null , "bytes != null" ) ;
1406
1402
Debug . Assert ( _readPos == _readLen , "_readPos == _readLen" ) ;
1407
- Debug . Assert ( _isAsync , "BeginWriteCore doesn't work on synchronous file streams!" ) ;
1403
+ Debug . Assert ( _isAsync , "WriteInternalCoreAsync doesn't work on synchronous file streams!" ) ;
1408
1404
Debug . Assert ( offset >= 0 , "offset is negative" ) ;
1409
1405
Debug . Assert ( numBytes >= 0 , "numBytes is negative" ) ;
1410
1406
@@ -1416,15 +1412,15 @@ unsafe private Task<int> WriteInternalCoreAsync(byte[] bytes, int offset, int nu
1416
1412
{
1417
1413
// Make sure we set the length of the file appropriately.
1418
1414
long len = _parent . Length ;
1419
- //Console.WriteLine("BeginWrite - Calculating end pos. pos: "+pos+" len: "+len+" numBytes: "+numBytes);
1415
+ //Console.WriteLine("WriteInternalCoreAsync - Calculating end pos. pos: "+pos+" len: "+len+" numBytes: "+numBytes);
1420
1416
1421
1417
// Make sure we are writing to the position that we think we are
1422
1418
if ( _exposedHandle )
1423
1419
VerifyOSHandlePosition ( ) ;
1424
1420
1425
1421
if ( _pos + numBytes > len )
1426
1422
{
1427
- //Console.WriteLine("BeginWrite - Setting length to: "+(pos + numBytes));
1423
+ //Console.WriteLine("WriteInternalCoreAsync - Setting length to: "+(pos + numBytes));
1428
1424
SetLengthCore ( _pos + numBytes ) ;
1429
1425
}
1430
1426
@@ -1439,7 +1435,7 @@ unsafe private Task<int> WriteInternalCoreAsync(byte[] bytes, int offset, int nu
1439
1435
SeekCore ( numBytes , SeekOrigin . Current ) ;
1440
1436
}
1441
1437
1442
- //Console.WriteLine("BeginWrite finishing. pos: "+pos+" numBytes: "+numBytes+" _pos: "+_pos+" Position: "+Position);
1438
+ //Console.WriteLine("WriteInternalCoreAsync finishing. pos: "+pos+" numBytes: "+numBytes+" _pos: "+_pos+" Position: "+Position);
1443
1439
1444
1440
int errorCode = 0 ;
1445
1441
// queue an async WriteFile operation and pass in a packed overlapped
@@ -1591,15 +1587,12 @@ private unsafe int ReadFileNative(SafeFileHandle handle, byte[] bytes, int offse
1591
1587
if ( r == 0 )
1592
1588
{
1593
1589
errorCode = Marshal . GetLastWin32Error ( ) ;
1594
- // We should never ignore an error here without some extra work.
1595
- // We must make sure that BeginReadCore won't return an
1596
- // IAsyncResult that will cause EndRead to block, since the OS
1597
- // won't call AsyncFSCallback for us.
1590
+
1598
1591
if ( errorCode == ERROR_BROKEN_PIPE || errorCode == Interop . mincore . Errors . ERROR_PIPE_NOT_CONNECTED )
1599
1592
{
1600
1593
// This handle was a pipe, and it's done. Not an error, but EOF.
1601
1594
// However, the OS will not call AsyncFSCallback!
1602
- // Let the caller handle this, since BeginReadCore & ReadCore
1595
+ // Let the caller handle this, since ReadInternalCoreAsync & ReadCore
1603
1596
// need to do different things.
1604
1597
return - 1 ;
1605
1598
}
@@ -1662,16 +1655,12 @@ private unsafe int WriteFileNative(SafeFileHandle handle, byte[] bytes, int offs
1662
1655
if ( r == 0 )
1663
1656
{
1664
1657
errorCode = Marshal . GetLastWin32Error ( ) ;
1665
- // We should never ignore an error here without some extra work.
1666
- // We must make sure that BeginWriteCore won't return an
1667
- // IAsyncResult that will cause EndWrite to block, since the OS
1668
- // won't call AsyncFSCallback for us.
1669
1658
1670
1659
if ( errorCode == ERROR_NO_DATA )
1671
1660
{
1672
1661
// This handle was a pipe, and the pipe is being closed on the
1673
- // other side. Let the caller handle this, since BeginWriteCore
1674
- // & WriteCore need to do different things.
1662
+ // other side. Let the caller handle this, since Write
1663
+ // and WriteAsync need to do different things.
1675
1664
return - 1 ;
1676
1665
}
1677
1666
0 commit comments