As if the previous
java.nio.channels.Pipe inconsistencies weren’t enough, on both Linux and Windows it appears that you have to drain a pipe’s source before you can write to the sink again. Again, this is a case that falls under the system-dependentness mentioned in
Pipe‘s javadoc. Poopy I say!
After I determined that the write selector was lying to me on Linux, and after pouring over Stevens’ Advanced Programming in the UNIX Environment to refresh my memory on
pipe() (which Linux uses), it turns out that the pipe does not require drain-then-fill. Again, the write selector is lying (which appears to be a known “issue” with Linux’s
select() on a
pipe()). Windows remains drain-then-fill.
It seems that the results of drain-then-fill are dependent on how the sink is filled. If the sink is filled one
byte at a time, then neither Linux nor Windows is drain-then-fill but Linux will still have an inaccurate write selector. If the sink is filled in 8k chunks, then Windows will exhibit a drain-then-fill requirement; Linux is never drain-then-fill.
Given that Linux’s write selector is not accurate and always returns “none available” when there is data in the pipe (but will always return “go ahead” when the pipe is empty), it is nearly impossible to generically replace a file or network channel with a
Pipe.SinkChannel. Rob angry good!
Link-back to main entry: NIO and SSL.