Pipe selector problems

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!

Update

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.

Update II

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.

Closing thoughts

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.

Advertisements

One comment

  1. It definitely sounds like this is edge-driven polling, not level-driven polling. Read Linux’s man page for epoll and I bet the behavior you see will then make sense.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s