public boolean flush() throws IOException { int oldVal, newVal; oldVal = state; if (allAreSet(oldVal, FLAG_CLOSE_COMP)) { return true; } final boolean flushed = delegate.flush(); if (! flushed) { return false; } do { if (allAreClear(oldVal, FLAG_CLOSE_REQ)) { return true; } newVal = oldVal | FLAG_CLOSE_COMP; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); invokeChannelListener(this, closeListener); return true; }
public int write(final ByteBuffer src) throws IOException { if (anyAreSet(state, FLAG_CLOSE_COMPLETE)) { throw new ClosedChannelException(); } int remaining = src.remaining(); src.position(src.position() + remaining); return remaining; }
@Override public void handleEvent(final StreamSourceChannel channel) { if (anyAreClear(state, FLAG_RESPONSE_TERMINATED)) { closeAndFlushResponse(); } } }, new ChannelExceptionHandler<StreamSourceChannel>() {
public void suspendWrites() { int oldVal, newVal; do { oldVal = state; if (allAreClear(oldVal, FLAG_RESUMED) || allAreSet(oldVal, FLAG_CLOSED)) { return; } newVal = oldVal & ~FLAG_RESUMED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); }
void beginHandshake() throws IOException { final int state = this.state; if (anyAreSet(state, READ_FLAG_EOF | WRITE_FLAG_SHUTDOWN)) { throw new ClosedChannelException(); } if (allAreClear(state, FLAG_TLS)) { this.state = state | FLAG_TLS; } engine.beginHandshake(); }
@Override public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException { if (anyAreSet(state, FLAG_WRITES_SHUTDOWN)) { throw new ClosedChannelException(); } return IoUtils.transfer(source, count, throughBuffer, new ConduitWritableByteChannel(this)); }
@Override public void run() { try { ChannelListener<? super S> listener = getWriteListener(); if (listener == null || !isWriteResumed()) { return; } if (loopCount++ == 100) { //should never happen UndertowLogger.ROOT_LOGGER.listenerNotProgressing(); IoUtils.safeClose(AbstractFramedStreamSinkChannel.this); return; } ChannelListeners.invokeChannelListener((S) AbstractFramedStreamSinkChannel.this, listener); } finally { inListenerLoopUpdater.set(AbstractFramedStreamSinkChannel.this, 0); } //if writes are shutdown or we become active then we stop looping //we stop when writes are shutdown because we can't flush until we are active //although we may be flushed as part of a batch if (writesResumed && allAreClear(state, STATE_CLOSED) && !broken && !readyForFlush && !fullyFlushed) { if (inListenerLoopUpdater.compareAndSet(AbstractFramedStreamSinkChannel.this, 0, 1)) { getIoThread().execute(this); } } } });
oldState = stateUpdater.get(this); if (allAreSet(oldState, WRITE_COMPLETE)) { return channel.flush(); final boolean shutDown = allAreSet(oldState, WRITE_SHUT_DOWN); if (! flushAction(shutDown)) { return false; while (! stateUpdater.compareAndSet(this, oldState, newState)) { oldState = stateUpdater.get(this); if (allAreSet(oldState, WRITE_COMPLETE)) { return channel.flush(); final boolean readShutDown = allAreSet(oldState, READ_SHUT_DOWN); try { shutdownWritesComplete(readShutDown); } finally { if (readShutDown) ChannelListeners.invokeChannelListener(thisTyped(), closeListener);
private void emptied() { int oldVal, newVal; do { oldVal = state; if (allAreSet(oldVal, EMPTIED)) { return; } newVal = oldVal | EMPTIED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); }
public long write(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { if (allAreSet(state, WRITE_FLAG_SHUTDOWN)) { throw new ClosedChannelException(); } if (allAreClear(state, FLAG_TLS)) { return sinkConduit.write(srcs, offs, len); } else { final long r1 = Buffers.remaining(srcs, offs, len); performIO(IO_GOAL_WRITE, srcs, offs, len, NO_BUFFERS, 0, 0); return (r1 - Buffers.remaining(srcs, offs, len)); } }
public void shutdownReads() throws IOException { int oldVal, newVal; do { oldVal = state; if (allAreSet(oldVal, FLAG_CLOSED)) { return; } newVal = oldVal | FLAG_CLOSED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); delegate.shutdownReads(); invokeChannelListener(this, closeListener); }
public void shutdownWrites() throws IOException { int oldVal, newVal; do { oldVal = state; if (allAreSet(oldVal, FLAG_CLOSED)) { return; } newVal = oldVal | FLAG_CLOSED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); writeListener = null; ChannelListeners.invokeChannelListener(this, closeListener); }
public void resumeWrites() { int oldVal, newVal; do { oldVal = state; if (anyAreSet(oldVal, FLAG_RESUMED | FLAG_CLOSED)) { return; } newVal = oldVal | FLAG_RESUMED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); thread.execute(ChannelListeners.getChannelListenerTask(this, writeListener)); }
public void shutdownWrites() throws IOException { int oldVal, newVal; do { oldVal = state; if (allAreSet(oldVal, FLAG_CLOSE_REQ)) { return; } newVal = oldVal | FLAG_CLOSE_REQ; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); delegate.shutdownWrites(); }
public void suspendReads() { int oldVal, newVal; do { oldVal = state; if (allAreClear(oldVal, RESUMED)) { return; } newVal = oldVal & ~RESUMED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); }
public void wakeupReads() { int oldVal, newVal; do { oldVal = state; if (anyAreSet(oldVal, CLOSED)) { return; } newVal = RESUMED; } while (! stateUpdater.compareAndSet(this, oldVal, newVal)); thread.execute(readRunnable); }
invokeExchangeCompleteListeners(); return; if (isResponseChannelAvailable()) { if(!getRequestMethod().equals(Methods.CONNECT) && !(getRequestMethod().equals(Methods.HEAD) && getResponseHeaders().contains(Headers.CONTENT_LENGTH)) && Connectors.isEntityBodyAllowed(this)) { getResponseHeaders().put(Headers.CONTENT_LENGTH, "0"); responseChannel.getWriteSetter().set(ChannelListeners.flushingChannelListener( new ChannelListener<StreamSinkChannel>() { @Override } else { if (anyAreClear(state, FLAG_RESPONSE_TERMINATED)) { UndertowLogger.ROOT_LOGGER.responseWasNotTerminated(connection, this); IoUtils.safeClose(connection); invokeExchangeCompleteListeners(); IoUtils.safeClose(connection);
@Override public void awaitReadable() throws IOException { try { if (anyAreSet(state, STATE_READING)) { next.awaitReadable(); } } catch (IOException | RuntimeException e) { IoUtils.safeClose(exchange.getConnection()); throw e; } }
public void shutdownReads() throws IOException { final int oldVal = stateUpdater.getAndSet(this, EMPTIED | CLOSED); if (allAreClear(oldVal, CLOSED)) { thread.execute(ChannelListeners.getChannelListenerTask(this, closeListener)); } }