@Override
  public void write(final ByteBufferList list) {
    if (mServer.getAffinity() != Thread.currentThread()) {
      mServer.run(
          new Runnable() {
            @Override
            public void run() {
              write(list);
            }
          });
      return;
    }
    if (!mChannel.isConnected()) {
      assert !mChannel.isChunked();
      return;
    }

    try {
      int before = list.remaining();
      ByteBuffer[] arr = list.getAllArray();
      mChannel.write(arr);
      list.addAll(arr);
      handleRemaining(list.remaining());
      mServer.onDataSent(before - list.remaining());
    } catch (IOException e) {
      closeInternal();
      reportEndPending(e);
      reportClose(e);
    }
  }
 @Override
 public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
   if (bb != null) totalRead += bb.remaining();
   Util.emitAllData(this, bb);
   if (bb != null) totalRead -= bb.remaining();
   if (tracker != null && bb != null) tracker.onData(totalRead);
   // if there's data after the emitting, and it is paused... the underlying implementation
   // is obligated to cache the byte buffer list.
 }
예제 #3
0
  @Override
  public void write(ByteBufferList bb) {
    if (mPendingWrites == null) mDataSink.write(bb);
    //        else
    //            Assert.assertTrue(mPendingWrites.remaining() <= mMaxBuffer);

    if (bb.remaining() > 0) {
      int toRead = Math.min(bb.remaining(), mMaxBuffer);
      if (toRead > 0) {
        if (mPendingWrites == null) mPendingWrites = new ByteBufferList();
        mPendingWrites.add(bb.get(toRead));
      }
    }
  }
예제 #4
0
 @Override
 public void run() {
   try {
     if (channel == null) channel = new FileInputStream(file).getChannel();
     if (!pending.isEmpty()) {
       Util.emitAllData(FileDataEmitter.this, pending);
       if (!pending.isEmpty()) return;
     }
     ByteBuffer b;
     do {
       b = ByteBufferList.obtain(8192);
       if (-1 == channel.read(b)) {
         report(null);
         return;
       }
       b.flip();
       pending.add(b);
       Util.emitAllData(FileDataEmitter.this, pending);
     } while (pending.remaining() == 0 && !isPaused());
   } catch (Exception e) {
     report(e);
   }
 }
예제 #5
0
 public int remaining() {
   if (mPendingWrites == null) return 0;
   return mPendingWrites.remaining();
 }