HavenDV / H.Pipes

A simple, easy to use, strongly-typed, async wrapper around .NET named pipes.
MIT License
219 stars 26 forks source link

Does this library support read-only or write-only? #39

Closed finnonly closed 4 months ago

finnonly commented 7 months ago

CreatePipeStreamFunc = (pipeName) => new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough);

When customizing a NamedPipeServerStream, the client connects and prompts that reading the stream is not supported.

HavenDV commented 7 months ago

Currently the main pipe for creating connections and the additional pipes for the connections themselves use the same method, so this is not possible for the main client (but will most likely work with SingleConnection versions of clients)

HavenDV commented 7 months ago

I added PipeServer.CreatePipeStreamForConnectionFunc in latest release now, please try to set up this for CreatePipeStreamForConnectionFunc and test

finnonly commented 7 months ago

PipeServer.CreatePipeStreamForConnectionFunc No effect

PipeConnection has a reading thread. If it is set to write only, ReadAsync will prompt that reading is not supported.

HavenDV commented 7 months ago

I created test for WriteOnly server case and disabled reading thread if PipeStream does not have Read capabilities. It should be released soon in 2.1.0.

finnonly commented 7 months ago

Looking forward to the release of the new version.😊

HavenDV commented 7 months ago

Unfortunately, I'm running macOS and it worked correctly, but the Windows tests failed with an exception and I'm trying to fix it:

   Test method H.Pipes.Tests.Tests.WriteOnlyServer threw exception: 
System.AggregateException: One or more errors occurred. (Access to the path is denied.) ---> System.UnauthorizedAccessException: Access to the path is denied.
  Stack Trace:
      at System.IO.Pipes.NamedPipeClientStream.TryConnect(Int32 timeout, CancellationToken cancellationToken)
   at System.IO.Pipes.NamedPipeClientStream.ConnectInternal(Int32 timeout, CancellationToken cancellationToken, Int32 startTime)
finnonly commented 7 months ago

Hi, have you found your problem? I tried to set PipeDirection.In on the server, but it was still PipeDirection.InOut on the client. I got the same error as you. PipeDirection.In and PipeDirection.Out need to be connected one-to-one so that there will be no

HavenDV commented 7 months ago

Unfortunately stuck with this. I will release a new prerelease version with the ability to set CreatePipeStreamForConnectionFunc for the client, you can help if you check different options

finnonly commented 7 months ago

I roughly looked at the PipeConnection code, and there is a start method. If the NamedPipeClientStream is in the write-only state, I think PipeConnection.ReadWorker does not need to be run.

HavenDV commented 7 months ago
image

I think this is already being processed, maybe I should move it outside of the ReadWorker, but I was afraid of breaking something

finnonly commented 4 months ago

After testing the 2.1.0-dev322 version, it seems that it can only read and write. Close this issue.