From de856f0189e69ba7c22b9598799203dc33039814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20G=C3=A4hwiler?= Date: Tue, 7 Aug 2018 12:33:31 +0300 Subject: [PATCH] export flush timeout --- transport/base_conn.go | 5 ++++- transport/conn.go | 2 -- transport/conn_test.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/transport/base_conn.go b/transport/base_conn.go index 625a579..c548f40 100644 --- a/transport/base_conn.go +++ b/transport/base_conn.go @@ -8,6 +8,9 @@ import ( "github.com/256dpi/gomqtt/packet" ) +// FlushTimeout is the time after any async writes are flushed asynchronously. +const FlushTimeout = time.Millisecond + // A Carrier is a generalized stream that can be used with BaseConn. type Carrier interface { io.ReadWriteCloser @@ -88,7 +91,7 @@ func (c *BaseConn) Send(pkt packet.Generic, async bool) error { // setup the timer if missing if c.flushTimer == nil { - c.flushTimer = time.AfterFunc(flushTimeout, c.asyncFlush) + c.flushTimer = time.AfterFunc(FlushTimeout, c.asyncFlush) } return nil diff --git a/transport/conn.go b/transport/conn.go index c079165..d78c880 100644 --- a/transport/conn.go +++ b/transport/conn.go @@ -7,8 +7,6 @@ import ( "github.com/256dpi/gomqtt/packet" ) -var flushTimeout = time.Millisecond - // A Conn is a connection between a client and a broker. It abstracts an // existing underlying stream connection. type Conn interface { diff --git a/transport/conn_test.go b/transport/conn_test.go index 54a655b..4d803b4 100644 --- a/transport/conn_test.go +++ b/transport/conn_test.go @@ -301,7 +301,7 @@ func abstractConnAsyncSendAfterCloseTest(t *testing.T, protocol string) { err = conn2.Send(packet.NewConnect(), true) assert.NoError(t, err) - <-time.After(2 * flushTimeout) + <-time.After(2 * FlushTimeout) err = conn2.Send(packet.NewConnect(), true) assert.Error(t, err)