You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After some experimentation, it seems to me that unlike NamedPipeClientStream, AnonymousPipeClientStream (or AnonymousPipeServerStream for that matter) does not support cancellation (because there's no way to open the pipe in async mode and so Stream.ReadAsync is used instead of PipeStream.ReadAsyncCore). This is a little painful because it means there's no way to "unblock" a pending read or write on that stream when the stream contains no data.
Here's a simple repro that shows what I'm trying to do. It works for named pipes, but not for anonymous ones:
NamedPipeServerStreamsource=newNamedPipeServerStream("pipe-test",PipeDirection.Out,1,PipeTransmissionMode.Byte,PipeOptions.Asynchronous);NamedPipeClientStreamdestination=newNamedPipeClientStream(".","pipe-test",PipeDirection.In,PipeOptions.Asynchronous);awaitdestination.ConnectAsync();CancellationTokenSourcecancellationSource=newCancellationTokenSource();byte[]buffer=newbyte[10];Task<int>readTask=destination.ReadAsync(buffer,0,buffer.Length,cancellationSource.Token);// Right now, readTask is blocked waiting for data.Tasktimeout=Task.Delay(TimeSpan.FromSeconds(1));Taskwinner=awaitTask.WhenAny(readTask,timeout);Assert.Equal(timeout,winner);cancellationSource.Cancel();// readTask will now fault with TaskCanceledExceptiontimeout=Task.Delay(TimeSpan.FromSeconds(5));winner=awaitTask.WhenAny(readTask,timeout);Assert.Equal(readTask,winner);// Prove that it was canceled via the correct CancellationTokenTaskCanceledExceptioncancelled=awaitAssert.ThrowsAsync<TaskCanceledException>(()=>readTask);Assert.Equal(cancellationSource.Token,cancelled.CancellationToken);
Is this by design, or simply something nobody has gotten around to, yet? Because it looks like it should be possible to implement by constructing the base PipeStream with isAsync: true to use the correct code-path.
The text was updated successfully, but these errors were encountered:
@tintoy this is a limitation of anonymous pipes in Windows:
Asynchronous (overlapped) read and write operations are not supported by anonymous pipes. This means that you cannot use the ReadFileEx and WriteFileEx functions with anonymous pipes. In addition, the lpOverlapped parameter of ReadFile and WriteFile is ignored when these functions are used with anonymous pipes.
Hi.
After some experimentation, it seems to me that unlike
NamedPipeClientStream
,AnonymousPipeClientStream
(orAnonymousPipeServerStream
for that matter) does not support cancellation (because there's no way to open the pipe in async mode and soStream.ReadAsync
is used instead ofPipeStream.ReadAsyncCore
). This is a little painful because it means there's no way to "unblock" a pending read or write on that stream when the stream contains no data.Here's a simple repro that shows what I'm trying to do. It works for named pipes, but not for anonymous ones:
Is this by design, or simply something nobody has gotten around to, yet? Because it looks like it should be possible to implement by constructing the base
PipeStream
withisAsync: true
to use the correct code-path.The text was updated successfully, but these errors were encountered: