private void setSettings(Settings settings) { // TODO: For HTTP/2.0, also adjust the stream flow control window size // by the difference between the new value and the old value. assert (Thread.holdsLock(connection)); // Because 'settings' is guarded by 'connection'. this.writeWindowSize = settings != null ? settings.getInitialWindowSize(Settings.DEFAULT_INITIAL_WINDOW_SIZE) : Settings.DEFAULT_INITIAL_WINDOW_SIZE; }
private SpdyConnection(Builder builder) { protocol = builder.protocol; pushObserver = builder.pushObserver; client = builder.client; handler = builder.handler; nextStreamId = builder.client ? 1 : 2; nextPingId = builder.client ? 1 : 2; // Flow control was designed more for servers, or proxies than edge clients. // If we are a client, set the flow control window to 16MiB. This avoids // thrashing window updates every 64KiB, yet small enough to avoid blowing // up the heap. if (builder.client) { okHttpSettings.set(Settings.INITIAL_WINDOW_SIZE, 0, 16 * 1024 * 1024); } hostName = builder.hostName; Variant variant; if (protocol == Protocol.HTTP_2) { variant = new Http20Draft09(); } else if (protocol == Protocol.SPDY_3) { variant = new Spdy3(); } else { throw new AssertionError(protocol); } bytesLeftInWriteWindow = peerSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE); frameReader = variant.newReader(builder.source, client); frameWriter = variant.newWriter(builder.sink, client); maxFrameSize = variant.maxFrameSize(); readerRunnable = new Reader(); new Thread(readerRunnable).start(); // Not a daemon thread. }