Beispiel #1
0
    private void processReads(Context cx) {
      if (!readStarted) {
        return;
      }
      int read;
      do {
        try {
          read = clientChannel.read(readBuffer);
        } catch (IOException ioe) {
          if (log.isDebugEnabled()) {
            log.debug("Error reading from channel: {}", ioe, ioe);
          }
          read = -1;
        }
        if (log.isDebugEnabled()) {
          log.debug("Read {} bytes from {} into {}", read, clientChannel, readBuffer);
        }
        if (read > 0) {
          readBuffer.flip();
          Buffer.BufferImpl buf = Buffer.BufferImpl.newBuffer(cx, this, readBuffer, true);
          readBuffer.clear();

          if (onRead != null) {
            onRead.call(cx, onRead, this, new Object[] {buf, 0, read});
          }
        } else if (read < 0) {
          setErrno(Constants.EOF);
          removeInterest(SelectionKey.OP_READ);
          if (onRead != null) {
            onRead.call(cx, onRead, this, new Object[] {null, 0, 0});
          }
        }
      } while (readStarted && (read > 0));
    }