예제 #1
0
  public ByteList doReceiveNonblock(ThreadContext context, int length) {
    Ruby runtime = context.runtime;
    Channel channel = getChannel();

    if (!(channel instanceof SelectableChannel)) {
      if (runtime.is1_9()) {
        throw runtime.newErrnoEAGAINReadableError(
            channel.getClass().getName() + " does not support nonblocking");
      } else {
        throw runtime.newErrnoEAGAINError(
            channel.getClass().getName() + " does not support nonblocking");
      }
    }

    SelectableChannel selectable = (SelectableChannel) channel;

    synchronized (selectable.blockingLock()) {
      boolean oldBlocking = selectable.isBlocking();

      try {
        selectable.configureBlocking(false);

        try {
          return doReceive(context, length);
        } finally {
          selectable.configureBlocking(oldBlocking);
        }

      } catch (IOException e) {
        throw runtime.newIOErrorFromException(e);
      }
    }
  }
예제 #2
0
파일: IoUtil.java 프로젝트: jCoderZ/fawkez
 /**
  * Closes the channel (safe).
  *
  * <p>This method tries to close the given channel and if an IOException occurs a message with the
  * level {@link Level#FINE} is logged. It's safe to pass a <code>null</code> reference for the
  * argument.
  *
  * @param channel the channel that should be closed.
  */
 public static void close(Channel channel) {
   if (channel != null) {
     try {
       channel.close();
     } catch (IOException x) {
       logCloseFailedWarningMessage(Channel.class, channel.getClass(), x);
     }
   }
 }