java.nio.channels.Pipe triva questions for you:
Q:What happens when you close the sink of a pipe?
For all those that answered “The source returns
-1 on read indicating an end-of-stream”, you get a gold star! Now on to a toughie.
Q:What happens when you close the source of a pipe?
Belt it out! “Writing to the sink will throw
java.io.IOException.” Well, you’re half right. And what does half right mean? Yup. You’re half wrong. The correct answer is “It depends on the platform.”
- Linux: any write will cause
.java.io.IOException: Broken pipeto be thrown.
- Windows: any number of writes can be performed before
java.io.IOException: An established connection was aborted by the software in your host machineis receveied (WinSock error 10053).
- Other: as of yet untested
The concern is the windows case where a write (or multiple writes) can be performed successfully.
Why isn’t there a
Pipe itself? And why doesn’t closing either the sink or the source automatically and synchronously close the other? I just don’t know. Part of Sun’s grand scheme to render its developers into blubbering masses of goo? That’s just anger talking again. I’ll just chalk it up to lack of foresight that has caused such things as the SSL + NIO problem.
Expect to see a defect report / RFE in the bug parade on this topic.
A big hearty thanks goes out to Igor for doing the Linux testing!
Link-back to main entry: NIO and SSL.