runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.IO.NamedPipeClientStream: When is 'IsAsync' supposed to be set when selecting PipeOptions.Asynchronous ?

Open bpschoch opened this issue 11 years ago • 6 comments

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.

bpschoch avatar Apr 24 '15 02:04 bpschoch

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

krwq avatar Apr 24 '15 16:04 krwq

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.

bpschoch avatar Apr 24 '15 17:04 bpschoch

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.

ericstj avatar Apr 24 '15 19:04 ericstj

@bpschoch, You can use Theory to create different instances of PipeStreams.

krwq avatar Apr 25 '15 02:04 krwq

Thanks, I didn't think of that

bpschoch avatar Apr 25 '15 18:04 bpschoch

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.

stephentoub avatar Jun 08 '15 18:06 stephentoub