@Override protected final boolean isReady() { return responseMsgPos == -1 && socketWrapper.isReadyForWrite(); }
@Override protected void resumeProcessing() { socketWrapper.processSocket(SocketEvent.OPEN_READ, true); }
protected void processWrites() throws IOException { synchronized (socketWrapper) { if (socketWrapper.flush(false)) { socketWrapper.registerWriteInterest(); } } }
public UpgradeProcessorInternal(SocketWrapperBase<?> wrapper, UpgradeToken upgradeToken) { super(upgradeToken); this.internalHttpUpgradeHandler = (InternalHttpUpgradeHandler) upgradeToken.getHttpUpgradeHandler(); /* * Leave timeouts in the hands of the upgraded protocol. */ wrapper.setReadTimeout(INFINITE_TIMEOUT); wrapper.setWriteTimeout(INFINITE_TIMEOUT); internalHttpUpgradeHandler.setSocketWrapper(wrapper); }
@Override protected void doWrite(SendHandler handler, long blockingWriteTimeoutExpiry, ByteBuffer... buffers) { if (socketWrapper.hasAsyncIO()) { final boolean block = (blockingWriteTimeoutExpiry != -1); long timeout = -1; socketWrapper.write(block ? BlockingMode.BLOCK : BlockingMode.SEMI_BLOCK, timeout, TimeUnit.MILLISECONDS, null, SocketWrapperBase.COMPLETE_WRITE_WITH_COMPLETION, new CompletionHandler<Long, Void>() { return; socketWrapper.setWriteTimeout(timeout); socketWrapper.write(true, buffer); return; socketWrapper.setWriteTimeout(timeout); socketWrapper.flush(true); handler.onResult(SENDRESULT_OK); } catch (IOException e) {
socketWrapper.flush(false); while (socketWrapper.isReadyForWrite()) { complete = true; for (ByteBuffer buffer : buffers) { if (buffer.hasRemaining()) { complete = false; socketWrapper.write(false, buffer); break; socketWrapper.flush(false); complete = socketWrapper.isReadyForWrite(); if (complete) { wsWriteTimeout.unregister(this);
return; socketWrapper.setWriteTimeout(timeout); socketWrapper.write(true, buffer); return; socketWrapper.setWriteTimeout(timeout); socketWrapper.flush(true); handler.onResult(SENDRESULT_OK); } catch (IOException e) {
/** * Scatter read. The completion handler will be called once some * data has been read or an error occurred. If a CompletionCheck * object has been provided, the completion handler will only be * called if the callHandler method returned true. If no * CompletionCheck object has been provided, the default NIO2 * behavior is used: the completion handler will be called as soon * as some data has been read, even if the read has completed inline. * * @param block is the blocking mode that will be used for this operation * @param timeout timeout duration for the read * @param unit units for the timeout duration * @param attachment an object to attach to the I/O operation that will be * used when calling the completion handler * @param check for the IO operation completion * @param handler to call when the IO is complete * @param dsts buffers * @param <A> The attachment type * @return the completion state (done, done inline, or still pending) */ public final <A> CompletionState read(BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) { if (dsts == null) { throw new IllegalArgumentException(); } return read(dsts, 0, dsts.length, block, timeout, unit, attachment, check, handler); }
socketWrapper.setReadTimeout(protocol.getConnectionTimeout()); socketWrapper.write(true, pongMessageArray, 0, pongMessageArray.length); socketWrapper.flush(true); } catch (IOException e) { setErrorState(ErrorState.CLOSE_CONNECTION_NOW, e); socketWrapper.setReadTimeout(protocol.getKeepAliveTimeout());
@Override protected void doClose() { if (handler != null) { // close() can be triggered by a wide range of scenarios. It is far simpler just to always use a dispatch than it is to try and track // whether or not this method was called by the same thread that triggered the write clearHandler(new EOFException(), true); } try { socketWrapper.close(); } catch (IOException e) { if (log.isDebugEnabled()) { log.warn(sm.getString("wsRemoteEndpointServer.closeFailed"), e); } } wsWriteTimeout.unregister(this); }
/** * Writes any remaining buffered data. * * @param block Should this method block until the buffer is empty * @return <code>true</code> if data remains in the buffer (which can only * happen in non-blocking mode) else <code>false</code>. * @throws IOException Error writing data */ protected boolean flushBuffer(boolean block) throws IOException { return socketWrapper.flush(block); }
@Override protected boolean readFrame(boolean block, FrameType expected) throws IOException, Http2Exception { if (block) { // Only used when reading the connection preface return super.readFrame(block, expected); } handleAsyncException(); header.clear(); framePaylod.clear(); FrameCompletionHandler handler = new FrameCompletionHandler(expected, header, framePaylod); CompletionState state = socketWrapper.read(BlockingMode.NON_BLOCK, socketWrapper.getWriteTimeout(), TimeUnit.MILLISECONDS, null, handler, handler, header, framePaylod); if (state == CompletionState.ERROR || state == CompletionState.INLINE) { handleAsyncException(); return true; } else { return false; } }
/** * Provides a mechanism to trigger processing on a container thread. * * @param runnable The task representing the processing that needs to take * place on a container thread */ protected void execute(Runnable runnable) { SocketWrapperBase<?> socketWrapper = this.socketWrapper; if (socketWrapper == null) { throw new RejectedExecutionException(sm.getString("abstractProcessor.noExecute")); } else { socketWrapper.execute(runnable); } }
@Override public InternalHttpUpgradeHandler getInternalUpgradeHandler(SocketWrapperBase<?> socketWrapper, Adapter adapter, Request coyoteRequest) { return socketWrapper.hasAsyncIO() ? new Http2AsyncUpgradeHandler(this, adapter, coyoteRequest) : new Http2UpgradeHandler(this, adapter, coyoteRequest); }
socket.socketWrapper.getEndpoint().countDownConnection(); ((NioSocketWrapper) socket.socketWrapper).closed = true; } else {
@Override protected void doWrite(SendHandler handler, long blockingWriteTimeoutExpiry, ByteBuffer... buffers) { if (socketWrapper.hasAsyncIO()) { final boolean block = (blockingWriteTimeoutExpiry != -1); long timeout = -1; socketWrapper.write(block ? BlockingMode.BLOCK : BlockingMode.SEMI_BLOCK, timeout, TimeUnit.MILLISECONDS, null, SocketWrapperBase.COMPLETE_WRITE_WITH_COMPLETION, new CompletionHandler<Long, Void>() { return; socketWrapper.setWriteTimeout(timeout); socketWrapper.write(true, buffer); return; socketWrapper.setWriteTimeout(timeout); socketWrapper.flush(true); handler.onResult(SENDRESULT_OK); } catch (IOException e) {
socketWrapper.flush(false); while (socketWrapper.isReadyForWrite()) { complete = true; for (ByteBuffer buffer : buffers) { if (buffer.hasRemaining()) { complete = false; socketWrapper.write(false, buffer); break; socketWrapper.flush(false); complete = socketWrapper.isReadyForWrite(); if (complete) { wsWriteTimeout.unregister(this);
/** * Gather write. The completion handler will be called once some * data has been written or an error occurred. If a CompletionCheck * object has been provided, the completion handler will only be * called if the callHandler method returned true. If no * CompletionCheck object has been provided, the default NIO2 * behavior is used: the completion handler will be called, even * if the write is incomplete and data remains in the buffers, or * if the write completed inline. * * @param block is the blocking mode that will be used for this operation * @param timeout timeout duration for the write * @param unit units for the timeout duration * @param attachment an object to attach to the I/O operation that will be * used when calling the completion handler * @param check for the IO operation completion * @param handler to call when the IO is complete * @param srcs buffers * @param <A> The attachment type * @return the completion state (done, done inline, or still pending) */ public final <A> CompletionState write(BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) { if (srcs == null) { throw new IllegalArgumentException(); } return write(srcs, 0, srcs.length, block, timeout, unit, attachment, check, handler); }