38 _source.RunContinuationsAsynchronously =
true;
126 Complete((uint)num, (uint)(
int)(num >> 32) & 0x7FFFFFFFu);
135 pipeValueTaskSource.
Complete(errorCode, numBytes);
139 private void Complete(uint errorCode, uint numBytes)
145 private protected abstract void CompleteCore(uint errorCode, uint numBytes);
158 private protected override void CompleteCore(uint errorCode, uint numBytes)
162 bool completion =
true;
202 private protected override void CompleteCore(uint errorCode, uint numBytes)
376 Unsafe.SkipInit(out uint num);
377 if (!global::Interop.Kernel32.GetNamedPipeInfo(
_handle, &num,
null,
null,
null))
400 Unsafe.SkipInit(out uint result);
401 if (!global::Interop.Kernel32.GetNamedPipeInfo(
_handle,
null,
null, &result,
null))
418 Unsafe.SkipInit(out uint outBufferSize);
422 return (
int)outBufferSize;
424 if (!global::Interop.Kernel32.GetNamedPipeInfo(
_handle,
null, &outBufferSize,
null,
null))
428 return (
int)outBufferSize;
450 int num = (int)
value << 1;
461 if (direction < PipeDirection.In || direction >
PipeDirection.InOut)
474 if (direction < PipeDirection.In || direction >
PipeDirection.InOut)
478 if (transmissionMode < PipeTransmissionMode.Byte || transmissionMode >
PipeTransmissionMode.Message)
482 if (outBufferSize < 0)
486 Init(direction, transmissionMode, (uint)outBufferSize);
509 if (isAsync &&
handle !=
null)
521 Unsafe.SkipInit(out
byte result);
552 protected override void Dispose(
bool disposing)
564 base.Dispose(disposing);
688 return Task.FromResult(0);
831 internal static string GetPipePath(
string serverName,
string pipeName)
833 string fullPath =
Path.
GetFullPath(
"\\\\" + serverName +
"\\pipe\\" + pipeName);
834 if (
string.Equals(fullPath,
"\\\\.\\pipe\\anonymous",
StringComparison.OrdinalIgnoreCase))
843 if (global::Interop.Kernel32.GetFileType(safePipeHandle) != 3)
859 source._preallocatedOverlapped.Dispose();
881 int numBytesRead = 0;
889 switch (lastPInvokeError)
912 switch (lastPInvokeError)
921 readWriteValueTaskSource.
Dispose();
925 readWriteValueTaskSource.
Dispose();
934 readWriteValueTaskSource.
Dispose();
949 int numBytesWritten = 0;
966 if (lastPInvokeError != 997)
968 readWriteValueTaskSource.
Dispose();
976 readWriteValueTaskSource.
Dispose();
980 return new ValueTask(readWriteValueTaskSource, readWriteValueTaskSource.
Version);
983 [SupportedOSPlatform(
"windows")]
991 if (!global::Interop.Kernel32.FlushFileBuffers(
_handle))
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);
1007 global::Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs =
GetSecAttrs(inheritability);
1008 if (pipeSecurity !=
null)
1012 fixed (
byte* ptr = securityDescriptorBinaryForm)
1014 secAttrs.lpSecurityDescriptor = (
IntPtr)ptr;
1022 Unsafe.SkipInit(out uint num);
1023 if (!global::Interop.Kernel32.GetNamedPipeHandleStateW(
SafePipeHandle, &num,
null,
null,
null,
null, 0u))
1027 if ((num & 2u) != 0)
static Exception GetReadNotSupported()
static Exception GetWriteNotSupported()
static Exception GetEndOfFile()
static Exception GetOperationAborted()
static Exception GetSeekNotSupported()
static Exception GetPipeNotOpen()
static string GetFullPath(string path)
ConnectionValueTaskSource(NamedPipeServerStream server)
override void CompleteCore(uint errorCode, uint numBytes)
unsafe void PrepareForOperation(ReadOnlyMemory< byte > memory=default(ReadOnlyMemory< byte >))
static unsafe readonly IOCompletionCallback s_ioCallback
MemoryHandle _memoryHandle
CancellationTokenRegistration _cancellationRegistration
PipeValueTaskSource(PipeStream pipeStream)
void OnCompleted(Action< object > continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
readonly PipeStream _pipeStream
unsafe void RegisterForCancellation(CancellationToken cancellationToken)
void CompleteCore(uint errorCode, uint numBytes)
void FinishedScheduling()
readonly PreAllocatedOverlapped _preallocatedOverlapped
void Complete(uint errorCode, uint numBytes)
ManualResetValueTaskSourceCore< int > _source
int GetResult(short token)
unsafe NativeOverlapped * _overlapped
unsafe void ReleaseResources()
void IValueTaskSource. GetResult(short token)
ValueTaskSourceStatus GetStatus(short token)
static unsafe void IOCallback(uint errorCode, uint numBytes, NativeOverlapped *pOverlapped)
override void CompleteCore(uint errorCode, uint numBytes)
ReadWriteValueTaskSource(PipeStream stream, bool isWrite)
ThreadPoolBoundHandle _threadPoolBinding
void CheckWriteOperations()
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)
unsafe void UpdateReadMode()
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)
void CheckReadOperations()
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
bool _isFromExistingHandle
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)
static int MakeHRFromErrorCode(int errorCode)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static Exception SetCurrentStackTrace(Exception source)
static int GetLastPInvokeError()
void SetHandleAsInvalid()
static string InvalidOperation_PipeReadModeNotMessage
static string IO_InvalidPipeHandle
static string NotSupported_UnwritableStream
static string InvalidOperation_PipeHandleNotSet
static string NotSupported_UnreadableStream
static string ArgumentOutOfRange_TransmissionModeByteOrMsg
static string InvalidOperation_PipeNotYetConnected
static string ArgumentOutOfRange_AnonymousReserved
static string IO_PipeBroken
static string ArgumentOutOfRange_NeedNonNegNum
static string ArgumentOutOfRange_DirectionModeInOutOrInOut
static string InvalidOperation_PipeDisconnected
byte[] GetSecurityDescriptorBinaryForm()
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)
static void End(IAsyncResult asyncResult)
static Task FromException(Exception exception)
static Task FromCanceled(CancellationToken cancellationToken)
static Task CompletedTask
new TaskAwaiter< TResult > GetAwaiter()
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)
void GetResult(short token)
ValueTaskSourceOnCompletedFlags
unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)
static readonly IntPtr Zero
static GCHandle Alloc(object? value)
bool IsCancellationRequested
static CancellationToken None
void SetResult(TResult result)
ValueTaskSourceStatus GetStatus(short token)
TResult GetResult(short token)
void OnCompleted(Action< object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
void SetException(Exception error)
static ValueTask FromCanceled(CancellationToken cancellationToken)
static ValueTask FromException(Exception exception)