SPDY: allow MAX_CONCURRENT_STREAMS to be set to 0

This commit is contained in:
Mike Schore 2013-08-23 13:28:15 -07:00 committed by Norman Maurer
parent 7aefd0cbdb
commit 005d33a761
2 changed files with 23 additions and 28 deletions

View File

@ -41,12 +41,13 @@ public class SpdySessionHandler
private final SpdySession spdySession = new SpdySession();
private int lastGoodStreamId;
private int remoteConcurrentStreams;
private int localConcurrentStreams;
private int maxConcurrentStreams;
private static final int DEFAULT_MAX_CONCURRENT_STREAMS = Integer.MAX_VALUE;
private int remoteConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS;
private int localConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS;
private int maxConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS;
private static final int DEFAULT_WINDOW_SIZE = 64 * 1024; // 64 KB default initial window size
private int initialSendWindowSize = DEFAULT_WINDOW_SIZE;
private int initialSendWindowSize = DEFAULT_WINDOW_SIZE;
private int initialReceiveWindowSize = DEFAULT_WINDOW_SIZE;
private final Object flowControlLock = new Object();
@ -664,23 +665,7 @@ public class SpdySessionHandler
} else {
localConcurrentStreams = newConcurrentStreams;
}
if (localConcurrentStreams == remoteConcurrentStreams) {
maxConcurrentStreams = localConcurrentStreams;
return;
}
if (localConcurrentStreams == 0) {
maxConcurrentStreams = remoteConcurrentStreams;
return;
}
if (remoteConcurrentStreams == 0) {
maxConcurrentStreams = localConcurrentStreams;
return;
}
if (localConcurrentStreams > remoteConcurrentStreams) {
maxConcurrentStreams = remoteConcurrentStreams;
} else {
maxConcurrentStreams = localConcurrentStreams;
}
maxConcurrentStreams = Math.min(localConcurrentStreams, remoteConcurrentStreams);
}
// need to synchronize to prevent new streams from being created while updating active streams
@ -705,9 +690,7 @@ public class SpdySessionHandler
return false;
}
int maxConcurrentStreams = this.maxConcurrentStreams;
if (maxConcurrentStreams != 0 &&
spdySession.numActiveStreams() >= maxConcurrentStreams) {
if (spdySession.numActiveStreams() >= maxConcurrentStreams) {
return false;
}
spdySession.acceptStream(

View File

@ -126,10 +126,23 @@ public class SpdySessionHandlerTest {
assertNull(sessionHandler.readOutbound());
remoteStreamId += 2;
// Check if session handler returns PROTOCOL_ERROR if it receives
// multiple SYN_REPLY frames for the same active Stream-ID
// Check if session handler correctly limits the number of
// concurrent streams in the SETTINGS frame
SpdySettingsFrame spdySettingsFrame = new DefaultSpdySettingsFrame();
spdySettingsFrame.setValue(SpdySettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS, 0);
sessionHandler.writeInbound(spdySettingsFrame);
assertNull(sessionHandler.readOutbound());
sessionHandler.writeInbound(spdySynStreamFrame);
assertRstStream(sessionHandler.readOutbound(), localStreamId, SpdyStreamStatus.REFUSED_STREAM);
assertNull(sessionHandler.readOutbound());
spdySettingsFrame.setValue(SpdySettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS, 100);
sessionHandler.writeInbound(spdySettingsFrame);
assertNull(sessionHandler.readOutbound());
sessionHandler.writeInbound(new DefaultSpdySynReplyFrame(remoteStreamId));
assertNull(sessionHandler.readOutbound());
// Check if session handler returns PROTOCOL_ERROR if it receives
// multiple SYN_REPLY frames for the same active Stream-ID
sessionHandler.writeInbound(new DefaultSpdySynReplyFrame(remoteStreamId));
assertRstStream(sessionHandler.readOutbound(), remoteStreamId, SpdyStreamStatus.STREAM_IN_USE);
assertNull(sessionHandler.readOutbound());
@ -187,9 +200,8 @@ public class SpdySessionHandlerTest {
assertNull(sessionHandler.readOutbound());
spdySynStreamFrame.setStreamId(localStreamId);
// Check if session handler correctly limits the number of
// Check if session handler correctly handles updates to the max
// concurrent streams in the SETTINGS frame
SpdySettingsFrame spdySettingsFrame = new DefaultSpdySettingsFrame();
spdySettingsFrame.setValue(SpdySettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS, 2);
sessionHandler.writeInbound(spdySettingsFrame);
assertNull(sessionHandler.readOutbound());