Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package org.apache.hc.core5.http2.impl.nio;

import javax.net.ssl.SSLSession;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
Expand All @@ -42,8 +43,6 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;

import javax.net.ssl.SSLSession;

import org.apache.hc.core5.concurrent.Cancellable;
import org.apache.hc.core5.concurrent.CancellableDependency;
import org.apache.hc.core5.http.ConnectionClosedException;
Expand Down Expand Up @@ -94,6 +93,7 @@
abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnection {

private static final long LINGER_TIME = 1000; // 1 second
private static final long CONNECTION_WINDOW_LOW_MARK = 10 * 1024 * 1024; // 10 MiB

enum ConnectionHandshake { READY, ACTIVE, GRACEFUL_SHUTDOWN, SHUTDOWN}
enum SettingsHandshake { READY, TRANSMITTED, ACKED }
Expand Down Expand Up @@ -125,11 +125,10 @@ enum SettingsHandshake { READY, TRANSMITTED, ACKED }

private int initInputWinSize;
private int initOutputWinSize;
private int lowMark;

private volatile H2Config remoteConfig;

private int lowMark;

private Continuation continuation;

private int processedRemoteStreamId;
Expand Down Expand Up @@ -419,6 +418,7 @@ public final void onConnect() throws HttpException, IOException {

commitFrame(settingsFrame);
localSettingState = SettingsHandshake.TRANSMITTED;
maximizeConnWindow(connInputWindow.get());

if (streamListener != null) {
final int initInputWindow = connInputWindow.get();
Expand Down Expand Up @@ -466,16 +466,6 @@ public final void onOutput() throws HttpException, IOException {
ioSession.getLock().unlock();
}

final int connWinSize = connInputWindow.get();
if (connWinSize < lowMark) {
final int delta = initInputWinSize - connWinSize;
if (delta > 0) {
final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(0, delta);
commitFrame(windowUpdateFrame);
updateInputWindow(0, connInputWindow, delta);
}
}

if (connState.compareTo(ConnectionHandshake.SHUTDOWN) < 0) {

if (connOutputWindow.get() > 0 && remoteSettingState == SettingsHandshake.ACKED) {
Expand Down Expand Up @@ -1000,13 +990,8 @@ private void consumeDataFrame(final RawFrame frame, final H2Stream stream) throw
stream.produceInputCapacityUpdate();
}
final int connWinSize = updateInputWindow(0, connInputWindow, -frameLength);
if (connWinSize < lowMark) {
final int chunk = Integer.MAX_VALUE - connWinSize;
if (chunk > 0) {
final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(0, chunk);
commitFrame(windowUpdateFrame);
updateInputWindow(0, connInputWindow, chunk);
}
if (connWinSize < CONNECTION_WINDOW_LOW_MARK) {
maximizeConnWindow(connWinSize);
}
}
if (stream.isRemoteClosed()) {
Expand All @@ -1021,6 +1006,15 @@ private void consumeDataFrame(final RawFrame frame, final H2Stream stream) throw
stream.consumeData(payload);
}

private void maximizeConnWindow(final int connWinSize) throws IOException {
final int delta = Integer.MAX_VALUE - connWinSize;
if (delta > 0) {
final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(0, delta);
commitFrame(windowUpdateFrame);
updateInputWindow(0, connInputWindow, delta);
}
}

private void consumePushPromiseFrame(final RawFrame frame, final ByteBuffer payload, final H2Stream promisedStream) throws HttpException, IOException {
final int promisedStreamId = promisedStream.getId();
if (!frame.isFlagSet(FrameFlag.END_HEADERS)) {
Expand Down Expand Up @@ -1203,7 +1197,6 @@ private void applyRemoteSettings(final H2Config config) throws H2ConnectionExcep
}
}
}
lowMark = initOutputWinSize / 2;
}

private void applyLocalSettings() throws H2ConnectionException {
Expand All @@ -1223,6 +1216,7 @@ private void applyLocalSettings() throws H2ConnectionException {
}
}
}
lowMark = initInputWinSize / 2;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void accept(final Emitter<ByteBuffer> emitter) {
final int bufferLength = (int) Math.min(remainingLength, 1 + random.nextInt(maximumBlockSize));
final byte[] bs = new byte[bufferLength];
for (int i = 0; i < bufferLength; i++) {
final byte b = RANGE[(int) (Math.random() * RANGE.length)];
final byte b = RANGE[(int) (random.nextDouble() * RANGE.length)];
bs[i] = b;
}
if (hash != null) {
Expand Down