/** * Transfers the data to the socket write buffer (writing that data to the * socket if the buffer fills up using a non-blocking write) until either * all the data has been transferred and space remains in the socket write * buffer or a non-blocking write leaves data in the socket write buffer. * After an incomplete write, any data remaining to be transferred to the * socket write buffer will be copied to the socket write buffer. If the * remaining data is too big for the socket write buffer, the socket write * buffer will be filled and the additional data written to the non-blocking * write buffer. * * @param from The ByteBuffer containing the data to be written * * @throws IOException If an IO error occurs during the write */ protected void writeNonBlocking(ByteBuffer from) throws IOException { if (nonBlockingWriteBuffer.isEmpty() && socketBufferHandler.isWriteBufferWritable()) { writeNonBlockingInternal(from); } if (from.remaining() > 0) { // Remaining data must be buffered nonBlockingWriteBuffer.add(from); } }
private class VectoredIOCompletionHandler<A> implements CompletionHandler<Long, OperationState<A>> { @Override public void completed(Long nBytes, OperationState<A> state) { if (nBytes.longValue() < 0) { failed(new EOFException(), state); } else { state.nBytes += nBytes.longValue(); CompletionState currentState = Nio2Endpoint.isInline() ? CompletionState.INLINE : CompletionState.DONE; boolean complete = true; boolean completion = true; if (state.check != null) { switch (state.check.callHandler(currentState, state.buffers, state.offset, state.length)) { case CONTINUE: complete = false; break; case DONE: break; case NONE: completion = false; break; } } if (complete) { boolean notify = false; state.semaphore.release(); if (state.block == BlockingMode.BLOCK && currentState != CompletionState.INLINE) { notify = true; } else { state.state = currentState; }
nonBlockingWriteBuffer.add(buf, off, len);