internal void Complete(int read, uint errorCode = UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) { if (_requestStream.TryCheckSizeLimit(read + (int)DataAlreadyRead, out var exception)) { _tcs.TrySetException(exception); } else if (_tcs.TrySetResult(read + (int)DataAlreadyRead)) { RequestStream.UpdateAfterRead((uint)errorCode, (uint)(read + DataAlreadyRead)); if (_callback != null) { try { _callback(this); } catch (Exception) { // TODO: Exception handling? This may be an IO callback thread and throwing here could crash the app. } } } Dispose(); }
internal RequestStreamAsyncResult(RequestStream requestStream, object userState, AsyncCallback callback, byte[] buffer, int offset, uint dataAlreadyRead) : this(requestStream, userState, callback, buffer, offset, dataAlreadyRead, new CancellationTokenRegistration()) { }
internal RequestStreamAsyncResult(RequestStream requestStream, object userState, AsyncCallback callback, uint dataAlreadyRead) : this(requestStream, userState, callback) { _dataAlreadyRead = dataAlreadyRead; }
internal RequestStreamAsyncResult(RequestStream requestStream, object userState, AsyncCallback callback) { _requestStream = requestStream; _tcs = new TaskCompletionSource <int>(userState); _callback = callback; }