@Override protected void flushBlocking() throws IOException { checkError(); // Before doing a blocking flush, make sure that any pending non // blocking write has completed. try { if (writePending.tryAcquire(toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS)) { writePending.release(); } else { throw new SocketTimeoutException(); } } catch (InterruptedException e) { // Ignore } super.flushBlocking(); }
getSocket().read(to, toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, this, readCompletionHandler); Nio2Endpoint.endInline();
toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, array, gatheringWriteCompletionHandler); nestedWriteCompletionCount.get().decrementAndGet(); getSocket().write(attachment, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, attachment, writeCompletionHandler); nestedWriteCompletionCount.get().decrementAndGet();
@Override public void completed(Long nBytes, ByteBuffer[] attachment) { writeNotify = false; synchronized (writeCompletionHandler) { if (nBytes.longValue() < 0) { failed(new EOFException(sm.getString("iob.failedwrite")), attachment); } else if (!nonBlockingWriteBuffer.isEmpty() || arrayHasData(attachment)) { // Continue writing data using a gathering write nestedWriteCompletionCount.get().incrementAndGet(); ByteBuffer[] array = nonBlockingWriteBuffer.toArray(attachment); getSocket().write(array, 0, array.length, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, array, gatheringWriteCompletionHandler); nestedWriteCompletionCount.get().decrementAndGet(); } else { // All data has been written if (writeInterest) { writeInterest = false; writeNotify = true; } writePending.release(); } } if (writeNotify && nestedWriteCompletionCount.get().get() == 0) { endpoint.processSocket(Nio2SocketWrapper.this, SocketEvent.OPEN_WRITE, Nio2Endpoint.isInline()); } }
getSocket().getBufHandler().configureWriteBufferForRead(); Nio2Endpoint.startInline(); getSocket().write(buffer, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, data, sendfileHandler); Nio2Endpoint.endInline();
public void awaitBytes() { // NO-OP is there is already a read in progress. if (readPending.tryAcquire()) { getSocket().getBufHandler().configureReadBufferForWrite(); Nio2Endpoint.startInline(); getSocket().read(getSocket().getBufHandler().getReadBuffer(), toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, this, awaitBytesHandler); Nio2Endpoint.endInline(); } }
sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(endpoint.getConnectionTimeout()), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); return 1; sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(endpoint.getConnectionTimeout()), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); return 1; break; case NEED_READ: sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(endpoint.getConnectionTimeout()), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); return 1;
} else { if (async) { sc.write(netOutBuffer, Nio2Endpoint.toNio2Timeout(timeout), TimeUnit.MILLISECONDS, socket, handshakeWriteCompletionHandler); } else { sc.write(netOutBuffer, Nio2Endpoint.toNio2Timeout(timeout), TimeUnit.MILLISECONDS, socket, handshakeWriteCompletionHandler); } else { sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(timeout), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); } else {
timeout = toNio2Timeout(getWriteTimeout());
getSocket().write(buffer, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, attachment, this);
private boolean flushNonBlocking(boolean hasPermit) throws IOException { checkError(); synchronized (writeCompletionHandler) { if (hasPermit || writePending.tryAcquire()) { socketBufferHandler.configureWriteBufferForRead(); if (!nonBlockingWriteBuffer.isEmpty()) { ByteBuffer[] array = nonBlockingWriteBuffer.toArray(socketBufferHandler.getWriteBuffer()); Nio2Endpoint.startInline(); getSocket().write(array, 0, array.length, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, array, gatheringWriteCompletionHandler); Nio2Endpoint.endInline(); } else if (socketBufferHandler.getWriteBuffer().hasRemaining()) { // Regular write Nio2Endpoint.startInline(); getSocket().write(socketBufferHandler.getWriteBuffer(), toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, socketBufferHandler.getWriteBuffer(), writeCompletionHandler); Nio2Endpoint.endInline(); } else { // Nothing was written if (!hasPermit) { writePending.release(); } } } return hasDataToWrite(); } }
timeout = toNio2Timeout(getReadTimeout());