private IRubyObject shutdownInternal(ThreadContext context, int how) { Channel socketChannel; switch (how) { case 0: socketChannel = openFile.getMainStream().getDescriptor().getChannel(); try { if (socketChannel instanceof SocketChannel || socketChannel instanceof DatagramChannel) { asSocket().shutdownInput(); } else if (socketChannel instanceof Shutdownable) { ((Shutdownable) socketChannel).shutdownInput(); } } catch (IOException e) { throw context.getRuntime().newIOError(e.getMessage()); } if (openFile.getPipeStream() != null) { openFile.setMainStream(openFile.getPipeStream()); openFile.setPipeStream(null); } openFile.setMode(openFile.getMode() & ~OpenFile.READABLE); return RubyFixnum.zero(context.getRuntime()); case 1: socketChannel = openFile.getMainStream().getDescriptor().getChannel(); try { if (socketChannel instanceof SocketChannel || socketChannel instanceof DatagramChannel) { asSocket().shutdownOutput(); } else if (socketChannel instanceof Shutdownable) { ((Shutdownable) socketChannel).shutdownOutput(); } } catch (IOException e) { throw context.getRuntime().newIOError(e.getMessage()); } openFile.setPipeStream(null); openFile.setMode(openFile.getMode() & ~OpenFile.WRITABLE); return RubyFixnum.zero(context.getRuntime()); case 2: shutdownInternal(context, 0); shutdownInternal(context, 1); return RubyFixnum.zero(context.getRuntime()); default: throw context.getRuntime().newArgumentError("`how' should be either 0, 1, 2"); } }