Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Rename ConnMaxChannels to ConnMaxSessions; make default 65536
Browse files Browse the repository at this point in the history
  • Loading branch information
vcabbage committed Jan 20, 2018
1 parent 94bd3f9 commit 5fe5150
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions conn.go
Expand Up @@ -15,7 +15,7 @@ import (
const (
DefaultMaxFrameSize = 512
DefaultIdleTimeout = 1 * time.Minute
DefaultMaxChannel = 1
DefaultMaxSessions = 65536
)

// Errors
Expand Down Expand Up @@ -107,14 +107,24 @@ func ConnConnectTimeout(d time.Duration) ConnOption {
return func(c *conn) error { c.connectTimeout = d; return nil }
}

// ConnMaxChannels sets the maximum channel number.
// ConnMaxSessions sets the maximum number of channels.
//
// Channel numbering starts at zero.
// n must be in the range 1 to 65536.
//
// Default: 1.
func ConnMaxChannels(n uint16) ConnOption {
// BUG: Currently this limits how many channels can ever
// be opened on this connection rather than how many
// channels can be open at the same time.
//
// Default: 65536.
func ConnMaxSessions(n int) ConnOption {
return func(c *conn) error {
c.channelMax = n
if n < 1 {
return errorNew("max sessions cannot be less than 1")
}
if n > 65536 {
return errorNew("max sessions cannot be greater than 65536")
}
c.channelMax = uint16(n - 1)
return nil
}
}
Expand Down Expand Up @@ -178,7 +188,7 @@ func newConn(netConn net.Conn, opts ...ConnOption) (*conn, error) {
net: netConn,
maxFrameSize: DefaultMaxFrameSize,
peerMaxFrameSize: DefaultMaxFrameSize,
channelMax: DefaultMaxChannel,
channelMax: DefaultMaxSessions - 1, // -1 because channel-max starts at zero
idleTimeout: DefaultIdleTimeout,
done: make(chan struct{}),
connErr: make(chan error, 2), // buffered to ensure connReader/Writer won't leak
Expand Down
2 changes: 1 addition & 1 deletion integration_test.go
Expand Up @@ -91,7 +91,7 @@ func TestIntegrationRoundTrip(t *testing.T) {

// Create client
client := newClient(t, tt.label,
amqp.ConnMaxChannels(uint16(tt.sessions-1)),
amqp.ConnMaxSessions(tt.sessions),
)
defer client.Close()

Expand Down

0 comments on commit 5fe5150

Please sign in to comment.