Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PipeStream.cs
Go to the documentation of this file.
10
11namespace System.IO.Pipes;
12
13public abstract class PipeStream : Stream
14{
16 {
17 internal unsafe static readonly IOCompletionCallback s_ioCallback = IOCallback;
18
20
21 internal readonly PipeStream _pipeStream;
22
24
26
27 internal unsafe NativeOverlapped* _overlapped;
28
30
31 internal ulong _result;
32
33 internal short Version => _source.Version;
34
35 protected PipeValueTaskSource(PipeStream pipeStream)
36 {
37 _pipeStream = pipeStream;
38 _source.RunContinuationsAsynchronously = true;
40 }
41
42 internal void Dispose()
43 {
46 }
47
54
55 public ValueTaskSourceStatus GetStatus(short token)
56 {
57 return _source.GetStatus(token);
58 }
59
60 public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
61 {
62 _source.OnCompleted(continuation, state, token, flags);
63 }
64
65 void IValueTaskSource.GetResult(short token)
66 {
67 GetResult(token);
68 }
69
70 public int GetResult(short token)
71 {
72 try
73 {
74 return _source.GetResult(token);
75 }
76 finally
77 {
79 }
80 }
81
83 {
84 if (!cancellationToken.CanBeCanceled)
85 {
86 return;
87 }
88 try
89 {
90 _cancellationRegistration = cancellationToken.UnsafeRegister(delegate(object s, CancellationToken token)
91 {
92 PipeValueTaskSource pipeValueTaskSource = (PipeValueTaskSource)s;
93 if (!pipeValueTaskSource._pipeStream.SafePipeHandle.IsInvalid)
94 {
95 try
96 {
97 global::Interop.Kernel32.CancelIoEx(pipeValueTaskSource._pipeStream.SafePipeHandle, pipeValueTaskSource._overlapped);
98 }
100 {
101 }
102 }
103 }, this);
104 }
106 {
107 }
108 }
109
110 internal unsafe void ReleaseResources()
111 {
114 if (_overlapped != null)
115 {
117 _overlapped = null;
118 }
119 }
120
121 internal void FinishedScheduling()
122 {
123 ulong num = Interlocked.Exchange(ref _result, 1uL);
124 if (num != 0L)
125 {
126 Complete((uint)num, (uint)(int)(num >> 32) & 0x7FFFFFFFu);
127 }
128 }
129
130 private unsafe static void IOCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
131 {
133 if (Interlocked.Exchange(ref pipeValueTaskSource._result, 0x8000000000000000uL | ((ulong)numBytes << 32) | errorCode) != 0L)
134 {
135 pipeValueTaskSource.Complete(errorCode, numBytes);
136 }
137 }
138
139 private void Complete(uint errorCode, uint numBytes)
140 {
142 CompleteCore(errorCode, numBytes);
143 }
144
145 private protected abstract void CompleteCore(uint errorCode, uint numBytes);
146 }
147
149 {
150 internal readonly bool _isWrite;
151
153 : base(stream)
154 {
155 _isWrite = isWrite;
156 }
157
158 private protected override void CompleteCore(uint errorCode, uint numBytes)
159 {
160 if (!_isWrite)
161 {
162 bool completion = true;
163 switch (errorCode)
164 {
165 case 109u:
166 case 232u:
167 case 233u:
168 errorCode = 0u;
169 break;
170 case 234u:
171 errorCode = 0u;
172 completion = false;
173 break;
174 }
176 }
177 switch (errorCode)
178 {
179 case 0u:
180 _source.SetResult((int)numBytes);
181 break;
182 case 995u:
183 {
186 break;
187 }
188 default:
190 break;
191 }
192 }
193 }
194
196 {
198 : base(server)
199 {
200 }
201
202 private protected override void CompleteCore(uint errorCode, uint numBytes)
203 {
204 switch (errorCode)
205 {
206 case 0u:
207 case 535u:
208 _pipeStream.State = PipeState.Connected;
209 _source.SetResult((int)numBytes);
210 break;
211 case 995u:
212 {
215 break;
216 }
217 default:
219 break;
220 }
221 }
222 }
223
225
226 private bool _canRead;
227
228 private bool _canWrite;
229
230 private bool _isAsync;
231
232 private bool _isCurrentUserOnly;
233
234 private bool _isMessageComplete;
235
237
238 private bool _isHandleExposed;
239
241
243
245
246 private uint _outBufferSize;
247
249
251
253
255
256 public bool IsConnected
257 {
258 get
259 {
260 return State == PipeState.Connected;
261 }
262 protected set
263 {
264 _state = (value ? PipeState.Connected : PipeState.Disconnected);
265 }
266 }
267
268 public bool IsAsync => _isAsync;
269
271 {
272 get
273 {
274 if (_state == PipeState.WaitingToConnect)
275 {
277 }
278 if (_state == PipeState.Disconnected)
279 {
281 }
282 if (_handle == null)
283 {
285 }
286 if (_state == PipeState.Closed || (_handle != null && _handle.IsClosed))
287 {
288 throw Error.GetPipeNotOpen();
289 }
290 if (_readMode != PipeTransmissionMode.Message)
291 {
293 }
294 return _isMessageComplete;
295 }
296 }
297
299 {
300 get
301 {
302 if (_handle == null)
303 {
305 }
306 if (_handle.IsClosed)
307 {
308 throw Error.GetPipeNotOpen();
309 }
310 _isHandleExposed = true;
311 return _handle;
312 }
313 }
314
316
318
319 public override bool CanRead => _canRead;
320
321 public override bool CanWrite => _canWrite;
322
323 public override bool CanSeek => false;
324
325 public override long Length
326 {
327 get
328 {
330 }
331 }
332
333 public override long Position
334 {
335 get
336 {
338 }
339 set
340 {
342 }
343 }
344
345 internal PipeState State
346 {
347 get
348 {
349 return _state;
350 }
351 set
352 {
353 _state = value;
354 }
355 }
356
357 internal bool IsCurrentUserOnly
358 {
359 get
360 {
361 return _isCurrentUserOnly;
362 }
363 set
364 {
366 }
367 }
368
370 {
371 get
372 {
375 {
376 Unsafe.SkipInit(out uint num);
377 if (!global::Interop.Kernel32.GetNamedPipeInfo(_handle, &num, null, null, null))
378 {
380 }
381 if ((num & 4u) != 0)
382 {
383 return PipeTransmissionMode.Message;
384 }
385 return PipeTransmissionMode.Byte;
386 }
387 return _transmissionMode;
388 }
389 }
390
391 public unsafe virtual int InBufferSize
392 {
393 get
394 {
396 if (!CanRead)
397 {
399 }
400 Unsafe.SkipInit(out uint result);
401 if (!global::Interop.Kernel32.GetNamedPipeInfo(_handle, null, null, &result, null))
402 {
404 }
405 return (int)result;
406 }
407 }
408
409 public unsafe virtual int OutBufferSize
410 {
411 get
412 {
414 if (!CanWrite)
415 {
417 }
418 Unsafe.SkipInit(out uint outBufferSize);
419 if (_pipeDirection == PipeDirection.Out)
420 {
421 outBufferSize = _outBufferSize;
422 return (int)outBufferSize;
423 }
424 if (!global::Interop.Kernel32.GetNamedPipeInfo(_handle, null, &outBufferSize, null, null))
425 {
427 }
428 return (int)outBufferSize;
429 }
430 }
431
432 public unsafe virtual PipeTransmissionMode ReadMode
433 {
434 get
435 {
438 {
440 }
441 return _readMode;
442 }
443 set
444 {
446 if (value < PipeTransmissionMode.Byte || value > PipeTransmissionMode.Message)
447 {
449 }
450 int num = (int)value << 1;
451 if (!global::Interop.Kernel32.SetNamedPipeHandleState(_handle, &num, IntPtr.Zero, IntPtr.Zero))
452 {
454 }
456 }
457 }
458
459 protected PipeStream(PipeDirection direction, int bufferSize)
460 {
461 if (direction < PipeDirection.In || direction > PipeDirection.InOut)
462 {
464 }
465 if (bufferSize < 0)
466 {
468 }
469 Init(direction, PipeTransmissionMode.Byte, (uint)bufferSize);
470 }
471
472 protected PipeStream(PipeDirection direction, PipeTransmissionMode transmissionMode, int outBufferSize)
473 {
474 if (direction < PipeDirection.In || direction > PipeDirection.InOut)
475 {
477 }
478 if (transmissionMode < PipeTransmissionMode.Byte || transmissionMode > PipeTransmissionMode.Message)
479 {
481 }
482 if (outBufferSize < 0)
483 {
485 }
486 Init(direction, transmissionMode, (uint)outBufferSize);
487 }
488
489 private void Init(PipeDirection direction, PipeTransmissionMode transmissionMode, uint outBufferSize)
490 {
491 _readMode = transmissionMode;
492 _transmissionMode = transmissionMode;
493 _pipeDirection = direction;
494 if ((_pipeDirection & PipeDirection.In) != 0)
495 {
496 _canRead = true;
497 }
498 if ((_pipeDirection & PipeDirection.Out) != 0)
499 {
500 _canWrite = true;
501 }
502 _outBufferSize = outBufferSize;
503 _isMessageComplete = true;
504 _state = PipeState.WaitingToConnect;
505 }
506
507 protected void InitializeHandle(SafePipeHandle? handle, bool isExposed, bool isAsync)
508 {
509 if (isAsync && handle != null)
510 {
512 }
513 _handle = handle;
514 _isAsync = isAsync;
515 _isHandleExposed = isExposed;
516 _isFromExistingHandle = isExposed;
517 }
518
519 public unsafe override int ReadByte()
520 {
521 Unsafe.SkipInit(out byte result);
522 if (Read(new Span<byte>(&result, 1)) <= 0)
523 {
524 return -1;
525 }
526 return result;
527 }
528
529 public unsafe override void WriteByte(byte value)
530 {
532 }
533
534 public override void Flush()
535 {
537 }
538
540 {
541 try
542 {
543 Flush();
544 return Task.CompletedTask;
545 }
546 catch (Exception exception)
547 {
549 }
550 }
551
552 protected override void Dispose(bool disposing)
553 {
554 try
555 {
556 if (_handle != null && !_handle.IsClosed)
557 {
559 }
560 DisposeCore(disposing);
561 }
562 finally
563 {
564 base.Dispose(disposing);
565 }
566 _state = PipeState.Closed;
567 }
568
569 internal void UpdateMessageCompletion(bool completion)
570 {
571 _isMessageComplete = completion || _state == PipeState.Broken;
572 }
573
574 public override void SetLength(long value)
575 {
577 }
578
579 public override long Seek(long offset, SeekOrigin origin)
580 {
582 }
583
584 protected internal virtual void CheckPipePropertyOperations()
585 {
586 if (_handle == null)
587 {
589 }
590 if (_state == PipeState.Closed || (_handle != null && _handle.IsClosed))
591 {
592 throw Error.GetPipeNotOpen();
593 }
594 }
595
596 protected internal void CheckReadOperations()
597 {
598 if (_state == PipeState.WaitingToConnect)
599 {
601 }
602 if (_state == PipeState.Disconnected)
603 {
605 }
606 if (_handle == null)
607 {
609 }
610 if (_state == PipeState.Closed || (_handle != null && _handle.IsClosed))
611 {
612 throw Error.GetPipeNotOpen();
613 }
614 }
615
616 protected internal void CheckWriteOperations()
617 {
618 if (_state == PipeState.WaitingToConnect)
619 {
621 }
622 if (_state == PipeState.Disconnected)
623 {
625 }
626 if (_handle == null)
627 {
629 }
630 if (_state == PipeState.Broken)
631 {
633 }
634 if (_state == PipeState.Closed || (_handle != null && _handle.IsClosed))
635 {
636 throw Error.GetPipeNotOpen();
637 }
638 }
639
640 public override int Read(byte[] buffer, int offset, int count)
641 {
642 if (_isAsync)
643 {
645 }
647 if (!CanRead)
648 {
650 }
652 return ReadCore(new Span<byte>(buffer, offset, count));
653 }
654
655 public override int Read(Span<byte> buffer)
656 {
657 if (_isAsync)
658 {
659 return base.Read(buffer);
660 }
661 if (!CanRead)
662 {
664 }
666 return ReadCore(buffer);
667 }
668
670 {
672 if (!CanRead)
673 {
675 }
676 if (cancellationToken.IsCancellationRequested)
677 {
679 }
681 if (!_isAsync)
682 {
683 return base.ReadAsync(buffer, offset, count, cancellationToken);
684 }
685 if (count == 0)
686 {
687 UpdateMessageCompletion(completion: false);
688 return Task.FromResult(0);
689 }
691 }
692
694 {
695 if (!_isAsync)
696 {
697 return base.ReadAsync(buffer, cancellationToken);
698 }
699 if (!CanRead)
700 {
702 }
703 if (cancellationToken.IsCancellationRequested)
704 {
706 }
708 if (buffer.Length == 0)
709 {
710 UpdateMessageCompletion(completion: false);
711 return new ValueTask<int>(0);
712 }
714 }
715
716 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
717 {
718 if (_isAsync)
719 {
721 }
722 return base.BeginRead(buffer, offset, count, callback, state);
723 }
724
725 public override int EndRead(IAsyncResult asyncResult)
726 {
727 if (_isAsync)
728 {
730 }
731 return base.EndRead(asyncResult);
732 }
733
734 public override void Write(byte[] buffer, int offset, int count)
735 {
736 if (_isAsync)
737 {
739 return;
740 }
742 if (!CanWrite)
743 {
745 }
748 }
749
750 public override void Write(ReadOnlySpan<byte> buffer)
751 {
752 if (_isAsync)
753 {
754 base.Write(buffer);
755 return;
756 }
757 if (!CanWrite)
758 {
760 }
763 }
764
766 {
768 if (!CanWrite)
769 {
771 }
772 if (cancellationToken.IsCancellationRequested)
773 {
775 }
777 if (!_isAsync)
778 {
779 return base.WriteAsync(buffer, offset, count, cancellationToken);
780 }
781 if (count == 0)
782 {
783 return Task.CompletedTask;
784 }
786 }
787
789 {
790 if (!_isAsync)
791 {
792 return base.WriteAsync(buffer, cancellationToken);
793 }
794 if (!CanWrite)
795 {
797 }
798 if (cancellationToken.IsCancellationRequested)
799 {
801 }
803 if (buffer.Length == 0)
804 {
805 return default(ValueTask);
806 }
808 }
809
810 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
811 {
812 if (_isAsync)
813 {
815 }
816 return base.BeginWrite(buffer, offset, count, callback, state);
817 }
818
819 public override void EndWrite(IAsyncResult asyncResult)
820 {
821 if (_isAsync)
822 {
824 }
825 else
826 {
827 base.EndWrite(asyncResult);
828 }
829 }
830
831 internal static string GetPipePath(string serverName, string pipeName)
832 {
833 string fullPath = Path.GetFullPath("\\\\" + serverName + "\\pipe\\" + pipeName);
834 if (string.Equals(fullPath, "\\\\.\\pipe\\anonymous", StringComparison.OrdinalIgnoreCase))
835 {
837 }
838 return fullPath;
839 }
840
841 internal void ValidateHandleIsPipe(SafePipeHandle safePipeHandle)
842 {
843 if (global::Interop.Kernel32.GetFileType(safePipeHandle) != 3)
844 {
846 }
847 }
848
853
854 internal virtual void TryToReuse(PipeValueTaskSource source)
855 {
856 source._source.Reset();
857 if (source is ReadWriteValueTaskSource readWriteValueTaskSource && Interlocked.CompareExchange(ref readWriteValueTaskSource._isWrite ? ref _reusableWriteValueTaskSource : ref _reusableReadValueTaskSource, readWriteValueTaskSource, null) != null)
858 {
859 source._preallocatedOverlapped.Dispose();
860 }
861 }
862
863 private void DisposeCore(bool disposing)
864 {
865 if (disposing)
866 {
870 }
871 }
872
873 private unsafe int ReadCore(Span<byte> buffer)
874 {
875 if (buffer.Length == 0)
876 {
877 return 0;
878 }
879 fixed (byte* bytes = &MemoryMarshal.GetReference(buffer))
880 {
881 int numBytesRead = 0;
882 if (global::Interop.Kernel32.ReadFile(_handle, bytes, buffer.Length, out numBytesRead, IntPtr.Zero) != 0)
883 {
884 _isMessageComplete = true;
885 return numBytesRead;
886 }
887 int lastPInvokeError = Marshal.GetLastPInvokeError();
888 _isMessageComplete = lastPInvokeError != 234;
889 switch (lastPInvokeError)
890 {
891 case 234:
892 return numBytesRead;
893 case 109:
894 case 233:
895 State = PipeState.Broken;
896 return 0;
897 default:
898 throw System.IO.Win32Marshal.GetExceptionForWin32Error(lastPInvokeError, string.Empty);
899 }
900 }
901 }
902
904 {
905 ReadWriteValueTaskSource readWriteValueTaskSource = Interlocked.Exchange(ref _reusableReadValueTaskSource, null) ?? new ReadWriteValueTaskSource(this, isWrite: false);
906 try
907 {
908 readWriteValueTaskSource.PrepareForOperation(buffer);
909 if (global::Interop.Kernel32.ReadFile(_handle, (byte*)readWriteValueTaskSource._memoryHandle.Pointer, buffer.Length, IntPtr.Zero, readWriteValueTaskSource._overlapped) == 0)
910 {
911 int lastPInvokeError = Marshal.GetLastPInvokeError();
912 switch (lastPInvokeError)
913 {
914 case 997:
915 readWriteValueTaskSource.RegisterForCancellation(cancellationToken);
916 break;
917 case 109:
918 case 233:
919 State = PipeState.Broken;
920 readWriteValueTaskSource._overlapped->InternalLow = IntPtr.Zero;
921 readWriteValueTaskSource.Dispose();
922 UpdateMessageCompletion(completion: true);
923 return new ValueTask<int>(0);
924 default:
925 readWriteValueTaskSource.Dispose();
927 case 234:
928 break;
929 }
930 }
931 }
932 catch
933 {
934 readWriteValueTaskSource.Dispose();
935 throw;
936 }
937 readWriteValueTaskSource.FinishedScheduling();
938 return new ValueTask<int>(readWriteValueTaskSource, readWriteValueTaskSource.Version);
939 }
940
942 {
943 if (buffer.Length == 0)
944 {
945 return;
946 }
947 fixed (byte* bytes = &MemoryMarshal.GetReference(buffer))
948 {
949 int numBytesWritten = 0;
950 if (global::Interop.Kernel32.WriteFile(_handle, bytes, buffer.Length, out numBytesWritten, IntPtr.Zero) == 0)
951 {
953 }
954 }
955 }
956
958 {
959 ReadWriteValueTaskSource readWriteValueTaskSource = Interlocked.Exchange(ref _reusableWriteValueTaskSource, null) ?? new ReadWriteValueTaskSource(this, isWrite: true);
960 try
961 {
962 readWriteValueTaskSource.PrepareForOperation(buffer);
963 if (global::Interop.Kernel32.WriteFile(_handle, (byte*)readWriteValueTaskSource._memoryHandle.Pointer, buffer.Length, IntPtr.Zero, readWriteValueTaskSource._overlapped) == 0)
964 {
965 int lastPInvokeError = Marshal.GetLastPInvokeError();
966 if (lastPInvokeError != 997)
967 {
968 readWriteValueTaskSource.Dispose();
970 }
971 readWriteValueTaskSource.RegisterForCancellation(cancellationToken);
972 }
973 }
974 catch
975 {
976 readWriteValueTaskSource.Dispose();
977 throw;
978 }
979 readWriteValueTaskSource.FinishedScheduling();
980 return new ValueTask(readWriteValueTaskSource, readWriteValueTaskSource.Version);
981 }
982
983 [SupportedOSPlatform("windows")]
984 public void WaitForPipeDrain()
985 {
987 if (!CanWrite)
988 {
990 }
991 if (!global::Interop.Kernel32.FlushFileBuffers(_handle))
992 {
994 }
995 }
996
997 internal unsafe static global::Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability)
998 {
999 global::Interop.Kernel32.SECURITY_ATTRIBUTES result = default(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
1000 result.nLength = (uint)sizeof(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
1001 result.bInheritHandle = (((inheritability & HandleInheritability.Inheritable) != 0) ? global::Interop.BOOL.TRUE : global::Interop.BOOL.FALSE);
1002 return result;
1003 }
1004
1005 internal unsafe static global::Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, ref GCHandle pinningHandle)
1006 {
1007 global::Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);
1008 if (pipeSecurity != null)
1009 {
1010 byte[] securityDescriptorBinaryForm = pipeSecurity.GetSecurityDescriptorBinaryForm();
1011 pinningHandle = GCHandle.Alloc(securityDescriptorBinaryForm, GCHandleType.Pinned);
1012 fixed (byte* ptr = securityDescriptorBinaryForm)
1013 {
1014 secAttrs.lpSecurityDescriptor = (IntPtr)ptr;
1015 }
1016 }
1017 return secAttrs;
1018 }
1019
1020 private unsafe void UpdateReadMode()
1021 {
1022 Unsafe.SkipInit(out uint num);
1023 if (!global::Interop.Kernel32.GetNamedPipeHandleStateW(SafePipeHandle, &num, null, null, null, null, 0u))
1024 {
1026 }
1027 if ((num & 2u) != 0)
1028 {
1030 }
1031 else
1032 {
1034 }
1035 }
1036
1037 internal Exception WinIOError(int errorCode)
1038 {
1039 switch (errorCode)
1040 {
1041 case 109:
1042 case 232:
1043 case 233:
1044 _state = PipeState.Broken;
1046 case 38:
1047 return Error.GetEndOfFile();
1048 case 6:
1050 _state = PipeState.Broken;
1051 break;
1052 }
1054 }
1055}
static Exception GetReadNotSupported()
Definition Error.cs:10
static Exception GetWriteNotSupported()
Definition Error.cs:20
static Exception GetEndOfFile()
Definition Error.cs:5
static Exception GetOperationAborted()
Definition Error.cs:30
static Exception GetSeekNotSupported()
Definition Error.cs:15
static Exception GetPipeNotOpen()
Definition Error.cs:10
static string GetFullPath(string path)
Definition Path.cs:881
ConnectionValueTaskSource(NamedPipeServerStream server)
override void CompleteCore(uint errorCode, uint numBytes)
unsafe void PrepareForOperation(ReadOnlyMemory< byte > memory=default(ReadOnlyMemory< byte >))
Definition PipeStream.cs:48
static unsafe readonly IOCompletionCallback s_ioCallback
Definition PipeStream.cs:17
CancellationTokenRegistration _cancellationRegistration
Definition PipeStream.cs:29
void OnCompleted(Action< object > continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
Definition PipeStream.cs:60
unsafe void RegisterForCancellation(CancellationToken cancellationToken)
Definition PipeStream.cs:82
void CompleteCore(uint errorCode, uint numBytes)
readonly PreAllocatedOverlapped _preallocatedOverlapped
Definition PipeStream.cs:19
void Complete(uint errorCode, uint numBytes)
ManualResetValueTaskSourceCore< int > _source
Definition PipeStream.cs:25
void IValueTaskSource. GetResult(short token)
Definition PipeStream.cs:65
ValueTaskSourceStatus GetStatus(short token)
Definition PipeStream.cs:55
static unsafe void IOCallback(uint errorCode, uint numBytes, NativeOverlapped *pOverlapped)
override void CompleteCore(uint errorCode, uint numBytes)
ReadWriteValueTaskSource(PipeStream stream, bool isWrite)
ThreadPoolBoundHandle _threadPoolBinding
unsafe ValueTask WriteAsyncCore(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken)
override long Seek(long offset, SeekOrigin origin)
override void EndWrite(IAsyncResult asyncResult)
PipeDirection _pipeDirection
void DisposeCore(bool disposing)
override int Read(Span< byte > buffer)
unsafe int ReadCore(Span< byte > buffer)
unsafe ValueTask< int > ReadAsyncCore(Memory< byte > buffer, CancellationToken cancellationToken)
void ValidateHandleIsPipe(SafePipeHandle safePipeHandle)
override void Dispose(bool disposing)
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Exception WinIOError(int errorCode)
unsafe override void WriteByte(byte value)
static string GetPipePath(string serverName, string pipeName)
PipeStream(PipeDirection direction, int bufferSize)
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
PipeTransmissionMode _readMode
override int EndRead(IAsyncResult asyncResult)
override Task FlushAsync(CancellationToken cancellationToken)
SafePipeHandle? InternalHandle
unsafe override int ReadByte()
PipeTransmissionMode _transmissionMode
void Init(PipeDirection direction, PipeTransmissionMode transmissionMode, uint outBufferSize)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
void UpdateMessageCompletion(bool completion)
virtual void TryToReuse(PipeValueTaskSource source)
PipeStream(PipeDirection direction, PipeTransmissionMode transmissionMode, int outBufferSize)
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
SafePipeHandle SafePipeHandle
override void Write(ReadOnlySpan< byte > buffer)
virtual void CheckPipePropertyOperations()
override void Write(byte[] buffer, int offset, int count)
static unsafe global::Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, ref GCHandle pinningHandle)
ReadWriteValueTaskSource _reusableWriteValueTaskSource
override int Read(byte[] buffer, int offset, int count)
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
void InitializeAsyncHandle(SafePipeHandle handle)
ReadWriteValueTaskSource _reusableReadValueTaskSource
void InitializeHandle(SafePipeHandle? handle, bool isExposed, bool isAsync)
virtual unsafe PipeTransmissionMode ReadMode
virtual unsafe int InBufferSize
virtual unsafe PipeTransmissionMode TransmissionMode
unsafe void WriteCore(ReadOnlySpan< byte > buffer)
static unsafe global::Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability)
override void SetLength(long value)
virtual unsafe int OutBufferSize
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
Definition Stream.cs:1044
static int MakeHRFromErrorCode(int errorCode)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static string InvalidOperation_PipeReadModeNotMessage
Definition SR.cs:50
static string IO_InvalidPipeHandle
Definition SR.cs:76
static string NotSupported_UnwritableStream
Definition SR.cs:30
static string InvalidOperation_PipeHandleNotSet
Definition SR.cs:48
static string NotSupported_UnreadableStream
Definition SR.cs:32
static string ArgumentOutOfRange_TransmissionModeByteOrMsg
Definition SR.cs:30
static string InvalidOperation_PipeNotYetConnected
Definition SR.cs:44
static string ArgumentOutOfRange_AnonymousReserved
Definition SR.cs:28
static string IO_PipeBroken
Definition SR.cs:74
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
static string ArgumentOutOfRange_DirectionModeInOutOrInOut
Definition SR.cs:32
static string InvalidOperation_PipeDisconnected
Definition SR.cs:46
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
static int Exchange(ref int location1, int value)
static IAsyncResult Begin(Task task, AsyncCallback callback, object state)
Definition TaskToApm.cs:43
static void End(IAsyncResult asyncResult)
Definition TaskToApm.cs:48
static Task FromException(Exception exception)
Definition Task.cs:3341
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 ThreadPoolBoundHandle BindHandle(SafeHandle handle)
unsafe void FreeNativeOverlapped(NativeOverlapped *overlapped)
unsafe NativeOverlapped * AllocateNativeOverlapped(IOCompletionCallback callback, object? state, object? pinData)
static unsafe? object GetNativeOverlappedState(NativeOverlapped *overlapped)
unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)
static readonly IntPtr Zero
Definition IntPtr.cs:18
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81
void OnCompleted(Action< object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
static ValueTask FromCanceled(CancellationToken cancellationToken)
Definition ValueTask.cs:180
static ValueTask FromException(Exception exception)
Definition ValueTask.cs:190