Пример #1
0
 protected void shutdownIO(final boolean read) {
   if (!isConnected()) {
     throw new NotYetConnectedException();
   }
   final SocketChannel channel = (SocketChannel) key.channel();
   try {
     final Method method =
         channel.getClass().getDeclaredMethod(read ? "shutdownInput" : "shutdownOutput");
     method.setAccessible(true);
     method.invoke(channel);
     return;
   } catch (NoSuchMethodException e) {
     logger.warn("{}", this, e);
   } catch (IllegalAccessException e) {
     logger.warn("{}", this, e);
   } catch (InvocationTargetException e) {
     logger.warn("{}", this, e);
   }
   final Socket socket = channel.socket();
   try {
     if (read) {
       socket.shutdownInput();
     } else {
       socket.shutdownOutput();
     }
   } catch (IOException e) {
     logger.warn("{}", this, e);
   }
 }
  protected void closeSocketChannel(SocketChannel socketChannel, FileDescriptor fileDescriptor)
      throws Exception {

    Field fileDescriptorField = ReflectionUtil.getDeclaredField(socketChannel.getClass(), "fd");

    fileDescriptorField.set(socketChannel, fileDescriptor);

    socketChannel.close();
  }