Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Stream.cs
Go to the documentation of this file.
7
8namespace System.IO;
9
11{
12 private struct ReadWriteParameters
13 {
14 internal byte[] Buffer;
15
16 internal int Offset;
17
18 internal int Count;
19 }
20
21 private sealed class ReadWriteTask : Task<int>, ITaskCompletionAction
22 {
23 internal readonly bool _isRead;
24
25 internal readonly bool _apm;
26
27 internal bool _endCalled;
28
29 internal Stream _stream;
30
31 internal byte[] _buffer;
32
33 internal readonly int _offset;
34
35 internal readonly int _count;
36
37 private AsyncCallback _callback;
38
40
42
43 bool ITaskCompletionAction.InvokeMayRunArbitraryCode => true;
44
45 internal void ClearBeginState()
46 {
47 _stream = null;
48 _buffer = null;
49 }
50
51 public ReadWriteTask(bool isRead, bool apm, Func<object, int> function, object state, Stream stream, byte[] buffer, int offset, int count, AsyncCallback callback)
53 {
54 _isRead = isRead;
55 _apm = apm;
59 _count = count;
60 if (callback != null)
61 {
62 _callback = callback;
65 }
66 }
67
68 private static void InvokeAsyncCallback(object completedTask)
69 {
70 ReadWriteTask readWriteTask = (ReadWriteTask)completedTask;
71 AsyncCallback callback = readWriteTask._callback;
72 readWriteTask._callback = null;
73 callback(readWriteTask);
74 }
75
76 void ITaskCompletionAction.Invoke(Task completingTask)
77 {
78 ExecutionContext context = _context;
79 if (context == null)
80 {
81 AsyncCallback callback = _callback;
82 _callback = null;
83 callback(completingTask);
84 }
85 else
86 {
87 _context = null;
89 ExecutionContext.RunInternal(context, callback2, this);
90 }
91 }
92 }
93
94 private sealed class NullStream : Stream
95 {
96 public override bool CanRead => true;
97
98 public override bool CanWrite => true;
99
100 public override bool CanSeek => true;
101
102 public override long Length => 0L;
103
104 public override long Position
105 {
106 get
107 {
108 return 0L;
109 }
110 set
111 {
112 }
113 }
114
115 internal NullStream()
116 {
117 }
118
119 public override void CopyTo(Stream destination, int bufferSize)
120 {
121 }
122
124 {
125 if (!cancellationToken.IsCancellationRequested)
126 {
127 return Task.CompletedTask;
128 }
130 }
131
132 protected override void Dispose(bool disposing)
133 {
134 }
135
136 public override void Flush()
137 {
138 }
139
141 {
142 if (!cancellationToken.IsCancellationRequested)
143 {
144 return Task.CompletedTask;
145 }
147 }
148
149 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
150 {
151 return TaskToApm.Begin(Task<int>.s_defaultResultTask, callback, state);
152 }
153
154 public override int EndRead(IAsyncResult asyncResult)
155 {
156 return TaskToApm.End<int>(asyncResult);
157 }
158
159 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
160 {
161 return TaskToApm.Begin(Task.CompletedTask, callback, state);
162 }
163
164 public override void EndWrite(IAsyncResult asyncResult)
165 {
167 }
168
169 public override int Read(byte[] buffer, int offset, int count)
170 {
171 return 0;
172 }
173
174 public override int Read(Span<byte> buffer)
175 {
176 return 0;
177 }
178
180 {
181 if (!cancellationToken.IsCancellationRequested)
182 {
183 return Task.FromResult(0);
184 }
186 }
187
189 {
190 if (!cancellationToken.IsCancellationRequested)
191 {
192 return default(ValueTask<int>);
193 }
195 }
196
197 public override int ReadByte()
198 {
199 return -1;
200 }
201
202 public override void Write(byte[] buffer, int offset, int count)
203 {
204 }
205
206 public override void Write(ReadOnlySpan<byte> buffer)
207 {
208 }
209
211 {
212 if (!cancellationToken.IsCancellationRequested)
213 {
214 return Task.CompletedTask;
215 }
217 }
218
220 {
221 if (!cancellationToken.IsCancellationRequested)
222 {
223 return default(ValueTask);
224 }
226 }
227
228 public override void WriteByte(byte value)
229 {
230 }
231
232 public override long Seek(long offset, SeekOrigin origin)
233 {
234 return 0L;
235 }
236
237 public override void SetLength(long length)
238 {
239 }
240 }
241
242 private sealed class SyncStream : Stream, IDisposable
243 {
244 private readonly Stream _stream;
245
246 public override bool CanRead => _stream.CanRead;
247
248 public override bool CanWrite => _stream.CanWrite;
249
250 public override bool CanSeek => _stream.CanSeek;
251
252 public override bool CanTimeout => _stream.CanTimeout;
253
254 public override long Length
255 {
256 get
257 {
258 lock (_stream)
259 {
260 return _stream.Length;
261 }
262 }
263 }
264
265 public override long Position
266 {
267 get
268 {
269 lock (_stream)
270 {
271 return _stream.Position;
272 }
273 }
274 set
275 {
276 lock (_stream)
277 {
278 _stream.Position = value;
279 }
280 }
281 }
282
283 public override int ReadTimeout
284 {
285 get
286 {
287 return _stream.ReadTimeout;
288 }
289 set
290 {
291 _stream.ReadTimeout = value;
292 }
293 }
294
295 public override int WriteTimeout
296 {
297 get
298 {
299 return _stream.WriteTimeout;
300 }
301 set
302 {
303 _stream.WriteTimeout = value;
304 }
305 }
306
308 {
309 _stream = stream ?? throw new ArgumentNullException("stream");
310 }
311
312 public override void Close()
313 {
314 lock (_stream)
315 {
316 try
317 {
318 _stream.Close();
319 }
320 finally
321 {
322 base.Dispose(disposing: true);
323 }
324 }
325 }
326
327 protected override void Dispose(bool disposing)
328 {
329 lock (_stream)
330 {
331 try
332 {
333 if (disposing)
334 {
335 ((IDisposable)_stream).Dispose();
336 }
337 }
338 finally
339 {
340 base.Dispose(disposing);
341 }
342 }
343 }
344
345 public override ValueTask DisposeAsync()
346 {
347 lock (_stream)
348 {
349 return _stream.DisposeAsync();
350 }
351 }
352
353 public override void Flush()
354 {
355 lock (_stream)
356 {
357 _stream.Flush();
358 }
359 }
360
361 public override int Read(byte[] bytes, int offset, int count)
362 {
363 lock (_stream)
364 {
365 return _stream.Read(bytes, offset, count);
366 }
367 }
368
369 public override int Read(Span<byte> buffer)
370 {
371 lock (_stream)
372 {
373 return _stream.Read(buffer);
374 }
375 }
376
377 public override int ReadByte()
378 {
379 lock (_stream)
380 {
381 return _stream.ReadByte();
382 }
383 }
384
385 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
386 {
388 lock (_stream)
389 {
390 IAsyncResult result;
391 if (!flag)
392 {
393 IAsyncResult asyncResult = _stream.BeginReadInternal(buffer, offset, count, callback, state, serializeAsynchronously: true, apm: true);
394 result = asyncResult;
395 }
396 else
397 {
398 result = _stream.BeginRead(buffer, offset, count, callback, state);
399 }
400 return result;
401 }
402 }
403
404 public override int EndRead(IAsyncResult asyncResult)
405 {
406 if (asyncResult == null)
407 {
409 }
410 lock (_stream)
411 {
413 }
414 }
415
416 public override long Seek(long offset, SeekOrigin origin)
417 {
418 lock (_stream)
419 {
420 return _stream.Seek(offset, origin);
421 }
422 }
423
424 public override void SetLength(long length)
425 {
426 lock (_stream)
427 {
429 }
430 }
431
432 public override void Write(byte[] bytes, int offset, int count)
433 {
434 lock (_stream)
435 {
437 }
438 }
439
440 public override void Write(ReadOnlySpan<byte> buffer)
441 {
442 lock (_stream)
443 {
445 }
446 }
447
448 public override void WriteByte(byte b)
449 {
450 lock (_stream)
451 {
453 }
454 }
455
456 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
457 {
459 lock (_stream)
460 {
461 IAsyncResult result;
462 if (!flag)
463 {
464 IAsyncResult asyncResult = _stream.BeginWriteInternal(buffer, offset, count, callback, state, serializeAsynchronously: true, apm: true);
465 result = asyncResult;
466 }
467 else
468 {
469 result = _stream.BeginWrite(buffer, offset, count, callback, state);
470 }
471 return result;
472 }
473 }
474
475 public override void EndWrite(IAsyncResult asyncResult)
476 {
477 if (asyncResult == null)
478 {
480 }
481 lock (_stream)
482 {
484 }
485 }
486 }
487
488 public static readonly Stream Null = new NullStream();
489
491
492 public abstract bool CanRead { get; }
493
494 public abstract bool CanWrite { get; }
495
496 public abstract bool CanSeek { get; }
497
498 public virtual bool CanTimeout => false;
499
500 public abstract long Length { get; }
501
502 public abstract long Position { get; set; }
503
504 public virtual int ReadTimeout
505 {
506 get
507 {
509 }
510 set
511 {
513 }
514 }
515
516 public virtual int WriteTimeout
517 {
518 get
519 {
521 }
522 set
523 {
525 }
526 }
527
528 [MethodImpl(MethodImplOptions.InternalCall)]
529 private extern bool HasOverriddenBeginEndRead();
530
531 [MethodImpl(MethodImplOptions.InternalCall)]
532 private extern bool HasOverriddenBeginEndWrite();
533
534 [MemberNotNull("_asyncActiveSemaphore")]
539
541 {
543 }
544
545 public virtual void CopyTo(Stream destination, int bufferSize)
546 {
548 if (!CanRead)
549 {
550 if (CanWrite)
551 {
553 }
555 }
556 byte[] array = ArrayPool<byte>.Shared.Rent(bufferSize);
557 try
558 {
559 int count;
560 while ((count = Read(array, 0, array.Length)) != 0)
561 {
562 destination.Write(array, 0, count);
563 }
564 }
565 finally
566 {
568 }
569 }
570
575
576 public Task CopyToAsync(Stream destination, int bufferSize)
577 {
578 return CopyToAsync(destination, bufferSize, CancellationToken.None);
579 }
580
585
587 {
589 if (!CanRead)
590 {
591 if (CanWrite)
592 {
594 }
596 }
597 return Core(this, destination, bufferSize, cancellationToken);
598 static async Task Core(Stream source, Stream destination, int bufferSize, CancellationToken cancellationToken)
599 {
600 byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
601 try
602 {
603 int length;
604 while ((length = await source.ReadAsync(new Memory<byte>(buffer), cancellationToken).ConfigureAwait(continueOnCapturedContext: false)) != 0)
605 {
606 await destination.WriteAsync(new ReadOnlyMemory<byte>(buffer, 0, length), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
607 }
608 }
609 finally
610 {
612 }
613 }
614 }
615
616 private int GetCopyBufferSize()
617 {
618 int num = 81920;
619 if (CanSeek)
620 {
621 long length = Length;
622 long position = Position;
623 if (length <= position)
624 {
625 num = 1;
626 }
627 else
628 {
629 long num2 = length - position;
630 if (num2 > 0)
631 {
632 num = (int)Math.Min(num, num2);
633 }
634 }
635 }
636 return num;
637 }
638
639 public void Dispose()
640 {
641 Close();
642 }
643
644 public virtual void Close()
645 {
646 Dispose(disposing: true);
647 GC.SuppressFinalize(this);
648 }
649
650 protected virtual void Dispose(bool disposing)
651 {
652 }
653
654 public virtual ValueTask DisposeAsync()
655 {
656 try
657 {
658 Dispose();
659 return default(ValueTask);
660 }
661 catch (Exception exception)
662 {
664 }
665 }
666
667 public abstract void Flush();
668
670 {
672 }
673
675 {
676 return Task.Factory.StartNew(delegate(object state)
677 {
678 ((Stream)state).Flush();
680 }
681
682 [Obsolete("CreateWaitHandle has been deprecated. Use the ManualResetEvent(false) constructor instead.")]
683 protected virtual WaitHandle CreateWaitHandle()
684 {
685 return new ManualResetEvent(initialState: false);
686 }
687
688 public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
689 {
690 return BeginReadInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);
691 }
692
693 internal Task<int> BeginReadInternal(byte[] buffer, int offset, int count, AsyncCallback callback, object state, bool serializeAsynchronously, bool apm)
694 {
696 if (!CanRead)
697 {
699 }
701 Task task = null;
702 if (serializeAsynchronously)
703 {
704 task = semaphoreSlim.WaitAsync();
705 }
706 else
707 {
708 semaphoreSlim.Wait();
709 }
710 ReadWriteTask readWriteTask = new ReadWriteTask(isRead: true, apm, delegate
711 {
712 ReadWriteTask readWriteTask2 = Task.InternalCurrent as ReadWriteTask;
713 try
714 {
715 return readWriteTask2._stream.Read(readWriteTask2._buffer, readWriteTask2._offset, readWriteTask2._count);
716 }
717 finally
718 {
719 if (!readWriteTask2._apm)
720 {
721 readWriteTask2._stream.FinishTrackingAsyncOperation(readWriteTask2);
722 }
723 readWriteTask2.ClearBeginState();
724 }
725 }, state, this, buffer, offset, count, callback);
726 if (task != null)
727 {
728 RunReadWriteTaskWhenReady(task, readWriteTask);
729 }
730 else
731 {
732 RunReadWriteTask(readWriteTask);
733 }
734 return readWriteTask;
735 }
736
737 public virtual int EndRead(IAsyncResult asyncResult)
738 {
739 if (asyncResult == null)
740 {
742 }
743 ReadWriteTask readWriteTask = asyncResult as ReadWriteTask;
744 if (readWriteTask == null || !readWriteTask._isRead)
745 {
746 ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple);
747 }
748 else if (readWriteTask._endCalled)
749 {
750 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple);
751 }
752 try
753 {
754 return readWriteTask.GetAwaiter().GetResult();
755 }
756 finally
757 {
758 FinishTrackingAsyncOperation(readWriteTask);
759 }
760 }
761
762 public Task<int> ReadAsync(byte[] buffer, int offset, int count)
763 {
765 }
766
768 {
769 if (!cancellationToken.IsCancellationRequested)
770 {
772 }
774 }
775
777 {
778 if (MemoryMarshal.TryGetArray((ReadOnlyMemory<byte>)buffer, out ArraySegment<byte> segment))
779 {
780 return new ValueTask<int>(ReadAsync(segment.Array, segment.Offset, segment.Count, cancellationToken));
781 }
782 byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length);
783 return FinishReadAsync(ReadAsync(array, 0, buffer.Length, cancellationToken), array, buffer);
784 static async ValueTask<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Memory<byte> localDestination)
785 {
786 try
787 {
788 int num = await readTask.ConfigureAwait(continueOnCapturedContext: false);
789 new ReadOnlySpan<byte>(localBuffer, 0, num).CopyTo(localDestination.Span);
790 return num;
791 }
792 finally
793 {
794 ArrayPool<byte>.Shared.Return(localBuffer);
795 }
796 }
797 }
798
800 {
802 {
803 return BeginReadInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
804 }
805 return TaskFactory<int>.FromAsyncTrim(this, new ReadWriteParameters
806 {
807 Buffer = buffer,
808 Offset = offset,
809 Count = count
810 }, (Stream stream, ReadWriteParameters args, AsyncCallback callback, object state) => stream.BeginRead(args.Buffer, args.Offset, args.Count, callback, state), (Stream stream, IAsyncResult asyncResult) => stream.EndRead(asyncResult));
811 }
812
813 public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
814 {
815 return BeginWriteInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);
816 }
817
818 internal Task BeginWriteInternal(byte[] buffer, int offset, int count, AsyncCallback callback, object state, bool serializeAsynchronously, bool apm)
819 {
821 if (!CanWrite)
822 {
824 }
826 Task task = null;
827 if (serializeAsynchronously)
828 {
829 task = semaphoreSlim.WaitAsync();
830 }
831 else
832 {
833 semaphoreSlim.Wait();
834 }
835 ReadWriteTask readWriteTask = new ReadWriteTask(isRead: false, apm, delegate
836 {
837 ReadWriteTask readWriteTask2 = Task.InternalCurrent as ReadWriteTask;
838 try
839 {
840 readWriteTask2._stream.Write(readWriteTask2._buffer, readWriteTask2._offset, readWriteTask2._count);
841 return 0;
842 }
843 finally
844 {
845 if (!readWriteTask2._apm)
846 {
847 readWriteTask2._stream.FinishTrackingAsyncOperation(readWriteTask2);
848 }
849 readWriteTask2.ClearBeginState();
850 }
851 }, state, this, buffer, offset, count, callback);
852 if (task != null)
853 {
854 RunReadWriteTaskWhenReady(task, readWriteTask);
855 }
856 else
857 {
858 RunReadWriteTask(readWriteTask);
859 }
860 return readWriteTask;
861 }
862
863 private static void RunReadWriteTaskWhenReady(Task asyncWaiter, ReadWriteTask readWriteTask)
864 {
865 if (asyncWaiter.IsCompleted)
866 {
867 RunReadWriteTask(readWriteTask);
868 return;
869 }
870 asyncWaiter.ContinueWith(delegate(Task t, object state)
871 {
872 ReadWriteTask readWriteTask2 = (ReadWriteTask)state;
873 RunReadWriteTask(readWriteTask2);
874 }, readWriteTask, default(CancellationToken), TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
875 }
876
877 private static void RunReadWriteTask(ReadWriteTask readWriteTask)
878 {
879 readWriteTask.m_taskScheduler = TaskScheduler.Default;
880 readWriteTask.ScheduleAndStart(needsProtection: false);
881 }
882
884 {
885 task._endCalled = true;
887 }
888
889 public virtual void EndWrite(IAsyncResult asyncResult)
890 {
891 if (asyncResult == null)
892 {
894 }
895 ReadWriteTask readWriteTask = asyncResult as ReadWriteTask;
896 if (readWriteTask == null || readWriteTask._isRead)
897 {
898 ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple);
899 }
900 else if (readWriteTask._endCalled)
901 {
902 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple);
903 }
904 try
905 {
906 readWriteTask.GetAwaiter().GetResult();
907 }
908 finally
909 {
910 FinishTrackingAsyncOperation(readWriteTask);
911 }
912 }
913
914 public Task WriteAsync(byte[] buffer, int offset, int count)
915 {
917 }
918
920 {
921 if (!cancellationToken.IsCancellationRequested)
922 {
924 }
926 }
927
929 {
930 if (MemoryMarshal.TryGetArray(buffer, out var segment))
931 {
932 return new ValueTask(WriteAsync(segment.Array, segment.Offset, segment.Count, cancellationToken));
933 }
934 byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length);
935 buffer.Span.CopyTo(array);
937 }
938
939 private static async Task FinishWriteAsync(Task writeTask, byte[] localBuffer)
940 {
941 try
942 {
943 await writeTask.ConfigureAwait(continueOnCapturedContext: false);
944 }
945 finally
946 {
947 ArrayPool<byte>.Shared.Return(localBuffer);
948 }
949 }
950
951 private Task BeginEndWriteAsync(byte[] buffer, int offset, int count)
952 {
954 {
955 return BeginWriteInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
956 }
957 return TaskFactory<VoidTaskResult>.FromAsyncTrim(this, new ReadWriteParameters
958 {
959 Buffer = buffer,
960 Offset = offset,
961 Count = count
962 }, (Stream stream, ReadWriteParameters args, AsyncCallback callback, object state) => stream.BeginWrite(args.Buffer, args.Offset, args.Count, callback, state), delegate(Stream stream, IAsyncResult asyncResult)
963 {
964 stream.EndWrite(asyncResult);
965 return default(VoidTaskResult);
966 });
967 }
968
969 public abstract long Seek(long offset, SeekOrigin origin);
970
971 public abstract void SetLength(long value);
972
973 public abstract int Read(byte[] buffer, int offset, int count);
974
975 public virtual int Read(Span<byte> buffer)
976 {
977 byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length);
978 try
979 {
980 int num = Read(array, 0, buffer.Length);
981 if ((uint)num > (uint)buffer.Length)
982 {
984 }
986 return num;
987 }
988 finally
989 {
991 }
992 }
993
994 public virtual int ReadByte()
995 {
996 byte[] array = new byte[1];
997 if (Read(array, 0, 1) != 0)
998 {
999 return array[0];
1000 }
1001 return -1;
1002 }
1003
1004 public abstract void Write(byte[] buffer, int offset, int count);
1005
1006 public virtual void Write(ReadOnlySpan<byte> buffer)
1007 {
1008 byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length);
1009 try
1010 {
1011 buffer.CopyTo(array);
1012 Write(array, 0, buffer.Length);
1013 }
1014 finally
1015 {
1017 }
1018 }
1019
1020 public virtual void WriteByte(byte value)
1021 {
1022 Write(new byte[1] { value }, 0, 1);
1023 }
1024
1026 {
1027 if (stream != null)
1028 {
1029 if (!(stream is SyncStream))
1030 {
1031 return new SyncStream(stream);
1032 }
1033 return stream;
1034 }
1035 throw new ArgumentNullException("stream");
1036 }
1037
1038 [Obsolete("Do not call or override this method.")]
1039 protected virtual void ObjectInvariant()
1040 {
1041 }
1042
1043 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1044 protected static void ValidateBufferArguments(byte[] buffer, int offset, int count)
1045 {
1046 if (buffer == null)
1047 {
1049 }
1050 if (offset < 0)
1051 {
1052 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.offset, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
1053 }
1054 if ((uint)count > buffer.Length - offset)
1055 {
1057 }
1058 }
1059
1060 protected static void ValidateCopyToArguments(Stream destination, int bufferSize)
1061 {
1062 if (destination == null)
1063 {
1064 throw new ArgumentNullException("destination");
1065 }
1066 if (bufferSize <= 0)
1067 {
1068 throw new ArgumentOutOfRangeException("bufferSize", bufferSize, SR.ArgumentOutOfRange_NeedPosNum);
1069 }
1070 if (!destination.CanWrite)
1071 {
1072 if (destination.CanRead)
1073 {
1075 }
1077 }
1078 }
1079}
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Definition Stream.cs:149
override void Write(ReadOnlySpan< byte > buffer)
Definition Stream.cs:206
override void Flush()
Definition Stream.cs:136
override Task FlushAsync(CancellationToken cancellationToken)
Definition Stream.cs:140
override long Seek(long offset, SeekOrigin origin)
Definition Stream.cs:232
override void Dispose(bool disposing)
Definition Stream.cs:132
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Definition Stream.cs:159
override int Read(Span< byte > buffer)
Definition Stream.cs:174
override void CopyTo(Stream destination, int bufferSize)
Definition Stream.cs:119
override void EndWrite(IAsyncResult asyncResult)
Definition Stream.cs:164
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken)
Definition Stream.cs:188
override void WriteByte(byte value)
Definition Stream.cs:228
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Definition Stream.cs:210
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Definition Stream.cs:219
override bool CanRead
Definition Stream.cs:96
override void SetLength(long length)
Definition Stream.cs:237
override int ReadByte()
Definition Stream.cs:197
override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
Definition Stream.cs:123
override void Write(byte[] buffer, int offset, int count)
Definition Stream.cs:202
override bool CanWrite
Definition Stream.cs:98
override int EndRead(IAsyncResult asyncResult)
Definition Stream.cs:154
override bool CanSeek
Definition Stream.cs:100
override int Read(byte[] buffer, int offset, int count)
Definition Stream.cs:169
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Definition Stream.cs:179
static void InvokeAsyncCallback(object completedTask)
Definition Stream.cs:68
ReadWriteTask(bool isRead, bool apm, Func< object, int > function, object state, Stream stream, byte[] buffer, int offset, int count, AsyncCallback callback)
Definition Stream.cs:51
ExecutionContext _context
Definition Stream.cs:39
static ContextCallback s_invokeAsyncCallback
Definition Stream.cs:41
override bool CanWrite
Definition Stream.cs:248
override int EndRead(IAsyncResult asyncResult)
Definition Stream.cs:404
override long Seek(long offset, SeekOrigin origin)
Definition Stream.cs:416
override void EndWrite(IAsyncResult asyncResult)
Definition Stream.cs:475
override int ReadByte()
Definition Stream.cs:377
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Definition Stream.cs:456
override int ReadTimeout
Definition Stream.cs:284
override void WriteByte(byte b)
Definition Stream.cs:448
SyncStream(Stream stream)
Definition Stream.cs:307
override int WriteTimeout
Definition Stream.cs:296
override void Close()
Definition Stream.cs:312
override void Flush()
Definition Stream.cs:353
override int Read(byte[] bytes, int offset, int count)
Definition Stream.cs:361
override void Dispose(bool disposing)
Definition Stream.cs:327
readonly Stream _stream
Definition Stream.cs:244
override void SetLength(long length)
Definition Stream.cs:424
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Definition Stream.cs:385
override int Read(Span< byte > buffer)
Definition Stream.cs:369
override bool CanRead
Definition Stream.cs:246
override bool CanTimeout
Definition Stream.cs:252
override void Write(byte[] bytes, int offset, int count)
Definition Stream.cs:432
override void Write(ReadOnlySpan< byte > buffer)
Definition Stream.cs:440
override bool CanSeek
Definition Stream.cs:250
override ValueTask DisposeAsync()
Definition Stream.cs:345
static async Task FinishWriteAsync(Task writeTask, byte[] localBuffer)
Definition Stream.cs:939
virtual void Dispose(bool disposing)
Definition Stream.cs:650
Task CopyToAsync(Stream destination, int bufferSize)
Definition Stream.cs:576
Task FlushAsync()
Definition Stream.cs:669
virtual int ReadByte()
Definition Stream.cs:994
bool HasOverriddenBeginEndRead()
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
Definition Stream.cs:1044
Task BeginEndWriteAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:951
void SetLength(long value)
bool HasOverriddenBeginEndWrite()
virtual void Write(ReadOnlySpan< byte > buffer)
Definition Stream.cs:1006
long Seek(long offset, SeekOrigin origin)
static void RunReadWriteTask(ReadWriteTask readWriteTask)
Definition Stream.cs:877
virtual bool CanTimeout
Definition Stream.cs:498
virtual Task FlushAsync(CancellationToken cancellationToken)
Definition Stream.cs:674
static void ValidateCopyToArguments(Stream destination, int bufferSize)
Definition Stream.cs:1060
virtual void Close()
Definition Stream.cs:644
virtual int ReadTimeout
Definition Stream.cs:505
Task WriteAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:914
virtual void EndWrite(IAsyncResult asyncResult)
Definition Stream.cs:889
int Read(byte[] buffer, int offset, int count)
virtual int Read(Span< byte > buffer)
Definition Stream.cs:975
virtual void CopyTo(Stream destination, int bufferSize)
Definition Stream.cs:545
void CopyTo(Stream destination)
Definition Stream.cs:540
void Dispose()
Definition Stream.cs:639
Task< int > BeginReadInternal(byte[] buffer, int offset, int count, AsyncCallback callback, object state, bool serializeAsynchronously, bool apm)
Definition Stream.cs:693
virtual Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Definition Stream.cs:767
static Stream Synchronized(Stream stream)
Definition Stream.cs:1025
int GetCopyBufferSize()
Definition Stream.cs:616
void FinishTrackingAsyncOperation(ReadWriteTask task)
Definition Stream.cs:883
Task< int > ReadAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:762
SemaphoreSlim _asyncActiveSemaphore
Definition Stream.cs:490
Task CopyToAsync(Stream destination, CancellationToken cancellationToken)
Definition Stream.cs:581
virtual void ObjectInvariant()
Definition Stream.cs:1039
void Write(byte[] buffer, int offset, int count)
virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
Definition Stream.cs:688
virtual void WriteByte(byte value)
Definition Stream.cs:1020
virtual WaitHandle CreateWaitHandle()
Definition Stream.cs:683
virtual Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
Definition Stream.cs:586
Task BeginWriteInternal(byte[] buffer, int offset, int count, AsyncCallback callback, object state, bool serializeAsynchronously, bool apm)
Definition Stream.cs:818
virtual ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Definition Stream.cs:776
virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
Definition Stream.cs:813
virtual int WriteTimeout
Definition Stream.cs:517
Task< int > BeginEndReadAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:799
virtual int EndRead(IAsyncResult asyncResult)
Definition Stream.cs:737
static readonly Stream Null
Definition Stream.cs:488
static void RunReadWriteTaskWhenReady(Task asyncWaiter, ReadWriteTask readWriteTask)
Definition Stream.cs:863
Task CopyToAsync(Stream destination)
Definition Stream.cs:571
SemaphoreSlim EnsureAsyncActiveSemaphoreInitialized()
Definition Stream.cs:535
virtual ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Definition Stream.cs:928
virtual ValueTask DisposeAsync()
Definition Stream.cs:654
virtual Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Definition Stream.cs:919
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static string ArgumentOutOfRange_NeedPosNum
Definition SR.cs:20
static string IO_StreamTooLong
Definition SR.cs:1586
static string InvalidOperation_TimeoutsNotSupported
Definition SR.cs:1520
Definition SR.cs:7
static void RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
static ? ExecutionContext Capture()
static int CompareExchange(ref int location1, int value, int comparand)
static IAsyncResult Begin(Task task, AsyncCallback callback, object state)
Definition TaskToApm.cs:43
static void End(IAsyncResult asyncResult)
Definition TaskToApm.cs:48
Task ContinueWith(Action< Task< TResult > > continuationAction)
Definition Task.cs:263
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
void AddCompletionAction(ITaskCompletionAction action, bool addBeforeOthers=false)
Definition Task.cs:2952
static new TaskFactory< TResult > Factory
Definition Task.cs:56
void ScheduleAndStart(bool needsProtection)
Definition Task.cs:1702
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363
static Task CompletedTask
Definition Task.cs:1120
new TaskAwaiter< TResult > GetAwaiter()
Definition Task.cs:221
static bool Read(ref bool location)
Definition Volatile.cs:67
static void ThrowNotSupportedException_UnwritableStream()
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowInvalidOperationException()
static void ThrowArgumentNullException(string name)
static void ThrowArgumentException(ExceptionResource resource)
static void ThrowObjectDisposedException_StreamClosed(string objectName)
static void ThrowNotSupportedException_UnreadableStream()
delegate void ContextCallback(object? state)
unsafe Span< T > Span
Definition Memory.cs:28
void CopyTo(Span< T > destination)
static ValueTask FromCanceled(CancellationToken cancellationToken)
Definition ValueTask.cs:180
static ValueTask FromException(Exception exception)
Definition ValueTask.cs:190