System.IO.NamedPipeClientStream: When is 'IsAsync' supposed to be set when selecting PipeOptions.Asynchronous ?
I'm extending the unit test for System.IO.Pipes, and have discovered a potential hole in the documentation regarding async operations on named pipes.
If I create a NamedPipeServerStream with PipeOptions.Asynchronous optiion set, the resulting object has the IsAsync property set to true;
However If I create a NamePipeClientStream with PipeOptions.Asynchronous option set the resulting object has the IsAsync property set to false. It seems that the IsAsync flag is only set after doing a connect.
I guess the purpose of this post is to verify if this is expected behavior (and perhaps the documentation clarified). I suspect if it's not, then it still has to be the same otherwise it might break something.
I'm not 100% sure about this although since we are not connected I believe IsAsync might be irrelevant. I think that options are just a suggestion for what might actually do and we don't know that until we are connected.
cc: @ericstj @YingP99
Whats also a bit confusing for a user is that regardless whether you select the async pipe option or not, you then can use either synchronous operations (ie read, write) or async operations (ReadAsync, WriteAsync). Under the covers it appears to handle things differently for each combination (sync/async pipe vs sync/async operations resulting in 4 implementations). Since I'm creating unit tests, I probably need to test all these combinations.
The main distinction is wether or not the operations are async at the OS level. Async ops on a non async handle will block a background thread, async on async will not (using an IO completion port), and thus it scales beter. Sync always blocks a thread. Sync on sync is slightly more performant than sync on async since sync. It's very important to test both.
The IsAsync flag is an indication about what type of handle is exposed. The primary scenario is for communicating what type of handle that is, since if you try to consume the handle in other .Net/Win32 APIs you must use the appropriate pattern for sync/async or they will fail.
@bpschoch, You can use Theory to create different instances of PipeStreams.
Thanks, I didn't think of that
I believe this issue is now resolved, so I'm going to close it. Feel free to re-open with additional details if it should remain open.