return the invalid stream ID if no streams are allowed

This commit is contained in:
Marten Seemann
2019-06-05 15:17:30 +08:00
parent 42fdeab091
commit 0dd26f4a4c
2 changed files with 6 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ type StreamID int64
// InvalidPacketNumber is a stream ID that is invalid.
// The first valid stream ID in QUIC is 0.
const InvalidStreamID = -1
const InvalidStreamID StreamID = -1
// StreamType encodes if this is a unidirectional or bidirectional stream
type StreamType uint8
@@ -43,7 +43,7 @@ func (s StreamID) StreamNum() uint64 {
// when it is allowed to open numStreams.
func MaxStreamID(stype StreamType, numStreams uint64, pers Perspective) StreamID {
if numStreams == 0 {
return 0
return InvalidStreamID
}
var first StreamID
switch stype {

View File

@@ -44,10 +44,10 @@ var _ = Describe("Stream ID", func() {
Context("maximum stream IDs", func() {
It("doesn't allow any", func() {
Expect(MaxStreamID(StreamTypeBidi, 0, PerspectiveClient)).To(Equal(StreamID(0)))
Expect(MaxStreamID(StreamTypeBidi, 0, PerspectiveServer)).To(Equal(StreamID(0)))
Expect(MaxStreamID(StreamTypeUni, 0, PerspectiveClient)).To(Equal(StreamID(0)))
Expect(MaxStreamID(StreamTypeUni, 0, PerspectiveServer)).To(Equal(StreamID(0)))
Expect(MaxStreamID(StreamTypeBidi, 0, PerspectiveClient)).To(Equal(InvalidStreamID))
Expect(MaxStreamID(StreamTypeBidi, 0, PerspectiveServer)).To(Equal(InvalidStreamID))
Expect(MaxStreamID(StreamTypeUni, 0, PerspectiveClient)).To(Equal(InvalidStreamID))
Expect(MaxStreamID(StreamTypeUni, 0, PerspectiveServer)).To(Equal(InvalidStreamID))
})
It("allows one", func() {