From 5fe51505022e25788ba8268ffc1112626b8240df Mon Sep 17 00:00:00 2001 From: Kale Blankenship Date: Sat, 20 Jan 2018 10:19:41 -0800 Subject: [PATCH] Rename ConnMaxChannels to ConnMaxSessions; make default 65536 --- conn.go | 24 +++++++++++++++++------- integration_test.go | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/conn.go b/conn.go index 8913d2de..22b0ae43 100644 --- a/conn.go +++ b/conn.go @@ -15,7 +15,7 @@ import ( const ( DefaultMaxFrameSize = 512 DefaultIdleTimeout = 1 * time.Minute - DefaultMaxChannel = 1 + DefaultMaxSessions = 65536 ) // Errors @@ -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 } } @@ -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 diff --git a/integration_test.go b/integration_test.go index c703c615..663557df 100644 --- a/integration_test.go +++ b/integration_test.go @@ -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()