@@ -13,38 +13,24 @@ internal unsafe class RequestStreamAsyncResult : IAsyncResult, IDisposable
1313
1414 private readonly SafeNativeOverlapped ? _overlapped ;
1515 private readonly IntPtr _pinnedBuffer ;
16+ private readonly int _size ;
1617 private readonly uint _dataAlreadyRead ;
1718 private readonly TaskCompletionSource < int > _tcs ;
1819 private readonly RequestStream _requestStream ;
1920 private readonly AsyncCallback ? _callback ;
2021 private readonly CancellationTokenRegistration _cancellationRegistration ;
2122
22- internal RequestStreamAsyncResult ( RequestStream requestStream , object ? userState , AsyncCallback ? callback )
23+ internal RequestStreamAsyncResult ( RequestStream requestStream , object ? userState , AsyncCallback ? callback , byte [ ] buffer , int offset , int size , uint dataAlreadyRead , CancellationTokenRegistration cancellationRegistration )
2324 {
2425 _requestStream = requestStream ;
2526 _tcs = new TaskCompletionSource < int > ( userState ) ;
2627 _callback = callback ;
27- }
28-
29- internal RequestStreamAsyncResult ( RequestStream requestStream , object ? userState , AsyncCallback ? callback , uint dataAlreadyRead )
30- : this ( requestStream , userState , callback )
31- {
32- _dataAlreadyRead = dataAlreadyRead ;
33- }
34-
35- internal RequestStreamAsyncResult ( RequestStream requestStream , object ? userState , AsyncCallback ? callback , byte [ ] buffer , int offset , uint dataAlreadyRead )
36- : this ( requestStream , userState , callback , buffer , offset , dataAlreadyRead , new CancellationTokenRegistration ( ) )
37- {
38- }
39-
40- internal RequestStreamAsyncResult ( RequestStream requestStream , object ? userState , AsyncCallback ? callback , byte [ ] buffer , int offset , uint dataAlreadyRead , CancellationTokenRegistration cancellationRegistration )
41- : this ( requestStream , userState , callback )
42- {
4328 _dataAlreadyRead = dataAlreadyRead ;
4429 var boundHandle = requestStream . RequestContext . Server . RequestQueue . BoundHandle ;
4530 _overlapped = new SafeNativeOverlapped ( boundHandle ,
4631 boundHandle . AllocateNativeOverlapped ( IOCallback , this , buffer ) ) ;
4732 _pinnedBuffer = ( Marshal . UnsafeAddrOfPinnedArrayElement ( buffer , offset ) ) ;
33+ _size = size ;
4834 _cancellationRegistration = cancellationRegistration ;
4935 }
5036
@@ -83,7 +69,13 @@ private static void IOCompleted(RequestStreamAsyncResult asyncResult, uint error
8369 {
8470 try
8571 {
86- if ( errorCode != UnsafeNclNativeMethods . ErrorCodes . ERROR_SUCCESS && errorCode != UnsafeNclNativeMethods . ErrorCodes . ERROR_HANDLE_EOF )
72+ // Zero-byte reads
73+ if ( errorCode == UnsafeNclNativeMethods . ErrorCodes . ERROR_MORE_DATA && asyncResult . _size == 0 )
74+ {
75+ // numBytes returns 1 to let us know there's data available. Don't count it against the request body size yet.
76+ asyncResult . Complete ( 0 , errorCode ) ;
77+ }
78+ else if ( errorCode != UnsafeNclNativeMethods . ErrorCodes . ERROR_SUCCESS && errorCode != UnsafeNclNativeMethods . ErrorCodes . ERROR_HANDLE_EOF )
8779 {
8880 asyncResult . Fail ( new IOException ( string . Empty , new HttpSysException ( ( int ) errorCode ) ) ) ;
8981 }
0 commit comments